exchange

package
v0.0.0-...-a2c5123 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2018 License: MIT Imports: 12 Imported by: 0

README

GoCryptoTrader package Exchanges

Build Status Software License GoDoc Coverage Status Go Report Card

This exchanges package is part of the GoCryptoTrader codebase.

This is still in active development

You can track ideas, planned features and what's in progresss on this Trello board: https://trello.com/b/ZAhMhpOy/gocryptotrader.

Join our slack to discuss all things related to GoCryptoTrader! GoCryptoTrader Slack

Current Features for exchanges

  • This package is used to connect and query data from supported exchanges.

  • Please checkout individual exchange README for more information on implementation

Please click GoDocs chevron above to view current GoDoc information for this package

Contribution

Please feel free to submit any pull requests or suggest any desired features to be added.

When submitting a PR, please abide by our coding guidelines:

  • Code must adhere to the official Go formatting guidelines (i.e. uses gofmt).
  • Code must be documented adhering to the official Go commentary guidelines.
  • Code must adhere to our coding style.
  • Pull requests need to be based on and opened against the master branch.

Donations

If this framework helped you in any way, or you would like to support the developers working on it, please donate Bitcoin to:

1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB

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."
	// DefaultHTTPTimeout is the default HTTP/HTTPS Timeout for exchange requests
	DefaultHTTPTimeout = time.Second * 15
)

Variables

This section is empty.

Functions

func CompareCurrencyPairFormats

func CompareCurrencyPairFormats(pair1 config.CurrencyPairFormatConfig, pair2 *config.CurrencyPairFormatConfig) bool

CompareCurrencyPairFormats checks and returns whether or not the two supplied config currency pairs match

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 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

Types

type AccountCurrencyInfo

type AccountCurrencyInfo struct {
	CurrencyName string
	TotalValue   float64
	Hold         float64
}

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, APIAuthPEMKey, ClientID string
	Nonce                                      nonce.Nonce
	TakerFee, MakerFee, Fee                    float64
	BaseCurrencies                             []string
	AvailablePairs                             []string
	EnabledPairs                               []string
	AssetTypes                                 []string
	PairsLastUpdated                           int64
	SupportsAutoPairUpdating                   bool
	SupportsRESTTickerBatching                 bool
	HTTPTimeout                                time.Duration
	HTTPUserAgent                              string
	WebsocketURL                               string
	APIUrl                                     string
	APIUrlDefault                              string
	APIUrlSecondary                            string
	APIUrlSecondaryDefault                     string
	RequestCurrencyPairFormat                  config.CurrencyPairFormatConfig
	ConfigCurrencyPairFormat                   config.CurrencyPairFormatConfig
	*request.Requester
}

Base stores the individual exchange information

func (*Base) GetAPIURL

func (e *Base) GetAPIURL() string

GetAPIURL returns the set API URL

func (*Base) GetAPIURLDefault

func (e *Base) GetAPIURLDefault() string

GetAPIURLDefault returns exchange default URL

func (*Base) GetAPIURLSecondaryDefault

func (e *Base) GetAPIURLSecondaryDefault() string

GetAPIURLSecondaryDefault returns exchange default secondary URL

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) GetClientBankAccounts

func (e *Base) GetClientBankAccounts(exchangeName, withdrawalCurrency string) (config.BankAccount, error)

GetClientBankAccounts returns banking details associated with a client for withdrawal purposes

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) GetExchangeBankAccounts

func (e *Base) GetExchangeBankAccounts(exchangeName, depositCurrency string) (config.BankAccount, error)

GetExchangeBankAccounts returns banking details associated with an exchange for funding purposes

func (*Base) GetHTTPClient

func (e *Base) GetHTTPClient() *http.Client

GetHTTPClient gets the exchanges HTTP client

func (*Base) GetHTTPClientUserAgent

func (e *Base) GetHTTPClientUserAgent() string

GetHTTPClientUserAgent gets the exchanges HTTP user agent

func (*Base) GetLastPairsUpdateTime

func (e *Base) GetLastPairsUpdateTime() int64

GetLastPairsUpdateTime returns the unix timestamp of when the exchanges currency pairs were last updated

func (*Base) GetName

func (e *Base) GetName() string

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

func (*Base) GetSecondaryAPIURL

func (e *Base) GetSecondaryAPIURL() string

GetSecondaryAPIURL returns the set Secondary API URL

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) SetAPIURL

func (e *Base) SetAPIURL(ec config.ExchangeConfig) error

SetAPIURL sets configuration API URL for an 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) SetAutoPairDefaults

func (e *Base) SetAutoPairDefaults() error

SetAutoPairDefaults sets the default values for whether or not the exchange supports auto pair updating or not

func (*Base) SetCurrencies

func (e *Base) SetCurrencies(pairs []pair.CurrencyPair, enabledPairs bool) error

SetCurrencies sets the exchange currency pairs for either enabledPairs or availablePairs

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) SetHTTPClient

func (e *Base) SetHTTPClient(h *http.Client)

SetHTTPClient sets exchanges HTTP client

func (*Base) SetHTTPClientTimeout

func (e *Base) SetHTTPClientTimeout(t time.Duration)

SetHTTPClientTimeout sets the timeout value for the exchanges HTTP Client

func (*Base) SetHTTPClientUserAgent

func (e *Base) SetHTTPClientUserAgent(ua string)

SetHTTPClientUserAgent sets the exchanges HTTP user agent

func (*Base) SupportsAutoPairUpdates

func (e *Base) SupportsAutoPairUpdates() bool

SupportsAutoPairUpdates returns whether or not the exchange supports auto currency pair updating

func (*Base) SupportsCurrency

func (e *Base) SupportsCurrency(p pair.CurrencyPair, enabledPairs bool) bool

SupportsCurrency returns true or not whether a currency pair exists in the exchange available currencies or not

func (*Base) SupportsRESTTickerBatchUpdates

func (e *Base) SupportsRESTTickerBatchUpdates() bool

SupportsRESTTickerBatchUpdates returns whether or not the exhange supports REST batch ticker fetching

func (*Base) UpdateCurrencies

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

UpdateCurrencies updates the exchange currency pairs for either enabledPairs or availablePairs

type Format

type Format struct {
	ExchangeName string
	OrderType    map[string]string
	OrderSide    map[string]string
}

Format holds exchange formatting

type Formatting

type Formatting []Format

Formatting contain a range of exchanges formatting

type FundHistory

type FundHistory struct {
	ExchangeName      string
	Status            string
	TransferID        int64
	Description       string
	Timestamp         int64
	Currency          string
	Amount            float64
	Fee               float64
	TransferType      string
	CryptoToAddress   string
	CryptoFromAddress string
	CryptoTxID        string
	BankTo            string
	BankFrom          string
}

FundHistory holds exchange funding history data

type IBotExchange

type IBotExchange interface {
	Setup(exch config.ExchangeConfig)
	Start(wg *sync.WaitGroup)
	SetDefaults()
	GetName() string
	IsEnabled() bool
	SetEnabled(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)
	UpdateOrderbook(currency pair.CurrencyPair, assetType string) (orderbook.Base, error)
	GetEnabledCurrencies() []pair.CurrencyPair
	GetAvailableCurrencies() []pair.CurrencyPair
	GetExchangeAccountInfo() (AccountInfo, error)
	GetAuthenticatedAPISupport() bool
	SetCurrencies(pairs []pair.CurrencyPair, enabledPairs bool) error
	GetExchangeHistory(pair.CurrencyPair, string) ([]TradeHistory, error)
	SupportsAutoPairUpdates() bool
	GetLastPairsUpdateTime() int64
	SupportsRESTTickerBatchUpdates() bool

	GetExchangeFundTransferHistory() ([]FundHistory, error)
	SubmitExchangeOrder(p pair.CurrencyPair, side OrderSide, orderType OrderType, amount, price float64, clientID string) (int64, error)
	ModifyExchangeOrder(orderID int64, modify ModifyOrder) (int64, error)
	CancelExchangeOrder(orderID int64) error
	CancelAllExchangeOrders() error
	GetExchangeOrderInfo(orderID int64) (OrderDetail, error)
	GetExchangeDepositAddress(cryptocurrency pair.CurrencyItem) (string, error)

	WithdrawCryptoExchangeFunds(address string, cryptocurrency pair.CurrencyItem, amount float64) (string, error)
	WithdrawFiatExchangeFunds(currency pair.CurrencyItem, amount float64) (string, error)
}

IBotExchange enforces standard functions for all exchanges supported in GoCryptoTrader

type ModifyOrder

type ModifyOrder struct {
	OrderType
	OrderSide
	Price  float64
	Amount float64
}

ModifyOrder is a an order modifyer

type OrderDetail

type OrderDetail struct {
	Exchange      string
	ID            int64
	BaseCurrency  string
	QuoteCurrency string
	OrderSide     string
	OrderType     string
	CreationTime  int64
	Status        string
	Price         float64
	Amount        float64
	OpenVolume    float64
}

OrderDetail holds order detail data

type OrderSide

type OrderSide string

OrderSide enforces a standard for OrderSides across the code base

func OrderSideBuy

func OrderSideBuy() OrderSide

OrderSideBuy returns an OrderSide buy order

func OrderSideSell

func OrderSideSell() OrderSide

OrderSideSell returns an OrderSide Sell order

func (OrderSide) Format

func (o OrderSide) Format(exchangeName string) string

Format changes the ordertype to the exchange standard and returns a string

type OrderType

type OrderType string

OrderType enforces a standard for Ordertypes across the code base

func OrderTypeLimit

func OrderTypeLimit() OrderType

OrderTypeLimit returns an OrderType limit order

func OrderTypeMarket

func OrderTypeMarket() OrderType

OrderTypeMarket returns an OrderType Market order

func (OrderType) Format

func (o OrderType) Format(exchangeName string) string

Format changes the ordertype to the exchange standard and returns a string

type TradeHistory

type TradeHistory struct {
	Timestamp int64
	TID       int64
	Price     float64
	Amount    float64
	Exchange  string
	Type      string
}

TradeHistory holds exchange history data

Jump to

Keyboard shortcuts

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