Version: v0.0.0-...-eb07c7e Latest Latest

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

Go to latest
Published: Jul 19, 2019 License: MIT Imports: 15 Imported by: 0


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:

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


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.


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





View Source
const (

	// WarningAuthenticatedRequestWithoutCredentialsSet error message for authenticated request without credentials set
	WarningAuthenticatedRequestWithoutCredentialsSet = "exchange %s authenticated HTTP request called but not supported due to unset/default API keys"
	// ErrExchangeNotFound is a stand for an error message
	ErrExchangeNotFound = "exchange not found in dataset"
	// DefaultHTTPTimeout is the default HTTP/HTTPS Timeout for exchange requests
	DefaultHTTPTimeout = time.Second * 15
View Source
const (
	// No withdraw
	NoAPIWithdrawalMethods                  uint32 = 0
	NoAPIWithdrawalMethodsText              string = "NONE, WEBSITE ONLY"
	AutoWithdrawCrypto                      uint32 = (1 << 0)
	AutoWithdrawCryptoWithAPIPermission     uint32 = (1 << 1)
	AutoWithdrawCryptoWithSetup             uint32 = (1 << 2)
	AutoWithdrawCryptoText                  string = "AUTO WITHDRAW CRYPTO"
	AutoWithdrawCryptoWithAPIPermissionText string = "AUTO WITHDRAW CRYPTO WITH API PERMISSION"
	AutoWithdrawCryptoWithSetupText         string = "AUTO WITHDRAW CRYPTO WITH SETUP"
	WithdrawCryptoWith2FA                   uint32 = (1 << 3)
	WithdrawCryptoWithSMS                   uint32 = (1 << 4)
	WithdrawCryptoWithEmail                 uint32 = (1 << 5)
	WithdrawCryptoWithWebsiteApproval       uint32 = (1 << 6)
	WithdrawCryptoWithAPIPermission         uint32 = (1 << 7)
	WithdrawCryptoWith2FAText               string = "WITHDRAW CRYPTO WITH 2FA"
	WithdrawCryptoWithSMSText               string = "WITHDRAW CRYPTO WITH SMS"
	WithdrawCryptoWithEmailText             string = "WITHDRAW CRYPTO WITH EMAIL"
	WithdrawCryptoWithWebsiteApprovalText   string = "WITHDRAW CRYPTO WITH WEBSITE APPROVAL"
	WithdrawCryptoWithAPIPermissionText     string = "WITHDRAW CRYPTO WITH API PERMISSION"
	AutoWithdrawFiat                        uint32 = (1 << 8)
	AutoWithdrawFiatWithAPIPermission       uint32 = (1 << 9)
	AutoWithdrawFiatWithSetup               uint32 = (1 << 10)
	AutoWithdrawFiatText                    string = "AUTO WITHDRAW FIAT"
	AutoWithdrawFiatWithAPIPermissionText   string = "AUTO WITHDRAW FIAT WITH API PERMISSION"
	AutoWithdrawFiatWithSetupText           string = "AUTO WITHDRAW FIAT WITH SETUP"
	WithdrawFiatWith2FA                     uint32 = (1 << 11)
	WithdrawFiatWithSMS                     uint32 = (1 << 12)
	WithdrawFiatWithEmail                   uint32 = (1 << 13)
	WithdrawFiatWithWebsiteApproval         uint32 = (1 << 14)
	WithdrawFiatWithAPIPermission           uint32 = (1 << 15)
	WithdrawFiatWith2FAText                 string = "WITHDRAW FIAT WITH 2FA"
	WithdrawFiatWithSMSText                 string = "WITHDRAW FIAT WITH SMS"
	WithdrawFiatWithEmailText               string = "WITHDRAW FIAT WITH EMAIL"
	WithdrawFiatWithWebsiteApprovalText     string = "WITHDRAW FIAT WITH WEBSITE APPROVAL"
	WithdrawFiatWithAPIPermissionText       string = "WITHDRAW FIAT WITH API PERMISSION"
	WithdrawCryptoViaWebsiteOnly            uint32 = (1 << 16)
	WithdrawFiatViaWebsiteOnly              uint32 = (1 << 17)
	WithdrawCryptoViaWebsiteOnlyText        string = "WITHDRAW CRYPTO VIA WEBSITE ONLY"
	WithdrawFiatViaWebsiteOnlyText          string = "WITHDRAW FIAT VIA WEBSITE ONLY"
	NoFiatWithdrawals                       uint32 = (1 << 18)
	NoFiatWithdrawalsText                   string = "NO FIAT WITHDRAWAL"

	UnknownWithdrawalTypeText string = "UNKNOWN"

	RestAuthentication      uint8 = 0
	WebsocketAuthentication uint8 = 1

Definitions for each type of withdrawal method for a given exchange

View Source
const (
	NoWebsocketSupport       uint32 = 0
	WebsocketTickerSupported uint32 = 1 << (iota - 1)

	WebsocketTickerSupportedText                 = "TICKER STREAMING SUPPORTED"
	WebsocketOrderbookSupportedText              = "ORDERBOOK STREAMING SUPPORTED"
	WebsocketKlineSupportedText                  = "KLINE STREAMING SUPPORTED"
	WebsocketTradeDataSupportedText              = "TRADE STREAMING SUPPORTED"
	WebsocketAccountSupportedText                = "ACCOUNT STREAMING SUPPORTED"
	WebsocketAllowsRequestsText                  = "WEBSOCKET REQUESTS SUPPORTED"
	NoWebsocketSupportText                       = "WEBSOCKET NOT SUPPORTED"
	UnknownWebsocketFunctionality                = "UNKNOWN FUNCTIONALITY BITMASK"
	WebsocketSubscribeSupportedText              = "WEBSOCKET SUBSCRIBE SUPPORTED"
	WebsocketUnsubscribeSupportedText            = "WEBSOCKET UNSUBSCRIBE SUPPORTED"
	WebsocketAuthenticatedEndpointsSupportedText = "WEBSOCKET AUTHENTICATED ENDPOINTS SUPPORTED"
	WebsocketAccountDataSupportedText            = "WEBSOCKET ACCOUNT DATA SUPPORTED"
	WebsocketSubmitOrderSupportedText            = "WEBSOCKET SUBMIT ORDER SUPPORTED"
	WebsocketCancelOrderSupportedText            = "WEBSOCKET CANCEL ORDER SUPPORTED"
	WebsocketWithdrawSupportedText               = "WEBSOCKET WITHDRAW SUPPORTED"

	// WebsocketNotEnabled alerts of a disabled websocket
	WebsocketNotEnabled = "exchange_websocket_not_enabled"
	// WebsocketTrafficLimitTime defines a standard time for no traffic from the
	// websocket connection
	WebsocketTrafficLimitTime = 5 * time.Second

	// WebsocketStateTimeout defines a const for when a websocket connection
	// times out, will be handled by the routine management system
	WebsocketStateTimeout = "TIMEOUT"

Websocket functionality list and state consts


This section is empty.


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 FilterOrdersByCurrencies

func FilterOrdersByCurrencies(orders *[]OrderDetail, currencies []currency.Pair)

FilterOrdersByCurrencies removes any OrderDetails that do not match the provided currency list It is forgiving in that the provided currencies can match quote or base currencies

func FilterOrdersBySide

func FilterOrdersBySide(orders *[]OrderDetail, orderSide OrderSide)

FilterOrdersBySide removes any OrderDetails that don't match the orderStatus provided

func FilterOrdersByTickRange

func FilterOrdersByTickRange(orders *[]OrderDetail, startTicks, endTicks time.Time)

FilterOrdersByTickRange removes any OrderDetails outside of the tick range

func FilterOrdersByType

func FilterOrdersByType(orders *[]OrderDetail, orderType OrderType)

FilterOrdersByType removes any OrderDetails that don't match the orderType provided

func FormatCurrency

func FormatCurrency(p currency.Pair) currency.Pair

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 currency.Pair) currency.Pair

FormatExchangeCurrency is a method that formats and returns a currency pair based on the exchange currency format

func GetAndFormatExchangeCurrencies

func GetAndFormatExchangeCurrencies(exchName string, pairs []currency.Pair) (string, 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 SortOrdersByCurrency

func SortOrdersByCurrency(orders *[]OrderDetail, reverse bool)

SortOrdersByCurrency the caller function to sort orders

func SortOrdersByDate

func SortOrdersByDate(orders *[]OrderDetail, reverse bool)

SortOrdersByDate the caller function to sort orders

func SortOrdersByPrice

func SortOrdersByPrice(orders *[]OrderDetail, reverse bool)

SortOrdersByPrice the caller function to sort orders

func SortOrdersBySide

func SortOrdersBySide(orders *[]OrderDetail, reverse bool)

SortOrdersBySide the caller function to sort orders

func SortOrdersByType

func SortOrdersByType(orders *[]OrderDetail, reverse bool)

SortOrdersByType the caller function to sort orders


type Account

type Account struct {
	ID         string
	Currencies []AccountCurrencyInfo

Account defines a singular account type with asocciated currencies

type AccountCurrencyInfo

type AccountCurrencyInfo struct {
	CurrencyName currency.Code
	TotalValue   float64
	Hold         float64

AccountCurrencyInfo is a sub type to store currency name and value

type AccountInfo

type AccountInfo struct {
	Exchange string
	Accounts []Account

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
	RESTPollingDelay                           time.Duration
	AuthenticatedAPISupport                    bool
	AuthenticatedWebsocketAPISupport           bool
	APIWithdrawPermissions                     uint32
	APIAuthPEMKeySupport                       bool
	APISecret, APIKey, APIAuthPEMKey, ClientID string
	TakerFee, MakerFee, Fee                    float64
	BaseCurrencies                             currency.Currencies
	AvailablePairs                             currency.Pairs
	EnabledPairs                               currency.Pairs
	AssetTypes                                 []string
	PairsLastUpdated                           int64
	SupportsAutoPairUpdating                   bool
	SupportsRESTTickerBatching                 bool
	HTTPTimeout                                time.Duration
	HTTPUserAgent                              string
	HTTPDebugging                              bool
	WebsocketURL                               string
	APIUrl                                     string
	APIUrlDefault                              string
	APIUrlSecondary                            string
	APIUrlSecondaryDefault                     string
	RequestCurrencyPairFormat                  config.CurrencyPairFormatConfig
	ConfigCurrencyPairFormat                   config.CurrencyPairFormatConfig
	Websocket                                  *Websocket

Base stores the individual exchange information

func (*Base) FormatWithdrawPermissions

func (e *Base) FormatWithdrawPermissions() string

FormatWithdrawPermissions will return each of the exchange's compatible withdrawal methods in readable form

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

func (e *Base) GetAssetTypes() []string

GetAssetTypes returns the available asset types for an individual exchange

func (*Base) GetAuthenticatedAPISupport

func (e *Base) GetAuthenticatedAPISupport(endpoint uint8) bool

GetAuthenticatedAPISupport returns whether the exchange supports authenticated API requests

func (*Base) GetAvailableCurrencies

func (e *Base) GetAvailableCurrencies() currency.Pairs

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() currency.Pairs

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

func (e *Base) GetWithdrawPermissions() uint32

GetWithdrawPermissions passes through the exchange's withdraw permissions

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

func (e *Base) SetClientProxyAddress(addr string) error

SetClientProxyAddress sets a proxy address for REST and websocket requests

func (*Base) SetCurrencies

func (e *Base) SetCurrencies(pairs []currency.Pair, 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 currency.Pair, 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) SupportsWithdrawPermissions

func (e *Base) SupportsWithdrawPermissions(permissions uint32) bool

SupportsWithdrawPermissions compares the supplied permissions with the exchange's to verify they're supported

func (*Base) UpdateCurrencies

func (e *Base) UpdateCurrencies(exchangeProducts currency.Pairs, enabled, force bool) error

UpdateCurrencies updates the exchange currency pairs for either enabledPairs or availablePairs

func (*Base) WebsocketInit

func (e *Base) WebsocketInit()

WebsocketInit initialises the websocket struct

func (*Base) WebsocketSetup

func (e *Base) WebsocketSetup(connector func() error,
	subscriber func(channelToSubscribe WebsocketChannelSubscription) error,
	unsubscriber func(channelToUnsubscribe WebsocketChannelSubscription) error,
	exchangeName string,
	verbose bool,
	runningURL string) error

WebsocketSetup sets main variables for websocket connection

type ByCurrency

type ByCurrency []OrderDetail

ByCurrency used for sorting orders by order currency

func (ByCurrency) Len

func (b ByCurrency) Len() int

func (ByCurrency) Less

func (b ByCurrency) Less(i, j int) bool

func (ByCurrency) Swap

func (b ByCurrency) Swap(i, j int)

type ByDate

type ByDate []OrderDetail

ByDate used for sorting orders by order date

func (ByDate) Len

func (b ByDate) Len() int

func (ByDate) Less

func (b ByDate) Less(i, j int) bool

func (ByDate) Swap

func (b ByDate) Swap(i, j int)

type ByOrderSide

type ByOrderSide []OrderDetail

ByOrderSide used for sorting orders by order side (buy sell)

func (ByOrderSide) Len

func (b ByOrderSide) Len() int

func (ByOrderSide) Less

func (b ByOrderSide) Less(i, j int) bool

func (ByOrderSide) Swap

func (b ByOrderSide) Swap(i, j int)

type ByOrderType

type ByOrderType []OrderDetail

ByOrderType used for sorting orders by order type

func (ByOrderType) Len

func (b ByOrderType) Len() int

func (ByOrderType) Less

func (b ByOrderType) Less(i, j int) bool

func (ByOrderType) Swap

func (b ByOrderType) Swap(i, j int)

type ByPrice

type ByPrice []OrderDetail

ByPrice used for sorting orders by price

func (ByPrice) Len

func (b ByPrice) Len() int

func (ByPrice) Less

func (b ByPrice) Less(i, j int) bool

func (ByPrice) Swap

func (b ByPrice) Swap(i, j int)

type CancelAllOrdersResponse

type CancelAllOrdersResponse struct {
	OrderStatus map[string]string

CancelAllOrdersResponse returns the status from attempting to cancel all orders on an exchagne

type FeeBuilder

type FeeBuilder struct {
	IsMaker             bool
	PurchasePrice       float64
	Amount              float64
	FeeType             FeeType
	FiatCurrency        currency.Code
	BankTransactionType InternationalBankTransactionType
	Pair                currency.Pair

FeeBuilder is the type which holds all parameters required to calculate a fee for an exchange

type FeeType

type FeeType uint8

FeeType custom type for calculating fees based on method

const (
	BankFee FeeType = iota

Const declarations for fee types

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        string
	Description       string
	Timestamp         time.Time
	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 GetOrdersRequest

type GetOrdersRequest struct {
	OrderType  OrderType
	OrderSide  OrderSide
	StartTicks time.Time
	EndTicks   time.Time
	// Currencies Empty array = all currencies. Some endpoints only support singular currency enquiries
	Currencies []currency.Pair

GetOrdersRequest used for GetOrderHistory and GetOpenOrders wrapper functions

type IBotExchange

type IBotExchange interface {
	Setup(exch *config.ExchangeConfig)
	Start(wg *sync.WaitGroup)
	GetName() string
	IsEnabled() bool
	GetTickerPrice(currency currency.Pair, assetType string) (ticker.Price, error)
	UpdateTicker(currency currency.Pair, assetType string) (ticker.Price, error)
	GetOrderbookEx(currency currency.Pair, assetType string) (orderbook.Base, error)
	UpdateOrderbook(currency currency.Pair, assetType string) (orderbook.Base, error)
	GetEnabledCurrencies() currency.Pairs
	GetAvailableCurrencies() currency.Pairs
	GetAssetTypes() []string
	GetAccountInfo() (AccountInfo, error)
	GetAuthenticatedAPISupport(endpoint uint8) bool
	SetCurrencies(pairs []currency.Pair, enabledPairs bool) error
	GetExchangeHistory(p currency.Pair, assetType string) ([]TradeHistory, error)
	SupportsAutoPairUpdates() bool
	GetLastPairsUpdateTime() int64
	SupportsRESTTickerBatchUpdates() bool
	GetFeeByType(feeBuilder *FeeBuilder) (float64, error)
	GetWithdrawPermissions() uint32
	FormatWithdrawPermissions() string
	SupportsWithdrawPermissions(permissions uint32) bool
	GetFundingHistory() ([]FundHistory, error)
	SubmitOrder(p currency.Pair, side OrderSide, orderType OrderType, amount, price float64, clientID string) (SubmitOrderResponse, error)
	ModifyOrder(action *ModifyOrder) (string, error)
	CancelOrder(order *OrderCancellation) error
	CancelAllOrders(orders *OrderCancellation) (CancelAllOrdersResponse, error)
	GetOrderInfo(orderID string) (OrderDetail, error)
	GetDepositAddress(cryptocurrency currency.Code, accountID string) (string, error)
	GetOrderHistory(getOrdersRequest *GetOrdersRequest) ([]OrderDetail, error)
	GetActiveOrders(getOrdersRequest *GetOrdersRequest) ([]OrderDetail, error)
	WithdrawCryptocurrencyFunds(withdrawRequest *WithdrawRequest) (string, error)
	WithdrawFiatFunds(withdrawRequest *WithdrawRequest) (string, error)
	WithdrawFiatFundsToInternationalBank(withdrawRequest *WithdrawRequest) (string, error)
	GetWebsocket() (*Websocket, error)
	SubscribeToWebsocketChannels(channels []WebsocketChannelSubscription) error
	UnsubscribeToWebsocketChannels(channels []WebsocketChannelSubscription) error
	AuthenticateWebsocket() error
	GetSubscriptions() ([]WebsocketChannelSubscription, error)

IBotExchange enforces standard functions for all exchanges supported in GoCryptoTrader

type InternationalBankTransactionType

type InternationalBankTransactionType uint8

InternationalBankTransactionType custom type for calculating fees based on fiat transaction types

const (
	WireTransfer InternationalBankTransactionType = iota

Const declarations for international transaction types

type KlineData

type KlineData struct {
	Timestamp  time.Time
	Pair       currency.Pair
	AssetType  string
	Exchange   string
	StartTime  time.Time
	CloseTime  time.Time
	Interval   string
	OpenPrice  float64
	ClosePrice float64
	HighPrice  float64
	LowPrice   float64
	Volume     float64

KlineData defines kline feed

type ModifyOrder

type ModifyOrder struct {
	OrderID string
	Price           float64
	Amount          float64
	LimitPriceUpper float64
	LimitPriceLower float64
	CurrencyPair    currency.Pair

	ImmediateOrCancel bool
	HiddenOrder       bool
	FillOrKill        bool
	PostOnly          bool

ModifyOrder is a an order modifyer

type ModifyOrderResponse

type ModifyOrderResponse struct {
	OrderID string

ModifyOrderResponse is an order modifying return type

type OrderCancellation

type OrderCancellation struct {
	AccountID     string
	OrderID       string
	WalletAddress string
	Side          OrderSide
	CurrencyPair  currency.Pair

OrderCancellation type required when requesting to cancel an order

type OrderDetail

type OrderDetail struct {
	Exchange        string
	AccountID       string
	ID              string
	CurrencyPair    currency.Pair
	OrderSide       OrderSide
	OrderType       OrderType
	OrderDate       time.Time
	Status          string
	Price           float64
	Amount          float64
	ExecutedAmount  float64
	RemainingAmount float64
	Fee             float64
	Trades          []TradeHistory

OrderDetail holds order detail data

type OrderSide

type OrderSide string

OrderSide enforces a standard for OrderSides across the code base

const (
	AnyOrderSide  OrderSide = "ANY"
	BuyOrderSide  OrderSide = "BUY"
	SellOrderSide OrderSide = "SELL"
	BidOrderSide  OrderSide = "BID"
	AskOrderSide  OrderSide = "ASK"

OrderSide types

func (OrderSide) ToString

func (o OrderSide) ToString() string

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

type OrderStatus

type OrderStatus string

OrderStatus defines order status types

const (
	AnyOrderStatus             OrderStatus = "ANY"
	NewOrderStatus             OrderStatus = "NEW"
	ActiveOrderStatus          OrderStatus = "ACTIVE"
	PartiallyFilledOrderStatus OrderStatus = "PARTIALLY_FILLED"
	FilledOrderStatus          OrderStatus = "FILLED"
	CancelledOrderStatus       OrderStatus = "CANCELED"
	PendingCancelOrderStatus   OrderStatus = "PENDING_CANCEL"
	RejectedOrderStatus        OrderStatus = "REJECTED"
	ExpiredOrderStatus         OrderStatus = "EXPIRED"
	HiddenOrderStatus          OrderStatus = "HIDDEN"
	UnknownOrderStatus         OrderStatus = "UNKNOWN"

All OrderStatus types

type OrderType

type OrderType string

OrderType enforces a standard for Ordertypes across the code base

const (
	AnyOrderType               OrderType = "ANY"
	LimitOrderType             OrderType = "LIMIT"
	MarketOrderType            OrderType = "MARKET"
	ImmediateOrCancelOrderType OrderType = "IMMEDIATE_OR_CANCEL"
	StopOrderType              OrderType = "STOP"
	TrailingStopOrderType      OrderType = "TRAILINGSTOP"
	UnknownOrderType           OrderType = "UNKNOWN"

OrderType ...types

func (OrderType) ToString

func (o OrderType) ToString() string

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

type SubmitOrderResponse

type SubmitOrderResponse struct {
	IsOrderPlaced bool
	OrderID       string

SubmitOrderResponse is what is returned after submitting an order to an exchange

type TickerData

type TickerData struct {
	Timestamp  time.Time
	Pair       currency.Pair
	AssetType  string
	Exchange   string
	ClosePrice float64
	Quantity   float64
	OpenPrice  float64
	HighPrice  float64
	LowPrice   float64

TickerData defines ticker feed

type TradeData

type TradeData struct {
	Timestamp    time.Time
	CurrencyPair currency.Pair
	AssetType    string
	Exchange     string
	EventType    string
	EventTime    int64
	Price        float64
	Amount       float64
	Side         string

TradeData defines trade data

type TradeHistory

type TradeHistory struct {
	Timestamp   time.Time
	TID         int64
	Price       float64
	Amount      float64
	Exchange    string
	Type        string
	Fee         float64
	Description string

TradeHistory holds exchange history data

type Websocket

type Websocket struct {

	// Connected denotes a channel switch for diversion of request flow
	Connected chan struct{}
	// Disconnected denotes a channel switch for diversion of request flow
	Disconnected chan struct{}
	// DataHandler pipes websocket data to an exchange websocket data handler
	DataHandler chan interface{}
	// ShutdownC is the main shutdown channel which controls all websocket go funcs
	ShutdownC                 chan struct{}
	ShutdownConnectionMonitor chan struct{}
	// Orderbook is a local cache of orderbooks
	Orderbook WebsocketOrderbookLocal

	// Wg defines a wait group for websocket routines for cleanly shutting down
	// routines
	Wg sync.WaitGroup
	// TrafficAlert monitors if there is a halt in traffic throughput
	TrafficAlert chan struct{}
	// Functionality defines websocket stream capabilities
	Functionality uint32
	// contains filtered or unexported fields

Websocket defines a return type for websocket connections via the interface wrapper for routine processing in routines.go

func (*Websocket) CanUseAuthenticatedEndpoints

func (w *Websocket) CanUseAuthenticatedEndpoints() bool

CanUseAuthenticatedEndpoints gets canUseAuthenticatedEndpoints val in a thread safe manner

func (*Websocket) Connect

func (w *Websocket) Connect() error

Connect intiates a websocket connection by using a package defined connection function

func (*Websocket) FormatFunctionality

func (w *Websocket) FormatFunctionality() string

FormatFunctionality will return each of the websocket connection compatible stream methods as a string

func (*Websocket) GetDefaultURL

func (w *Websocket) GetDefaultURL() string

GetDefaultURL returns the default websocket URL

func (*Websocket) GetFunctionality

func (w *Websocket) GetFunctionality() uint32

GetFunctionality returns a functionality bitmask for the websocket connection

func (*Websocket) GetName

func (w *Websocket) GetName() string

GetName returns exchange name

func (*Websocket) GetProxyAddress

func (w *Websocket) GetProxyAddress() string

GetProxyAddress returns the current websocket proxy

func (*Websocket) GetSubscriptions

func (w *Websocket) GetSubscriptions() []WebsocketChannelSubscription

GetSubscriptions returns a copied list of subscriptions subscriptions is a private member and cannot be manipulated

func (*Websocket) GetWebsocketURL

func (w *Websocket) GetWebsocketURL() string

GetWebsocketURL returns the running websocket URL

func (*Websocket) IsConnected

func (w *Websocket) IsConnected() bool

IsConnected exposes websocket connection status

func (*Websocket) IsConnecting

func (w *Websocket) IsConnecting() bool

IsConnecting checks whether websocket is busy connecting

func (*Websocket) IsEnabled

func (w *Websocket) IsEnabled() bool

IsEnabled returns bool

func (*Websocket) ResubscribeToChannel

func (w *Websocket) ResubscribeToChannel(subscribedChannel WebsocketChannelSubscription)

ResubscribeToChannel calls unsubscribe func and removes it from subscribedChannels to trigger a subscribe event

func (*Websocket) SetCanUseAuthenticatedEndpoints

func (w *Websocket) SetCanUseAuthenticatedEndpoints(val bool)

SetCanUseAuthenticatedEndpoints sets canUseAuthenticatedEndpoints val in a thread safe manner

func (*Websocket) SetChannelSubscriber

func (w *Websocket) SetChannelSubscriber(subscriber func(channelToSubscribe WebsocketChannelSubscription) error)

SetChannelSubscriber sets the function to use the base subscribe func

func (*Websocket) SetChannelUnsubscriber

func (w *Websocket) SetChannelUnsubscriber(unsubscriber func(channelToUnsubscribe WebsocketChannelSubscription) error)

SetChannelUnsubscriber sets the function to use the base unsubscribe func

func (*Websocket) SetConnector

func (w *Websocket) SetConnector(connector func() error)

SetConnector sets connection function

func (*Websocket) SetDefaultURL

func (w *Websocket) SetDefaultURL(defaultURL string)

SetDefaultURL sets default websocket URL

func (*Websocket) SetExchangeName

func (w *Websocket) SetExchangeName(exchName string)

SetExchangeName sets exchange name

func (*Websocket) SetProxyAddress

func (w *Websocket) SetProxyAddress(proxyAddr string) error

SetProxyAddress sets websocket proxy address

func (*Websocket) SetWebsocketURL

func (w *Websocket) SetWebsocketURL(websocketURL string)

SetWebsocketURL sets websocket URL

func (*Websocket) SetWsStatusAndConnection

func (w *Websocket) SetWsStatusAndConnection(enabled bool) error

SetWsStatusAndConnection sets if websocket is enabled it will also connect/disconnect the websocket connection

func (*Websocket) Shutdown

func (w *Websocket) Shutdown() error

Shutdown attempts to shut down a websocket connection and associated routines by using a package defined shutdown function

func (*Websocket) SubscribeToChannels

func (w *Websocket) SubscribeToChannels(channels []WebsocketChannelSubscription)

SubscribeToChannels appends supplied channels to channelsToSubscribe

func (*Websocket) SupportsFunctionality

func (w *Websocket) SupportsFunctionality(f uint32) bool

SupportsFunctionality returns if the functionality is supported as a boolean

func (*Websocket) UnsubscribeToChannels

func (w *Websocket) UnsubscribeToChannels(channels []WebsocketChannelSubscription)

UnsubscribeToChannels removes supplied channels from channelsToSubscribe

func (*Websocket) WebsocketReset

func (w *Websocket) WebsocketReset() error

WebsocketReset sends the shutdown command, waits for channel/func closure and then reconnects

type WebsocketChannelSubscription

type WebsocketChannelSubscription struct {
	Channel  string
	Currency currency.Pair
	Params   map[string]interface{}

WebsocketChannelSubscription container for websocket subscriptions Currently only a one at a time thing to avoid complexity

func (*WebsocketChannelSubscription) Equal

func (w *WebsocketChannelSubscription) Equal(subscribedChannel *WebsocketChannelSubscription) bool

Equal two WebsocketChannelSubscription to determine equality

type WebsocketOrderbookLocal

type WebsocketOrderbookLocal struct {
	// contains filtered or unexported fields

WebsocketOrderbookLocal defines a local cache of orderbooks for amending, appending and deleting changes and updates the main store in orderbook.go

func (*WebsocketOrderbookLocal) FlushCache

func (w *WebsocketOrderbookLocal) FlushCache()

FlushCache flushes w.ob data to be garbage collected and refreshed when a connection is lost and reconnected

func (*WebsocketOrderbookLocal) LoadSnapshot

func (w *WebsocketOrderbookLocal) LoadSnapshot(newOrderbook *orderbook.Base, exchName string, overwrite bool) error

LoadSnapshot loads initial snapshot of orderbook data, overite allows full orderbook to be completely rewritten because the exchange is a doing a full update not an incremental one

func (*WebsocketOrderbookLocal) Update

func (w *WebsocketOrderbookLocal) Update(bidTargets, askTargets []orderbook.Item,
	p currency.Pair,
	updated time.Time,
	exchName, assetType string) error

Update updates a local cache using bid targets and ask targets then updates main cache in orderbook.go Volume == 0; deletion at price target Price target not found; append of price target Price target found; amend volume of price target

func (*WebsocketOrderbookLocal) UpdateUsingID

func (w *WebsocketOrderbookLocal) UpdateUsingID(bidTargets, askTargets []orderbook.Item,
	p currency.Pair,
	exchName, assetType, action string) error

UpdateUsingID updates orderbooks using specified ID

type WebsocketOrderbookUpdate

type WebsocketOrderbookUpdate struct {
	Pair     currency.Pair
	Asset    string
	Exchange string

WebsocketOrderbookUpdate defines a websocket event in which the orderbook has been updated in the orderbook package

type WebsocketPositionUpdated

type WebsocketPositionUpdated struct {
	Timestamp time.Time
	Pair      currency.Pair
	AssetType string
	Exchange  string

WebsocketPositionUpdated reflects a change in orders/contracts on an exchange

type WebsocketResponse

type WebsocketResponse struct {
	Type int
	Raw  []byte

WebsocketResponse defines generalised data from the websocket connection

type WithdrawRequest

type WithdrawRequest struct {
	// General withdraw information
	Description     string
	OneTimePassword int64
	AccountID       string
	PIN             int64
	TradePassword   string
	Amount          float64
	Currency        currency.Code
	// Crypto related information
	Address    string
	AddressTag string
	FeeAmount  float64
	// FIAT related information
	BankAccountName   string
	BankAccountNumber float64
	BankName          string
	BankAddress       string
	BankCity          string
	BankCountry       string
	BankPostalCode    string
	SwiftCode         string
	IBAN              string
	BankCode          float64
	IsExpressWire     bool
	// Intermediary bank information
	RequiresIntermediaryBank      bool
	IntermediaryBankAccountNumber float64
	IntermediaryBankName          string
	IntermediaryBankAddress       string
	IntermediaryBankCity          string
	IntermediaryBankCountry       string
	IntermediaryBankPostalCode    string
	IntermediarySwiftCode         string
	IntermediaryBankCode          float64
	IntermediaryIBAN              string
	WireCurrency                  string

WithdrawRequest used for wrapper crypto and FIAT withdraw methods


Path Synopsis
Package gemini exchange documentation can be found at
Package gemini exchange documentation can be found at

Jump to

Keyboard shortcuts

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