exchange

package
v0.0.0-...-e477184 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2017 License: MIT Imports: 9 Imported by: 21

Documentation

Index

Constants

View Source
const (

	// WarningAuthenticatedRequestWithoutCredentialsSet error message for authenticated request without credentials set
	WarningAuthenticatedRequestWithoutCredentialsSet = "WARNING -- Exchange %s authenticated HTTP request called but not supported due to unset/default API keys."
	// ErrExchangeNotFound is a constant for an error message
	ErrExchangeNotFound = "Exchange not found in dataset."
	// ErrExchangeOrderNotFound is one of the possible errors returned by IBotExchangeEx.GetOrder()
	ErrOrderNotFound = "Exchange order not found."
)

Variables

This section is empty.

Functions

func ErrInsufficentFundsForOrder

func ErrInsufficentFundsForOrder() error

ErrInsufficentFundsForOrder returns an error that indicates that aren't sufficient funds available to place a new order on the exchange.

func FormatCurrency

func FormatCurrency(p pair.CurrencyPair) pair.CurrencyItem

FormatCurrency is a method that formats and returns a currency pair based on the user currency display preferences

func FormatExchangeCurrency

func FormatExchangeCurrency(exchName string, p pair.CurrencyPair) pair.CurrencyItem

FormatExchangeCurrency is a method that formats and returns a currency pair based on the user currency display preferences

func FormatExchangeCurrencyPair

func FormatExchangeCurrencyPair(exchName string, p pair.CurrencyPair) pair.CurrencyPair

func GetAndFormatExchangeCurrencies

func GetAndFormatExchangeCurrencies(exchName string, pairs []pair.CurrencyPair) (pair.CurrencyItem, error)

GetAndFormatExchangeCurrencies returns a pair.CurrencyItem string containing the exchanges formatted currency pairs

func GetExchangeAssetTypes

func GetExchangeAssetTypes(exchName string) ([]string, error)

GetExchangeAssetTypes returns the asset types the exchange supports (SPOT, binary, futures)

func GetExchangeFormatCurrencySeperator

func GetExchangeFormatCurrencySeperator(exchName string) bool

GetExchangeFormatCurrencySeperator returns whether or not a specific exchange contains a separator used for API requests

func WarningHTTPRequestRateLimited

func WarningHTTPRequestRateLimited() error

WarningHTTPRequestRateLimited() returns an error that indicates that a method of the IBotExchangeEx interface was rate limited.

Types

type AccountCurrencyInfo

type AccountCurrencyInfo struct {
	CurrencyName string
	TotalValue   float64 // Hold + Available
	Hold         float64 // Amount on hold (used for currently open orders)
	Available    float64 // Amount actually available for placing orders
}

AccountCurrencyInfo is a sub type to store currency name and value

type AccountInfo

type AccountInfo struct {
	ExchangeName string
	Currencies   []AccountCurrencyInfo
}

AccountInfo is a Generic type to hold each exchange's holdings in all enabled currencies

type Base

type Base struct {
	Name                        string
	Enabled                     bool
	Verbose                     bool
	Websocket                   bool
	RESTPollingDelay            time.Duration
	AuthenticatedAPISupport     bool
	APISecret, APIKey, ClientID string
	Nonce                       nonce.Nonce
	TakerFee, MakerFee, Fee     float64
	BaseCurrencies              []string
	AvailablePairs              []string
	EnabledPairs                []string
	AssetTypes                  []string
	WebsocketURL                string
	APIUrl                      string
	RequestCurrencyPairFormat   config.CurrencyPairFormatConfig
	ConfigCurrencyPairFormat    config.CurrencyPairFormatConfig
	Orderbooks                  orderbook.Orderbooks
}

Base stores the individual exchange information

func (*Base) CommonSetup

func (e *Base) CommonSetup(exch config.ExchangeConfig)

Common exchange setup method so we can stop duplicating so much code

func (*Base) FormatExchangeCurrencyPair

func (e *Base) FormatExchangeCurrencyPair(p pair.CurrencyPair) pair.CurrencyPair

func (*Base) GetAuthenticatedAPISupport

func (e *Base) GetAuthenticatedAPISupport() bool

GetAuthenticatedAPISupport returns whether the exchange supports authenticated API requests

func (*Base) GetAvailableCurrencies

func (e *Base) GetAvailableCurrencies() []pair.CurrencyPair

GetAvailableCurrencies is a method that returns the available currency pairs of the exchange base

func (*Base) GetEnabledCurrencies

func (e *Base) GetEnabledCurrencies() []pair.CurrencyPair

GetEnabledCurrencies is a method that returns the enabled currency pairs of the exchange base

func (*Base) GetName

func (e *Base) GetName() string

GetName is a method that returns the name of the exchange base

func (*Base) GetOrderbookSimple

func (e *Base) GetOrderbookSimple(p pair.CurrencyPair, assetType string) (orderbook.Base, error)

GetOrderbookSimple returns orderbook base on the currency pair, does not update exchange

func (*Base) IsEnabled

func (e *Base) IsEnabled() bool

IsEnabled is a method that returns if the current exchange is enabled

func (*Base) SetAPIKeys

func (e *Base) SetAPIKeys(APIKey, APISecret, ClientID string, b64Decode bool)

SetAPIKeys is a method that sets the current API keys for the exchange

func (*Base) SetAssetTypes

func (e *Base) SetAssetTypes() error

SetAssetTypes checks the exchange asset types (whether it supports SPOT, Binary or Futures) and sets it to a default setting if it doesn't exist

func (*Base) SetCurrencyPairFormat

func (e *Base) SetCurrencyPairFormat() error

SetCurrencyPairFormat checks the exchange request and config currency pair formats and sets it to a default setting if it doesn't exist

func (*Base) SetEnabled

func (e *Base) SetEnabled(enabled bool)

SetEnabled is a method that sets if the exchange is enabled

func (*Base) UpdateAvailableCurrencies

func (e *Base) UpdateAvailableCurrencies(exchangeProducts []string, force bool) error

UpdateAvailableCurrencies is a method that sets new pairs to the current exchange. Setting force to true upgrades the available currencies

func (*Base) UpdateEnabledCurrencies

func (e *Base) UpdateEnabledCurrencies(exchangeProducts []string, force bool) error

UpdateEnabledCurrencies is a method that sets new pairs to the current exchange. Setting force to true upgrades the enabled currencies

type CurrencyPairInfo

type CurrencyPairInfo struct {
	Currency           pair.CurrencyPair
	FirstCurrencyName  string
	SecondCurrencyName string
}

type DefaultExchangeLimits

type DefaultExchangeLimits struct{}

DefaultExchangeLimits provides reasonable defaults for exchanges that don't bother specifying this kind of information in their API docs.

func (*DefaultExchangeLimits) GetAmountDecimalPlaces

func (l *DefaultExchangeLimits) GetAmountDecimalPlaces(p pair.CurrencyPair) int32

GetAmountDecimalPlaces returns max number of decimal places allowed in the trade amount for the given currency pair, -1 should be used to indicate this value isn't defined.

func (*DefaultExchangeLimits) GetMinAmount

func (l *DefaultExchangeLimits) GetMinAmount(p pair.CurrencyPair) float64

GetMinAmount returns the minimum trade amount for the given currency pair.

func (*DefaultExchangeLimits) GetMinTotal

func (l *DefaultExchangeLimits) GetMinTotal(p pair.CurrencyPair) float64

GetMinTotal returns the minimum trade total (amount * price) for the given currency pair.

func (*DefaultExchangeLimits) GetPriceDecimalPlaces

func (l *DefaultExchangeLimits) GetPriceDecimalPlaces(p pair.CurrencyPair) int32

GetPriceDecimalPlaces Returns max number of decimal places allowed in the trade price for the given currency pair, -1 should be used to indicate this value isn't defined.

type IBotExchange

type IBotExchange interface {
	Setup(exch config.ExchangeConfig)
	Start()
	SetDefaults()
	GetName() string
	IsEnabled() bool
	GetTickerPrice(currency pair.CurrencyPair, assetType string) (ticker.Price, error)
	UpdateTicker(currency pair.CurrencyPair, assetType string) (ticker.Price, error)
	GetOrderbookEx(currency pair.CurrencyPair, assetType string) (orderbook.Base, error)
	GetOrderbookSimple(currency pair.CurrencyPair, assetType string) (orderbook.Base, error)
	UpdateOrderbook(currency pair.CurrencyPair, assetType string) (orderbook.Base, error)
	GetEnabledCurrencies() []pair.CurrencyPair
	GetExchangeAccountInfo() (AccountInfo, error)
	GetAuthenticatedAPISupport() bool
}

IBotExchange enforces standard functions for all exchanges supported in GoCryptoTrader

type IBotExchangeEx

type IBotExchangeEx interface {
	IBotExchange
	Run()
	// NewOrder creates a new order on the exchange.
	// Returns the ID of the new exchange order, or an empty string if the order was filled
	// immediately but no ID was generated.
	NewOrder(symbol pair.CurrencyPair, amount, price float64, side OrderSide, orderType OrderType) (string, error)
	// CancelOrder will attempt to cancel the active order matching the given ID.
	// The currency pair may be required for some exchanges.
	CancelOrder(OrderID string, currencyPair pair.CurrencyPair) error
	// GetOrder returns information about a previously placed order (which may be active or inactive).
	// The currency pair may be required for some exchanges.
	GetOrder(orderID string, currencyPair pair.CurrencyPair) (*Order, error)
	// GetOrders returns information about currently active orders.
	// The pairs parameter should contain the currency pairs for which active orders should be retrieved,
	// if this is parameter is nil or empty then all active orders will be retrieved.
	GetOrders(pairs []pair.CurrencyPair) ([]*Order, error)
	// GetLimits returns price/amount limits for the exchange.
	GetLimits() ILimits
	// Returns currency pairs that can be used by the exchange account associated with this bot.
	// Use FormatExchangeCurrency to get the right key.
	GetCurrencyPairs() map[pair.CurrencyItem]*CurrencyPairInfo
}

Extended bot interface for new methods

type ILimits

type ILimits interface {
	// Returns max number of decimal places allowed in the trade price for the given currency pair,
	// -1 should be used to indicate this value isn't defined.
	GetPriceDecimalPlaces(p pair.CurrencyPair) int32
	// Returns max number of decimal places allowed in the trade amount for the given currency pair,
	// -1 should be used to indicate this value isn't defined.
	GetAmountDecimalPlaces(p pair.CurrencyPair) int32
	// Returns the minimum trade amount for the given currency pair.
	GetMinAmount(p pair.CurrencyPair) float64
	// Returns the minimum trade total (the amount multiplied by the price, denominated in the
	// price currency).
	GetMinTotal(p pair.CurrencyPair) float64
}

ILimits provides information about the limits placed by an exchange on numbers representing order/trade price and amount.

type Order

type Order struct {
	CurrencyPair    pair.CurrencyPair
	Type            OrderType
	Side            OrderSide
	Amount          float64 //original amount requested
	FilledAmount    float64
	RemainingAmount float64
	Rate            float64
	CreatedAt       int64 // timestamp
	//	LastUpdate      int64 // timestamp
	Status          OrderStatus
	OrderID         string // Order ID generated by the exchange
	InternalOrderID string // Order ID generated by the trading system (or bot)
}

type OrderSide

type OrderSide string
const (
	OrderSideBuy  OrderSide = "buy"
	OrderSideSell OrderSide = "sell"
)

type OrderStatus

type OrderStatus string
const (
	OrderStatusActive  OrderStatus = "active"
	OrderStatusFilled  OrderStatus = "filled"
	OrderStatusAborted OrderStatus = "aborted"
	OrderStatusUnknown OrderStatus = "unknown"
)

type OrderType

type OrderType string
const (
	OrderTypeExchangeLimit OrderType = "exchange limit"
	OrderTypeMarginLimit             = "margin limit"
)

Jump to

Keyboard shortcuts

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