api

package
v1.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 15, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertMSO2Ops added in v1.11.0

func ConvertMSO2Ops(msos []*txnbuild.ManageSellOffer) []txnbuild.Operation

ConvertMSO2Ops converts manage sell offers into Operations.

func ConvertOperation2TM added in v1.8.0

func ConvertOperation2TM(ops []txnbuild.Operation) []build.TransactionMutator

ConvertOperation2TM is a temporary adapter to support transitioning from the old Go SDK to the new SDK without having to bump the major version

func ConvertTM2MSO added in v1.11.0

func ConvertTM2MSO(muts []build.TransactionMutator) []*txnbuild.ManageSellOffer

ConvertTM2MSO converts mutators from the old SDK to ManageSellOffer ops in the new one.

func ConvertTM2Operation added in v1.8.0

func ConvertTM2Operation(muts []build.TransactionMutator) []txnbuild.Operation

ConvertTM2Operation is a temporary adapter to support transitioning from the old Go SDK to the new SDK without having to bump the major version

Types

type Account

type Account interface {
	GetAccountBalances(assetList []interface{}) (map[interface{}]model.Number, error)
}

Account allows you to access key account functions

type Alert added in v1.2.0

type Alert interface {
	Trigger(description string, details interface{}) error
}

Alert interface is used for the various monitoring and alerting tools for Kelp.

type Balance added in v1.6.0

type Balance struct {
	Balance float64
	Trust   float64
	Reserve float64
}

Balance repesents various aspects of an asset's balance

type Constrainable added in v1.3.0

type Constrainable interface {
	// return nil if the constraint does not exist for the exchange
	GetOrderConstraints(pair *model.TradingPair) *model.OrderConstraints

	OverrideOrderConstraints(pair *model.TradingPair, override *model.OrderConstraintsOverride)
}

Constrainable extracts out the method that SDEX can implement for now

type DepositAPI

type DepositAPI interface {
	/*
		Input:
			asset - asset you want to deposit
			amount - amount you want to deposit
		Output:
			PrepareDepositResult - contains the deposit instructions
			error - ErrDepositAmountAboveLimit, ErrTooManyDepositAddresses, or any other error
	*/
	PrepareDeposit(asset model.Asset, amount *model.Number) (*PrepareDepositResult, error)
}

DepositAPI is defined by anything where you can deposit funds.

type ErrDepositAmountAboveLimit

type ErrDepositAmountAboveLimit error

ErrDepositAmountAboveLimit error type

func MakeErrDepositAmountAboveLimit

func MakeErrDepositAmountAboveLimit(amount *model.Number, limit *model.Number) ErrDepositAmountAboveLimit

MakeErrDepositAmountAboveLimit is a factory method

type ErrTooManyDepositAddresses

type ErrTooManyDepositAddresses error

ErrTooManyDepositAddresses error type

func MakeErrTooManyDepositAddresses

func MakeErrTooManyDepositAddresses() ErrTooManyDepositAddresses

MakeErrTooManyDepositAddresses is a factory method

type ErrWithdrawAmountAboveLimit

type ErrWithdrawAmountAboveLimit error

ErrWithdrawAmountAboveLimit error type

func MakeErrWithdrawAmountAboveLimit

func MakeErrWithdrawAmountAboveLimit(amount *model.Number, limit *model.Number) ErrWithdrawAmountAboveLimit

MakeErrWithdrawAmountAboveLimit is a factory method

type ErrWithdrawAmountInvalid

type ErrWithdrawAmountInvalid error

ErrWithdrawAmountInvalid error type

func MakeErrWithdrawAmountInvalid

func MakeErrWithdrawAmountInvalid(amountToWithdraw *model.Number, fee *model.Number) ErrWithdrawAmountInvalid

MakeErrWithdrawAmountInvalid is a factory method

type Exchange

type Exchange interface {
	Account
	TickerAPI
	TradeAPI
	DepositAPI
	WithdrawAPI
}

Exchange is the interface we use as a generic API for all crypto exchanges

type ExchangeAPIKey added in v1.2.0

type ExchangeAPIKey struct {
	Key    string
	Secret string
}

ExchangeAPIKey specifies API credentials for an exchange

type ExchangeHeader added in v1.6.1

type ExchangeHeader struct {
	Header string
	Value  string
}

ExchangeHeader specifies additional HTTP headers

type ExchangeParam added in v1.6.1

type ExchangeParam struct {
	Param string
	Value interface{}
}

ExchangeParam specifies an additional parameter to be sent when initializing the exchange

type ExchangeShim added in v1.6.0

type ExchangeShim interface {
	SubmitOps(ops []build.TransactionMutator, submitMode SubmitMode, asyncCallback func(hash string, e error)) error
	SubmitOpsSynch(ops []build.TransactionMutator, submitMode SubmitMode, asyncCallback func(hash string, e error)) error // forced synchronous version of SubmitOps
	GetBalanceHack(asset hProtocol.Asset) (*Balance, error)
	LoadOffersHack() ([]hProtocol.Offer, error)
	Constrainable
	OrderbookFetcher
	FillTrackable
}

ExchangeShim is the interface we use as a generic API for all crypto exchanges

type FeedPair

type FeedPair struct {
	FeedA PriceFeed
	FeedB PriceFeed
}

TODO this should be structured as a specific impl. of the PriceFeed interface FeedPair is the struct representing a price feed for a trading pair

func (*FeedPair) GetFeedPairPrice added in v1.8.0

func (p *FeedPair) GetFeedPairPrice() (float64, error)

GetFeedPairPrice fetches the price by dividing FeedA by FeedB

type FillHandler added in v1.3.0

type FillHandler interface {
	HandleFill(trade model.Trade) error
}

FillHandler is invoked by the FillTracker (once registered) anytime an order is filled

type FillTrackable added in v1.3.0

type FillTrackable interface {
	TradeFetcher
	GetLatestTradeCursor() (interface{}, error)
}

FillTrackable enables any implementing exchange to support fill tracking

type FillTracker added in v1.3.0

type FillTracker interface {
	GetPair() (pair *model.TradingPair)
	// TrackFills should be executed in a new thread
	TrackFills() error
	IsRunningInBackground() bool
	FillTrackSingleIteration() ([]model.Trade, error)
	RegisterHandler(handler FillHandler)
	NumHandlers() uint8
}

FillTracker knows how to track fills against open orders

type Level

type Level struct {
	Price  model.Number
	Amount model.Number
}

Level represents a layer in the orderbook

type LevelProvider

type LevelProvider interface {
	GetLevels(maxAssetBase float64, maxAssetQuote float64) ([]Level, error)
	GetFillHandlers() ([]FillHandler, error)
}

LevelProvider returns the levels for the given mid price, which controls the spread and number of levels

type OrderbookFetcher added in v1.6.0

type OrderbookFetcher interface {
	GetOrderBook(pair *model.TradingPair, maxCount int32) (*model.OrderBook, error)
}

OrderbookFetcher extracts out the method that should go into ExchangeShim for now

type PrepareDepositResult

type PrepareDepositResult struct {
	Fee      *model.Number // fee that will be deducted from your deposit, i.e. amount available is depositAmount - fee
	Address  string        // address you should send the funds to
	ExpireTs int64         // expire time as a unix timestamp, 0 if it does not expire
}

PrepareDepositResult is the result of a PrepareDeposit call

type PriceFeed

type PriceFeed interface {
	GetPrice() (float64, error)
}

PriceFeed allows you to fetch the price of a feed

type Query added in v1.10.0

type Query interface {
	// Name returns a constant string name with which to represent the query
	Name() string

	// QueryRow executes the query with the passed in runtime parameters
	QueryRow(args ...interface{}) (interface{}, error)
}

Query is an interface for a query that returns data

type SideStrategy

type SideStrategy interface {
	PruneExistingOffers(offers []hProtocol.Offer) ([]build.TransactionMutator, []hProtocol.Offer)
	PreUpdate(maxAssetA float64, maxAssetB float64, trustA float64, trustB float64) error
	UpdateWithOps(offers []hProtocol.Offer) (ops []build.TransactionMutator, newTopOffer *model.Number, e error)
	PostUpdate() error
	GetFillHandlers() ([]FillHandler, error)
}

SideStrategy represents a strategy on a single side of the orderbook

type Strategy

type Strategy interface {
	PruneExistingOffers(buyingAOffers []hProtocol.Offer, sellingAOffers []hProtocol.Offer) ([]build.TransactionMutator, []hProtocol.Offer, []hProtocol.Offer)
	PreUpdate(maxAssetA float64, maxAssetB float64, trustA float64, trustB float64) error
	UpdateWithOps(buyingAOffers []hProtocol.Offer, sellingAOffers []hProtocol.Offer) ([]build.TransactionMutator, error)
	PostUpdate() error
	GetFillHandlers() ([]FillHandler, error)
}

Strategy represents some logic for a bot to follow while doing market making

type SubmitMode added in v1.4.0

type SubmitMode uint8

SubmitMode is the type of mode to be used when submitting orders to the trader bot

const (
	SubmitModeMakerOnly SubmitMode = iota
	SubmitModeBoth
)

constants for the SubmitMode

func ParseSubmitMode added in v1.4.0

func ParseSubmitMode(submitMode string) (SubmitMode, error)

ParseSubmitMode converts a string to the SubmitMode constant

func (*SubmitMode) String added in v1.4.0

func (s *SubmitMode) String() string

type Ticker

type Ticker struct {
	AskPrice  *model.Number
	BidPrice  *model.Number
	LastPrice *model.Number
}

Ticker encapsulates all the data for a given Trading Pair

type TickerAPI added in v1.1.0

type TickerAPI interface {
	GetTickerPrice(pairs []model.TradingPair) (map[model.TradingPair]Ticker, error)
}

TickerAPI is the interface we use as a generic API for getting ticker data from any crypto exchange

type TimeController added in v1.2.0

type TimeController interface {
	// ShouldUpdate defines when to enter the bot's update cycle
	// lastUpdateTime will never start off as the zero value
	ShouldUpdate(lastUpdateTime time.Time, currentUpdateTime time.Time) bool

	// SleepTime computes how long we want to sleep before the next call to ShouldUpdate
	SleepTime(lastUpdateTime time.Time) time.Duration
}

TimeController controls the update loop for the bot

type TradeAPI

type TradeAPI interface {
	GetAssetConverter() model.AssetConverterInterface

	Constrainable

	OrderbookFetcher

	GetTrades(pair *model.TradingPair, maybeCursor interface{}) (*TradesResult, error)

	FillTrackable

	GetOpenOrders(pairs []*model.TradingPair) (map[model.TradingPair][]model.OpenOrder, error)

	AddOrder(order *model.Order, submitMode SubmitMode) (*model.TransactionID, error)

	CancelOrder(txID *model.TransactionID, pair model.TradingPair) (model.CancelOrderResult, error)
}

TradeAPI is the interface we use as a generic API for trading on any crypto exchange

type TradeFetcher added in v1.3.0

type TradeFetcher interface {
	GetTradeHistory(pair model.TradingPair, maybeCursorStart interface{}, maybeCursorEnd interface{}) (*TradeHistoryResult, error)
}

TradeFetcher is the common method between FillTrackable and exchange temporarily extracted out from TradeAPI so SDEX has the flexibility to only implement this rather than exchange and FillTrackable

type TradeHistoryResult

type TradeHistoryResult struct {
	Cursor interface{}
	Trades []model.Trade
}

TradeHistoryResult is the result of a GetTradeHistory call this should be the same object as TradesResult but it's a separate object for backwards compatibility

type TradesResult

type TradesResult struct {
	Cursor interface{}
	Trades []model.Trade
}

TradesResult is the result of a GetTrades call

type WithdrawAPI

type WithdrawAPI interface {
	/*
		Input:
			asset - asset you want to withdraw
			amountToWithdraw - amount you want deducted from your account
			address - address you want to withdraw to
		Output:
			WithdrawInfo - details on how to perform the withdrawal
			error - ErrWithdrawAmountAboveLimit, ErrWithdrawAmountInvalid, or any other error
	*/
	GetWithdrawInfo(asset model.Asset, amountToWithdraw *model.Number, address string) (*WithdrawInfo, error)

	/*
		Input:
			asset - asset you want to withdraw
			amountToWithdraw - amount you want deducted from your account (fees will be deducted from here, use GetWithdrawInfo for fee estimate)
			address - address you want to withdraw to
		Output:
		    WithdrawFunds - result of the withdrawal
			error - any error
	*/
	WithdrawFunds(
		asset model.Asset,
		amountToWithdraw *model.Number,
		address string,
	) (*WithdrawFunds, error)
}

WithdrawAPI is defined by anything where you can withdraw funds.

type WithdrawFunds

type WithdrawFunds struct {
	WithdrawalID string
}

WithdrawFunds is the result of a WithdrawFunds call

type WithdrawInfo

type WithdrawInfo struct {
	AmountToReceive *model.Number // amount that you will receive after any fees is taken (excludes fees charged on the deposit side)
}

WithdrawInfo is the result of a GetWithdrawInfo call

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL