exchange

package
v0.0.0-...-83dca6d Latest Latest
Warning

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

Go to latest
Published: May 23, 2022 License: MIT Imports: 30 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 progress 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

Guide for adding a new exchange

  • A guide on implementing API support for a new exchange can be found here

websocket notes

  • If contributing websocket improvements, please make sure order reports follow these rules.
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:

bc1qk0jareu4jytc0cfrhr5wgshsq8282awpavfahc

Documentation

Index

Constants

View Source
const (

	// DefaultHTTPTimeout is the default HTTP/HTTPS Timeout for exchange requests
	DefaultHTTPTimeout = time.Second * 15
	// DefaultWebsocketResponseCheckTimeout is the default delay in checking for an expected websocket response
	DefaultWebsocketResponseCheckTimeout = time.Millisecond * 50
	// DefaultWebsocketResponseMaxLimit is the default max wait for an expected websocket response before a timeout
	DefaultWebsocketResponseMaxLimit = time.Second * 7
	// DefaultWebsocketOrderbookBufferLimit is the maximum number of orderbook updates that get stored before being applied
	DefaultWebsocketOrderbookBufferLimit = 5
	// ResetConfigPairsWarningMessage is displayed when a currency pair format in the config needs to be updated
	ResetConfigPairsWarningMessage = "" /* 135-byte string literal not displayed */
)
View Source
const (
	RestAuthentication      uint8 = 0
	WebsocketAuthentication uint8 = 1
	// Repeated exchange strings
	// FeeType custom type for calculating fees based on method
	WireTransfer InternationalBankTransactionType = iota
	PerfectMoney
	Neteller
	AdvCash
	Payeer
	Skrill
	Simplex
	SEPA
	Swift
	RapidTransfer
	MisterTangoSEPA
	Qiwi
	VisaMastercard
	WebMoney
	Capitalist
	WesternUnion
	MoneyGram
	Contact
	// Const declarations for fee types
	BankFee FeeType = iota
	InternationalBankDepositFee
	InternationalBankWithdrawalFee
	CryptocurrencyTradeFee
	CryptocurrencyDepositFee
	CryptocurrencyWithdrawalFee
	OfflineTradeFee
	// Definitions for each type of withdrawal method for a given exchange
	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"
)

Endpoint authentication types

Variables

View Source
var (
	// ErrAuthenticatedRequestWithoutCredentialsSet error message for authenticated request without credentials set
	ErrAuthenticatedRequestWithoutCredentialsSet = errors.New("authenticated HTTP request called but not supported due to unset/default API keys")

	// ErrPairNotFound is an error message for when unable to find a currency pair
	ErrPairNotFound = errors.New("pair not found")
)
View Source
var Exchanges = []string{
	"binance",
	"bitfinex",
	"bitflyer",
	"bithumb",
	"bitmex",
	"bitstamp",
	"bittrex",
	"btc markets",
	"btse",
	"coinbasepro",
	"coinut",
	"exmo",
	"ftx",
	"gateio",
	"gemini",
	"hitbtc",
	"huobi",
	"itbit",
	"kraken",
	"lbank",
	"localbitcoins",
	"okcoin international",
	"okex",
	"poloniex",
	"yobit",
	"zb",
}

Exchanges stores a list of supported exchanges

Functions

func IsSupported

func IsSupported(exchangeName string) bool

IsSupported returns whether or not a specific exchange is supported

Types

type API

type API struct {
	AuthenticatedSupport          bool
	AuthenticatedWebsocketSupport bool
	PEMKeySupport                 bool

	Endpoints *Endpoints

	Credentials struct {
		Key        string
		Secret     string
		ClientID   string
		PEMKey     string
		Subaccount string
	}

	CredentialsValidator struct {
		// For Huobi (optional)
		RequiresPEM bool

		RequiresKey                bool
		RequiresSecret             bool
		RequiresClientID           bool
		RequiresBase64DecodeSecret bool
	}
}

API stores the exchange API settings

type AssetWebsocketSupport

type AssetWebsocketSupport struct {
	// contains filtered or unexported fields
}

AssetWebsocketSupport defines the availability of websocket functionality to the specific asset type. TODO: Deprecate as this is a temp item to address certain limitations quickly.

func (*AssetWebsocketSupport) IsAssetWebsocketSupported

func (a *AssetWebsocketSupport) IsAssetWebsocketSupported(aType asset.Item) bool

IsAssetWebsocketSupported checks to see if the supplied asset type is supported by websocket.

type Base

type Base struct {
	Name                          string
	Enabled                       bool
	Verbose                       bool
	LoadedByConfig                bool
	SkipAuthCheck                 bool
	API                           API
	BaseCurrencies                currency.Currencies
	CurrencyPairs                 currency.PairsManager
	Features                      Features
	HTTPTimeout                   time.Duration
	HTTPUserAgent                 string
	HTTPRecording                 bool
	HTTPDebugging                 bool
	BypassConfigFormatUpgrades    bool
	WebsocketResponseCheckTimeout time.Duration
	WebsocketResponseMaxLimit     time.Duration
	WebsocketOrderbookBufferLimit int64
	Websocket                     *stream.Websocket
	*request.Requester
	Config *config.Exchange

	// CanVerifyOrderbook determines if the orderbook verification can be bypassed,
	// increasing potential update speed but decreasing confidence in orderbook
	// integrity.
	CanVerifyOrderbook bool
	order.ExecutionLimits

	AssetWebsocketSupport
	*currencystate.States
	// contains filtered or unexported fields
}

Base stores the individual exchange information

func (*Base) AddTradesToBuffer

func (b *Base) AddTradesToBuffer(trades ...trade.Data) error

AddTradesToBuffer is a helper function that will only add trades to the buffer if it is allowed

func (*Base) AllowAuthenticatedRequest

func (b *Base) AllowAuthenticatedRequest() bool

AllowAuthenticatedRequest checks to see if the required fields have been set before sending an authenticated API request

func (*Base) AuthenticateWebsocket

func (b *Base) AuthenticateWebsocket(_ context.Context) error

AuthenticateWebsocket sends an authentication message to the websocket

func (*Base) CheckTransientError

func (b *Base) CheckTransientError(err error) error

CheckTransientError catches transient errors and returns nil if found, used for validation of API credentials

func (*Base) DisableAssetWebsocketSupport

func (b *Base) DisableAssetWebsocketSupport(aType asset.Item) error

DisableAssetWebsocketSupport disables websocket functionality for the supplied asset item. In the case that websocket functionality has not yet been implemented for that specific asset type. This is a base method to check availability of asset type.

func (*Base) DisableRateLimiter

func (b *Base) DisableRateLimiter() error

DisableRateLimiter disables the rate limiting system for the exchange

func (*Base) EnableRateLimiter

func (b *Base) EnableRateLimiter() error

EnableRateLimiter enables the rate limiting system for the exchange

func (*Base) FlushWebsocketChannels

func (b *Base) FlushWebsocketChannels() error

FlushWebsocketChannels refreshes websocket channel subscriptions based on websocket features. Used in the event of a pair/asset or subscription change.

func (*Base) FormatExchangeCurrencies

func (b *Base) FormatExchangeCurrencies(pairs []currency.Pair, assetType asset.Item) (string, error)

FormatExchangeCurrencies returns a string containing the exchanges formatted currency pairs

func (*Base) FormatExchangeCurrency

func (b *Base) FormatExchangeCurrency(p currency.Pair, assetType asset.Item) (currency.Pair, error)

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

func (*Base) FormatExchangeKlineInterval

func (b *Base) FormatExchangeKlineInterval(in kline.Interval) string

FormatExchangeKlineInterval returns Interval to string Exchanges can override this if they require custom formatting

func (*Base) FormatSymbol

func (b *Base) FormatSymbol(pair currency.Pair, assetType asset.Item) (string, error)

FormatSymbol formats the given pair to a string suitable for exchange API requests

func (*Base) FormatWithdrawPermissions

func (b *Base) FormatWithdrawPermissions() string

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

func (*Base) GetAssetTypes

func (b *Base) GetAssetTypes(enabled bool) asset.Items

GetAssetTypes returns the either the enabled or available asset types for an individual exchange

func (*Base) GetAuthenticatedAPISupport

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

GetAuthenticatedAPISupport returns whether the exchange supports authenticated API requests

func (*Base) GetAvailablePairs

func (b *Base) GetAvailablePairs(assetType asset.Item) (currency.Pairs, error)

GetAvailablePairs is a method that returns the available currency pairs of the exchange by asset type

func (*Base) GetAvailableTransferChains

func (b *Base) GetAvailableTransferChains(_ context.Context, _ currency.Code) ([]string, error)

GetAvailableTransferChains returns a list of supported transfer chains based on the supplied cryptocurrency

func (*Base) GetBase

func (b *Base) GetBase() *Base

GetBase returns the exchange base

func (*Base) GetClientBankAccounts

func (b *Base) GetClientBankAccounts(exchangeName, withdrawalCurrency string) (*banking.Account, error)

GetClientBankAccounts returns banking details associated with a client for withdrawal purposes

func (*Base) GetEnabledFeatures

func (b *Base) GetEnabledFeatures() FeaturesEnabled

GetEnabledFeatures returns the exchanges enabled features

func (*Base) GetEnabledPairs

func (b *Base) GetEnabledPairs(a asset.Item) (currency.Pairs, error)

GetEnabledPairs is a method that returns the enabled currency pairs of the exchange by asset type, if the asset type is disabled this will return no enabled pairs

func (*Base) GetExchangeBankAccounts

func (b *Base) GetExchangeBankAccounts(id, depositCurrency string) (*banking.Account, error)

GetExchangeBankAccounts returns banking details associated with an exchange for funding purposes

func (*Base) GetHTTPClient

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

GetHTTPClient gets the exchanges HTTP client

func (*Base) GetHTTPClientUserAgent

func (b *Base) GetHTTPClientUserAgent() string

GetHTTPClientUserAgent gets the exchanges HTTP user agent

func (*Base) GetLastPairsUpdateTime

func (b *Base) GetLastPairsUpdateTime() int64

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

func (*Base) GetName

func (b *Base) GetName() string

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

func (*Base) GetPairAssetType

func (b *Base) GetPairAssetType(c currency.Pair) (asset.Item, error)

GetPairAssetType returns the associated asset type for the currency pair This method is only useful for exchanges that have pair names with multiple delimiters (BTC-USD-0626) Helpful if the exchange has only a single asset type but in that case the asset type can be hard coded

func (*Base) GetPairFormat

func (b *Base) GetPairFormat(assetType asset.Item, requestFormat bool) (currency.PairFormat, error)

GetPairFormat returns the pair format based on the exchange and asset type

func (*Base) GetRequestFormattedPairAndAssetType

func (b *Base) GetRequestFormattedPairAndAssetType(p string) (currency.Pair, asset.Item, error)

GetRequestFormattedPairAndAssetType is a method that returns the enabled currency pair of along with its asset type. Only use when there is no chance of the same name crossing over

func (*Base) GetSubscriptions

func (b *Base) GetSubscriptions() ([]stream.ChannelSubscription, error)

GetSubscriptions returns a copied list of subscriptions

func (*Base) GetSupportedFeatures

func (b *Base) GetSupportedFeatures() FeaturesSupported

GetSupportedFeatures returns the exchanges supported features

func (*Base) GetWebsocket

func (b *Base) GetWebsocket() (*stream.Websocket, error)

GetWebsocket returns a pointer to the exchange websocket

func (*Base) GetWithdrawPermissions

func (b *Base) GetWithdrawPermissions() uint32

GetWithdrawPermissions passes through the exchange's withdraw permissions

func (*Base) IsEnabled

func (b *Base) IsEnabled() bool

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

func (*Base) IsFillsFeedEnabled

func (b *Base) IsFillsFeedEnabled() bool

IsFillsFeedEnabled checks the state of FillsFeed in a concurrent-friendly manner

func (*Base) IsSaveTradeDataEnabled

func (b *Base) IsSaveTradeDataEnabled() bool

IsSaveTradeDataEnabled checks the state of SaveTradeData in a concurrent-friendly manner

func (*Base) IsTradeFeedEnabled

func (b *Base) IsTradeFeedEnabled() bool

IsTradeFeedEnabled checks the state of TradeFeed in a concurrent-friendly manner

func (*Base) IsWebsocketEnabled

func (b *Base) IsWebsocketEnabled() bool

IsWebsocketEnabled returns whether or not the exchange has its websocket client enabled

func (*Base) NewEndpoints

func (b *Base) NewEndpoints() *Endpoints

NewEndpoints declares default and running URLs maps

func (*Base) PrintEnabledPairs

func (b *Base) PrintEnabledPairs()

PrintEnabledPairs prints the exchanges enabled asset pairs

func (*Base) SetAPICredentialDefaults

func (b *Base) SetAPICredentialDefaults()

SetAPICredentialDefaults sets the API Credential validator defaults

func (*Base) SetAPIKeys

func (b *Base) SetAPIKeys(apiKey, apiSecret, clientID string)

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

func (*Base) SetAPIURL

func (b *Base) SetAPIURL() error

SetAPIURL sets configuration API URL for an exchange

func (*Base) SetClientProxyAddress

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

SetClientProxyAddress sets a proxy address for REST and websocket requests

func (*Base) SetConfigPairs

func (b *Base) SetConfigPairs() error

SetConfigPairs sets the exchanges currency pairs to the pairs set in the config

func (*Base) SetCurrencyPairFormat

func (b *Base) SetCurrencyPairFormat()

SetCurrencyPairFormat checks the exchange request and config currency pair formats and syncs it with the exchanges SetDefault settings

func (*Base) SetEnabled

func (b *Base) SetEnabled(enabled bool)

SetEnabled is a method that sets if the exchange is enabled

func (*Base) SetFeatureDefaults

func (b *Base) SetFeatureDefaults()

SetFeatureDefaults sets the exchanges default feature support set

func (*Base) SetFillsFeedStatus

func (b *Base) SetFillsFeedStatus(enabled bool)

SetFillsFeedStatus locks and sets the status of the config and the exchange's setting for FillsFeed

func (*Base) SetGlobalPairsManager

func (b *Base) SetGlobalPairsManager(request, config *currency.PairFormat, assets ...asset.Item) error

SetGlobalPairsManager sets defined asset and pairs management system with with global formatting

func (*Base) SetHTTPClient

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

SetHTTPClient sets exchanges HTTP client

func (*Base) SetHTTPClientTimeout

func (b *Base) SetHTTPClientTimeout(t time.Duration) error

SetHTTPClientTimeout sets the timeout value for the exchanges HTTP Client and also the underlying transports idle connection timeout

func (*Base) SetHTTPClientUserAgent

func (b *Base) SetHTTPClientUserAgent(ua string)

SetHTTPClientUserAgent sets the exchanges HTTP user agent

func (*Base) SetPairs

func (b *Base) SetPairs(pairs currency.Pairs, assetType asset.Item, enabled bool) error

SetPairs sets the exchange currency pairs for either enabledPairs or availablePairs

func (*Base) SetSaveTradeDataStatus

func (b *Base) SetSaveTradeDataStatus(enabled bool)

SetSaveTradeDataStatus locks and sets the status of the config and the exchange's setting for SaveTradeData

func (*Base) SetTradeFeedStatus

func (b *Base) SetTradeFeedStatus(enabled bool)

SetTradeFeedStatus locks and sets the status of the config and the exchange's setting for TradeFeed

func (*Base) SetupDefaults

func (b *Base) SetupDefaults(exch *config.Exchange) error

SetupDefaults sets the exchange settings based on the supplied config

func (*Base) StoreAssetPairFormat

func (b *Base) StoreAssetPairFormat(a asset.Item, f currency.PairStore) error

StoreAssetPairFormat initialises and stores a defined asset format

func (*Base) SubscribeToWebsocketChannels

func (b *Base) SubscribeToWebsocketChannels(channels []stream.ChannelSubscription) error

SubscribeToWebsocketChannels appends to ChannelsToSubscribe which lets websocket.manageSubscriptions handle subscribing

func (*Base) SupportsAsset

func (b *Base) SupportsAsset(a asset.Item) bool

SupportsAsset whether or not the supplied asset is supported by the exchange

func (*Base) SupportsAutoPairUpdates

func (b *Base) SupportsAutoPairUpdates() bool

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

func (*Base) SupportsPair

func (b *Base) SupportsPair(p currency.Pair, enabledPairs bool, assetType asset.Item) error

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

func (*Base) SupportsREST

func (b *Base) SupportsREST() bool

SupportsREST returns whether or not the exchange supports REST

func (*Base) SupportsRESTTickerBatchUpdates

func (b *Base) SupportsRESTTickerBatchUpdates() bool

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

func (*Base) SupportsWebsocket

func (b *Base) SupportsWebsocket() bool

SupportsWebsocket returns whether or not the exchange supports websocket

func (*Base) SupportsWithdrawPermissions

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

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

func (*Base) UnsubscribeToWebsocketChannels

func (b *Base) UnsubscribeToWebsocketChannels(channels []stream.ChannelSubscription) error

UnsubscribeToWebsocketChannels removes from ChannelsToSubscribe which lets websocket.manageSubscriptions handle unsubscribing

func (*Base) UpdateCurrencyStates

func (b *Base) UpdateCurrencyStates(ctx context.Context, a asset.Item) error

UpdateCurrencyStates updates currency states

func (*Base) UpdateOrderExecutionLimits

func (b *Base) UpdateOrderExecutionLimits(_ context.Context, _ asset.Item) error

UpdateOrderExecutionLimits updates order execution limits this is overridable

func (*Base) UpdatePairs

func (b *Base) UpdatePairs(exchangeProducts currency.Pairs, assetType asset.Item, enabled, force bool) error

UpdatePairs updates the exchange currency pairs for either enabledPairs or availablePairs

func (*Base) ValidateAPICredentials

func (b *Base) ValidateAPICredentials() bool

ValidateAPICredentials validates the exchanges API credentials

func (*Base) ValidateKline

func (b *Base) ValidateKline(pair currency.Pair, a asset.Item, interval kline.Interval) error

ValidateKline confirms that the requested pair, asset & interval are supported and/or enabled by the requested exchange

type CurrencyStateManagement

type CurrencyStateManagement interface {
	GetCurrencyStateSnapshot() ([]currencystate.Snapshot, error)
	UpdateCurrencyStates(ctx context.Context, a asset.Item) error
	CanTradePair(p currency.Pair, a asset.Item) error
	CanTrade(c currency.Code, a asset.Item) error
	CanWithdraw(c currency.Code, a asset.Item) error
	CanDeposit(c currency.Code, a asset.Item) error
}

CurrencyStateManagement defines functionality for currency state management

type Endpoints

type Endpoints struct {
	Exchange string

	sync.RWMutex
	// contains filtered or unexported fields
}

Endpoints stores running url endpoints for exchanges

func (*Endpoints) GetURL

func (e *Endpoints) GetURL(key URL) (string, error)

GetURL gets default url from URLs map

func (*Endpoints) GetURLMap

func (e *Endpoints) GetURLMap() map[string]string

GetURLMap gets all urls for either running or default map based on the bool value supplied

func (*Endpoints) SetDefaultEndpoints

func (e *Endpoints) SetDefaultEndpoints(m map[URL]string) error

SetDefaultEndpoints declares and sets the default URLs map

func (*Endpoints) SetRunning

func (e *Endpoints) SetRunning(key, val string) error

SetRunning populates running URLs map

type Features

type Features struct {
	Supports FeaturesSupported
	Enabled  FeaturesEnabled
}

Features stores the supported and enabled features for the exchange

type FeaturesEnabled

type FeaturesEnabled struct {
	AutoPairUpdates bool
	Kline           kline.ExchangeCapabilitiesEnabled
	SaveTradeData   bool
	TradeFeed       bool
	FillsFeed       bool
}

FeaturesEnabled stores the exchange enabled features

type FeaturesSupported

type FeaturesSupported struct {
	REST                  bool
	RESTCapabilities      protocol.Features
	Websocket             bool
	WebsocketCapabilities protocol.Features
	WithdrawPermissions   uint32
	Kline                 kline.ExchangeCapabilitiesSupported
}

FeaturesSupported stores the exchanges supported features

type FeeBuilder

type FeeBuilder struct {
	FeeType FeeType
	// Used for calculating crypto trading fees, deposits & withdrawals
	Pair    currency.Pair
	IsMaker bool
	// Fiat currency used for bank deposits & withdrawals
	FiatCurrency        currency.Code
	BankTransactionType InternationalBankTransactionType
	// Used to multiply for fee calculations
	PurchasePrice float64
	Amount        float64
}

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

type FeeType

type FeeType uint8

FeeType is the type for holding a custom fee type (International withdrawal fee)

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
	CryptoChain       string
	BankTo            string
	BankFrom          string
}

FundHistory holds exchange funding history data

type IBotExchange

type IBotExchange interface {
	Setup(exch *config.Exchange) error
	Start(wg *sync.WaitGroup) error
	SetDefaults()
	GetName() string
	IsEnabled() bool
	SetEnabled(bool)
	ValidateCredentials(ctx context.Context, a asset.Item) error
	FetchTicker(ctx context.Context, p currency.Pair, a asset.Item) (*ticker.Price, error)
	UpdateTicker(ctx context.Context, p currency.Pair, a asset.Item) (*ticker.Price, error)
	UpdateTickers(ctx context.Context, a asset.Item) error
	FetchOrderbook(ctx context.Context, p currency.Pair, a asset.Item) (*orderbook.Base, error)
	UpdateOrderbook(ctx context.Context, p currency.Pair, a asset.Item) (*orderbook.Base, error)
	FetchTradablePairs(ctx context.Context, a asset.Item) ([]string, error)
	UpdateTradablePairs(ctx context.Context, forceUpdate bool) error
	GetEnabledPairs(a asset.Item) (currency.Pairs, error)
	GetAvailablePairs(a asset.Item) (currency.Pairs, error)
	FetchAccountInfo(ctx context.Context, a asset.Item) (account.Holdings, error)
	UpdateAccountInfo(ctx context.Context, a asset.Item) (account.Holdings, error)
	GetAuthenticatedAPISupport(endpoint uint8) bool
	SetPairs(pairs currency.Pairs, a asset.Item, enabled bool) error
	GetAssetTypes(enabled bool) asset.Items
	GetRecentTrades(ctx context.Context, p currency.Pair, a asset.Item) ([]trade.Data, error)
	GetHistoricTrades(ctx context.Context, p currency.Pair, a asset.Item, startTime, endTime time.Time) ([]trade.Data, error)
	SupportsAutoPairUpdates() bool
	SupportsRESTTickerBatchUpdates() bool
	GetFeeByType(ctx context.Context, f *FeeBuilder) (float64, error)
	GetLastPairsUpdateTime() int64
	GetWithdrawPermissions() uint32
	FormatWithdrawPermissions() string
	SupportsWithdrawPermissions(permissions uint32) bool
	GetFundingHistory(ctx context.Context) ([]FundHistory, error)
	SubmitOrder(ctx context.Context, s *order.Submit) (order.SubmitResponse, error)
	ModifyOrder(ctx context.Context, action *order.Modify) (order.Modify, error)
	CancelOrder(ctx context.Context, o *order.Cancel) error
	CancelBatchOrders(ctx context.Context, o []order.Cancel) (order.CancelBatchResponse, error)
	CancelAllOrders(ctx context.Context, orders *order.Cancel) (order.CancelAllResponse, error)
	GetOrderInfo(ctx context.Context, orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error)
	GetDepositAddress(ctx context.Context, cryptocurrency currency.Code, accountID, chain string) (*deposit.Address, error)
	GetAvailableTransferChains(ctx context.Context, cryptocurrency currency.Code) ([]string, error)
	GetOrderHistory(ctx context.Context, getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error)
	GetWithdrawalsHistory(ctx context.Context, code currency.Code) ([]WithdrawalHistory, error)
	GetActiveOrders(ctx context.Context, getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error)
	WithdrawCryptocurrencyFunds(ctx context.Context, withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error)
	WithdrawFiatFunds(ctx context.Context, withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error)
	WithdrawFiatFundsToInternationalBank(ctx context.Context, withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error)
	SetHTTPClientUserAgent(ua string)
	GetHTTPClientUserAgent() string
	SetClientProxyAddress(addr string) error
	SupportsREST() bool
	GetSubscriptions() ([]stream.ChannelSubscription, error)
	GetDefaultConfig() (*config.Exchange, error)
	GetBase() *Base
	SupportsAsset(assetType asset.Item) bool
	GetHistoricCandles(ctx context.Context, p currency.Pair, a asset.Item, timeStart, timeEnd time.Time, interval kline.Interval) (kline.Item, error)
	GetHistoricCandlesExtended(ctx context.Context, p currency.Pair, a asset.Item, timeStart, timeEnd time.Time, interval kline.Interval) (kline.Item, error)
	DisableRateLimiter() error
	EnableRateLimiter() error

	GetWebsocket() (*stream.Websocket, error)
	IsWebsocketEnabled() bool
	SupportsWebsocket() bool
	SubscribeToWebsocketChannels(channels []stream.ChannelSubscription) error
	UnsubscribeToWebsocketChannels(channels []stream.ChannelSubscription) error
	IsAssetWebsocketSupported(aType asset.Item) bool
	FlushWebsocketChannels() error
	AuthenticateWebsocket(ctx context.Context) error

	GetOrderExecutionLimits(a asset.Item, cp currency.Pair) (*order.Limits, error)
	CheckOrderExecutionLimits(a asset.Item, cp currency.Pair, price, amount float64, orderType order.Type) error
	UpdateOrderExecutionLimits(ctx context.Context, a asset.Item) error

	CurrencyStateManagement
}

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

type URL

type URL uint16

URL stores uint conversions

const (
	Invalid URL = iota
	RestSpot
	RestSpotSupplementary
	RestUSDTMargined
	RestCoinMargined
	RestFutures
	RestSwap
	RestSandbox
	WebsocketSpot
	WebsocketSpotSupplementary
	ChainAnalysis
	EdgeCase1
	EdgeCase2
	EdgeCase3
)

url lookup consts

func (URL) String

func (u URL) String() string

type WithdrawalHistory

type WithdrawalHistory struct {
	Status          string
	TransferID      string
	Description     string
	Timestamp       time.Time
	Currency        string
	Amount          float64
	Fee             float64
	TransferType    string
	CryptoToAddress string
	CryptoTxID      string
	CryptoChain     string
	BankTo          string
}

WithdrawalHistory holds exchange Withdrawal history data

Directories

Path Synopsis
Package gemini exchange documentation can be found at https://docs.sandbox.gemini.com
Package gemini exchange documentation can be found at https://docs.sandbox.gemini.com

Jump to

Keyboard shortcuts

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