huobi

package
v0.0.0-...-1ca2487 Latest Latest
Warning

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

Go to latest
Published: May 29, 2020 License: MIT Imports: 29 Imported by: 0

README

GoCryptoTrader package Huobi

Build Status Software License GoDoc Coverage Status Go Report Card

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

Huobi Exchange

Current Features
  • REST Support
  • Websocket Support
How to enable
  // Exchanges will be abstracted out in further updates and examples will be
  // supplied then
How to do REST public/private calls
  • If enabled via "configuration".json file the exchange will be added to the IBotExchange array in the go var bot Bot and you will only be able to use the wrapper interface functions for accessing exchange data. View routines.go for an example of integration usage with GoCryptoTrader. Rudimentary example below:

main.go

var h exchange.IBotExchange

for i := range bot.Exchanges {
  if bot.Exchanges[i].GetName() == "Huobi" {
    h = bot.Exchanges[i]
  }
}

// Public calls - wrapper functions

// Fetches current ticker information
tick, err := h.FetchTicker()
if err != nil {
  // Handle error
}

// Fetches current orderbook information
ob, err := h.FetchOrderbook()
if err != nil {
  // Handle error
}

// Private calls - wrapper functions - make sure your APIKEY and APISECRET are
// set and AuthenticatedAPISupport is set to true

// Fetches current account information
accountInfo, err := h.GetAccountInfo()
if err != nil {
  // Handle error
}
  • If enabled via individually importing package, rudimentary example below:
// Public calls

// Fetches current ticker information
ticker, err := h.GetTicker()
if err != nil {
  // Handle error
}

// Fetches current orderbook information
ob, err := h.GetOrderBook()
if err != nil {
  // Handle error
}

// Private calls - make sure your APIKEY and APISECRET are set and
// AuthenticatedAPISupport is set to true

// GetUserInfo returns account info
accountInfo, err := h.GetUserInfo(...)
if err != nil {
  // Handle error
}

// Submits an order and the exchange and returns its tradeID
tradeID, err := h.Trade(...)
if err != nil {
  // Handle error
}
How to do Websocket public/private calls
  // Exchanges will be abstracted out in further updates and examples will be
  // supplied then
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

This section is empty.

Variables

View Source
var (
	OrderBookDataRequestParamsTypeNone  = OrderBookDataRequestParamsType("")
	OrderBookDataRequestParamsTypeStep0 = OrderBookDataRequestParamsType("step0")
	OrderBookDataRequestParamsTypeStep1 = OrderBookDataRequestParamsType("step1")
	OrderBookDataRequestParamsTypeStep2 = OrderBookDataRequestParamsType("step2")
	OrderBookDataRequestParamsTypeStep3 = OrderBookDataRequestParamsType("step3")
	OrderBookDataRequestParamsTypeStep4 = OrderBookDataRequestParamsType("step4")
	OrderBookDataRequestParamsTypeStep5 = OrderBookDataRequestParamsType("step5")
)

vars for OrderBookDataRequestParamsTypes

View Source
var (
	// SpotNewOrderRequestTypeBuyMarket buy market order
	SpotNewOrderRequestTypeBuyMarket = SpotNewOrderRequestParamsType("buy-market")

	// SpotNewOrderRequestTypeSellMarket sell market order
	SpotNewOrderRequestTypeSellMarket = SpotNewOrderRequestParamsType("sell-market")

	// SpotNewOrderRequestTypeBuyLimit buy limit order
	SpotNewOrderRequestTypeBuyLimit = SpotNewOrderRequestParamsType("buy-limit")

	// SpotNewOrderRequestTypeSellLimit sell lmit order
	SpotNewOrderRequestTypeSellLimit = SpotNewOrderRequestParamsType("sell-limit")
)
View Source
var (
	TimeIntervalMinute         = TimeInterval("1min")
	TimeIntervalFiveMinutes    = TimeInterval("5min")
	TimeIntervalFifteenMinutes = TimeInterval("15min")
	TimeIntervalThirtyMinutes  = TimeInterval("30min")
	TimeIntervalHour           = TimeInterval("60min")
	TimeIntervalDay            = TimeInterval("1day")
	TimeIntervalWeek           = TimeInterval("1week")
	TimeIntervalMohth          = TimeInterval("1mon")
	TimeIntervalYear           = TimeInterval("1year")
)

TimeInterval vars

Functions

This section is empty.

Types

type Account

type Account struct {
	ID     int64  `json:"id"`
	Type   string `json:"type"`
	State  string `json:"state"`
	UserID int64  `json:"user-id"`
}

Account stores the account data

type AccountBalance

type AccountBalance struct {
	ID                    int64                  `json:"id"`
	Type                  string                 `json:"type"`
	State                 string                 `json:"state"`
	AccountBalanceDetails []AccountBalanceDetail `json:"list"`
}

AccountBalance stores the user all account balance

type AccountBalanceDetail

type AccountBalanceDetail struct {
	Currency string  `json:"currency"`
	Type     string  `json:"type"`
	Balance  float64 `json:"balance,string"`
}

AccountBalanceDetail stores the user account balance

type AggregatedBalance

type AggregatedBalance struct {
	Currency string  `json:"currency"`
	Balance  float64 `json:"balance,string"`
}

AggregatedBalance stores balances of all the sub-account

type CancelOpenOrdersBatch

type CancelOpenOrdersBatch struct {
	Data struct {
		FailedCount  int `json:"failed-count"`
		NextID       int `json:"next-id"`
		SuccessCount int `json:"success-count"`
	} `json:"data"`
	Status       string `json:"status"`
	ErrorMessage string `json:"err-msg"`
}

CancelOpenOrdersBatch stores open order batch response data

type CancelOrderBatch

type CancelOrderBatch struct {
	Success []string `json:"success"`
	Failed  []struct {
		OrderID      int64  `json:"order-id,string"`
		ErrorCode    string `json:"err-code"`
		ErrorMessage string `json:"err-msg"`
	} `json:"failed"`
}

CancelOrderBatch stores the cancel order batch data

type Chain

type Chain struct {
	Chain                   string `json:"chain"`
	BaseChain               string `json:"baseChain"`
	BaseChainProtocol       string `json:"baseChainProtocol"`
	WithdrawFeeType         string `json:"withdrawFeeType"`
	IsDynamic               bool   `json:"isDynamic"`
	TransactFeeWithdraw     string `json:"transactFeeWithdraw"`
	MinTransactFeeWithdraw  string `json:"minTransactFeeWithdraw"`
	MaxTransactFeeWithdraw  string `json:"maxTransactFeeWithdraw"`
	TransactFeeRateWithdraw string `json:"transactFeeRateWithdraw"`
	WithdrawStatus          string `json:"withdrawStatus"`
	DepositStatus           string `json:"depositStatus"`
	MinDepositAmt           string `json:"minDepositAmt"`
	MinWithdrawAmt          string `json:"minWithdrawAmt"`
	MaxWithdrawAmt          string `json:"maxWithdrawAmt"`
	WithdrawQuotaPerDay     string `json:"withdrawQuotaPerDay"`
	WithdrawPrecision       int64  `json:"withdrawPrecision"`
}

Chain ...

type ChainQuota

type ChainQuota struct {
	Chain                         string  `json:"chain"`
	MaxWithdrawAmount             float64 `json:"maxWithdrawAmt,string"`
	WithdrawQuotaPerDay           float64 `json:"withdrawQuotaPerDay,string"`
	RemainingWithdrawQuotaPerDay  float64 `json:"remainWithdrawQuotaPerDay,string"`
	WithdrawQuotaPerYear          float64 `json:"withdrawQuotaPerYear,string"`
	RemainingWithdrawQuotaPerYear float64 `json:"remainWithdrawQuotaPerYear,string"`
	WithdrawQuotaTotal            float64 `json:"withdrawQuotaTotal,string"`
	RemainingWithdrawQuotaTotal   float64 `json:"remainWithdrawQuotaTotal,string"`
}

ChainQuota stores the users currency chain quota

type Currency

type Currency struct {
	Currency string  `json:"currency"`
	Chains   []Chain `json:"chains"`
}

Currency ...

type DepositAddress

type DepositAddress struct {
	Currency   string `json:"currency"`
	Address    string `json:"address"`
	AddressTag string `json:"addressTag"`
	Chain      string `json:"chain"`
}

DepositAddress stores the users deposit address info

type Detail

type Detail struct {
	Amount    float64 `json:"amount"`
	Open      float64 `json:"open"`
	Close     float64 `json:"close"`
	High      float64 `json:"high"`
	Timestamp int64   `json:"timestamp"`
	ID        int64   `json:"id"`
	Count     int     `json:"count"`
	Low       float64 `json:"low"`
	Volume    float64 `json:"vol"`
}

Detail stores the ticker detail data

type DetailMerged

type DetailMerged struct {
	Detail
	Version int64     `json:"version"`
	Ask     []float64 `json:"ask"`
	Bid     []float64 `json:"bid"`
}

DetailMerged stores the ticker detail merged data

type HUOBI

type HUOBI struct {
	exchange.Base
	AccountID                  string
	WebsocketConn              *wshandler.WebsocketConnection
	AuthenticatedWebsocketConn *wshandler.WebsocketConnection
}

HUOBI is the overarching type across this package

func (*HUOBI) AuthenticateWebsocket

func (h *HUOBI) AuthenticateWebsocket() error

AuthenticateWebsocket sends an authentication message to the websocket

func (*HUOBI) CancelAllOrders

func (h *HUOBI) CancelAllOrders(orderCancellation *order.Cancel) (order.CancelAllResponse, error)

CancelAllOrders cancels all orders associated with a currency pair

func (*HUOBI) CancelExistingOrder

func (h *HUOBI) CancelExistingOrder(orderID int64) (int64, error)

CancelExistingOrder cancels an order on Huobi

func (*HUOBI) CancelOpenOrdersBatch

func (h *HUOBI) CancelOpenOrdersBatch(accountID, symbol string) (CancelOpenOrdersBatch, error)

CancelOpenOrdersBatch cancels a batch of orders -- to-do

func (*HUOBI) CancelOrder

func (h *HUOBI) CancelOrder(order *order.Cancel) error

CancelOrder cancels an order by its corresponding ID number

func (*HUOBI) CancelOrderBatch

func (h *HUOBI) CancelOrderBatch(_ []int64) ([]CancelOrderBatch, error)

CancelOrderBatch cancels a batch of orders -- to-do

func (*HUOBI) CancelWithdraw

func (h *HUOBI) CancelWithdraw(withdrawID int64) (int64, error)

CancelWithdraw cancels a withdraw request

func (*HUOBI) FetchAccountInfo

func (h *HUOBI) FetchAccountInfo() (account.Holdings, error)

FetchAccountInfo retrieves balances for all enabled currencies

func (*HUOBI) FetchOrderbook

func (h *HUOBI) FetchOrderbook(p currency.Pair, assetType asset.Item) (*orderbook.Base, error)

FetchOrderbook returns orderbook base on the currency pair

func (*HUOBI) FetchTicker

func (h *HUOBI) FetchTicker(p currency.Pair, assetType asset.Item) (*ticker.Price, error)

FetchTicker returns the ticker for a currency pair

func (*HUOBI) FetchTradablePairs

func (h *HUOBI) FetchTradablePairs(asset asset.Item) ([]string, error)

FetchTradablePairs returns a list of the exchanges tradable pairs

func (*HUOBI) GenerateDefaultSubscriptions

func (h *HUOBI) GenerateDefaultSubscriptions()

GenerateDefaultSubscriptions Adds default subscriptions to websocket to be handled by ManageSubscriptions()

func (*HUOBI) GetAccountBalance

func (h *HUOBI) GetAccountBalance(accountID string) ([]AccountBalanceDetail, error)

GetAccountBalance returns the users Huobi account balance

func (*HUOBI) GetAccountID

func (h *HUOBI) GetAccountID() ([]Account, error)

GetAccountID returns the account ID for trades

func (*HUOBI) GetAccounts

func (h *HUOBI) GetAccounts() ([]Account, error)

GetAccounts returns the Huobi user accounts

func (*HUOBI) GetActiveOrders

func (h *HUOBI) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error)

GetActiveOrders retrieves any orders that are active/open

func (*HUOBI) GetAggregatedBalance

func (h *HUOBI) GetAggregatedBalance() ([]AggregatedBalance, error)

GetAggregatedBalance returns the balances of all the sub-account aggregated.

func (*HUOBI) GetCurrencies

func (h *HUOBI) GetCurrencies() ([]string, error)

GetCurrencies returns a list of currencies supported by Huobi

func (*HUOBI) GetCurrencyReference

func (h *HUOBI) GetCurrencyReference(currency string) ([]Currency, error)

GetCurrencyReference returns currency reference by Huobi

func (*HUOBI) GetDefaultConfig

func (h *HUOBI) GetDefaultConfig() (*config.ExchangeConfig, error)

GetDefaultConfig returns a default exchange config

func (*HUOBI) GetDepositAddress

func (h *HUOBI) GetDepositAddress(cryptocurrency currency.Code, accountID string) (string, error)

GetDepositAddress returns a deposit address for a specified currency

func (*HUOBI) GetDepositHistory

func (h *HUOBI) GetDepositHistory(cryptocurrency string) ([]WithdrawDepositHistory, error)

GetDepositHistory returns the deposit history

func (*HUOBI) GetDepth

func (h *HUOBI) GetDepth(obd OrderBookDataRequestParams) (Orderbook, error)

GetDepth returns the depth for the specified symbol

func (*HUOBI) GetExchangeHistory

func (h *HUOBI) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exchange.TradeHistory, error)

GetExchangeHistory returns historic trade data since exchange opening.

func (*HUOBI) GetFee

func (h *HUOBI) GetFee(feeBuilder *exchange.FeeBuilder) (float64, error)

GetFee returns an estimate of fee based on type of transaction

func (*HUOBI) GetFeeByType

func (h *HUOBI) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error)

GetFeeByType returns an estimate of fee based on type of transaction

func (*HUOBI) GetFundingHistory

func (h *HUOBI) GetFundingHistory() ([]exchange.FundHistory, error)

GetFundingHistory returns funding history, deposits and withdrawals

func (*HUOBI) GetHistoricCandles

func (h *HUOBI) GetHistoricCandles(pair currency.Pair, a asset.Item, start, end time.Time, interval time.Duration) (kline.Item, error)

GetHistoricCandles returns candles between a time period for a set time interval

func (*HUOBI) GetLatestSpotPrice

func (h *HUOBI) GetLatestSpotPrice(symbol string) (float64, error)

GetLatestSpotPrice returns latest spot price of symbol

symbol: string of currency pair

func (*HUOBI) GetMarginAccountBalance

func (h *HUOBI) GetMarginAccountBalance(symbol string) ([]MarginAccountBalance, error)

GetMarginAccountBalance returns the margin account balances

func (*HUOBI) GetMarginLoanOrders

func (h *HUOBI) GetMarginLoanOrders(symbol, currency, start, end, states, from, direct, size string) ([]MarginOrder, error)

GetMarginLoanOrders returns the margin loan orders

func (*HUOBI) GetMarketDetail

func (h *HUOBI) GetMarketDetail(symbol string) (Detail, error)

GetMarketDetail returns the ticker for the specified symbol

func (*HUOBI) GetMarketDetailMerged

func (h *HUOBI) GetMarketDetailMerged(symbol string) (DetailMerged, error)

GetMarketDetailMerged returns the ticker for the specified symbol

func (*HUOBI) GetOpenOrders

func (h *HUOBI) GetOpenOrders(accountID, symbol, side string, size int64) ([]OrderInfo, error)

GetOpenOrders returns a list of orders

func (*HUOBI) GetOrder

func (h *HUOBI) GetOrder(orderID int64) (OrderInfo, error)

GetOrder returns order information for the specified order

func (*HUOBI) GetOrderHistory

func (h *HUOBI) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error)

GetOrderHistory retrieves account order information Can Limit response to specific order status

func (*HUOBI) GetOrderInfo

func (h *HUOBI) GetOrderInfo(orderID string) (order.Detail, error)

GetOrderInfo returns information on a current open order

func (*HUOBI) GetOrderMatchResults

func (h *HUOBI) GetOrderMatchResults(orderID int64) ([]OrderMatchInfo, error)

GetOrderMatchResults returns matched order info for the specified order

func (*HUOBI) GetOrders

func (h *HUOBI) GetOrders(symbol, types, start, end, states, from, direct, size string) ([]OrderInfo, error)

GetOrders returns a list of orders

func (*HUOBI) GetOrdersMatch

func (h *HUOBI) GetOrdersMatch(symbol, types, start, end, from, direct, size string) ([]OrderMatchInfo, error)

GetOrdersMatch returns a list of matched orders

func (*HUOBI) GetSpotKline

func (h *HUOBI) GetSpotKline(arg KlinesRequestParams) ([]KlineItem, error)

GetSpotKline returns kline data KlinesRequestParams contains symbol, period and size

func (*HUOBI) GetSubscriptions

func (h *HUOBI) GetSubscriptions() ([]wshandler.WebsocketChannelSubscription, error)

GetSubscriptions returns a copied list of subscriptions

func (*HUOBI) GetSymbols

func (h *HUOBI) GetSymbols() ([]Symbol, error)

GetSymbols returns an array of symbols supported by Huobi

func (*HUOBI) GetTickers

func (h *HUOBI) GetTickers() (Tickers, error)

GetTickers returns the ticker for the specified symbol

func (*HUOBI) GetTimestamp

func (h *HUOBI) GetTimestamp() (int64, error)

GetTimestamp returns the Huobi server time

func (*HUOBI) GetTradeHistory

func (h *HUOBI) GetTradeHistory(symbol, size string) ([]TradeHistory, error)

GetTradeHistory returns the trades for the specified symbol

func (*HUOBI) GetTrades

func (h *HUOBI) GetTrades(symbol string) ([]Trade, error)

GetTrades returns the trades for the specified symbol

func (*HUOBI) GetWebsocket

func (h *HUOBI) GetWebsocket() (*wshandler.Websocket, error)

GetWebsocket returns a pointer to the exchange websocket

func (*HUOBI) GetWithdrawalHistory

func (h *HUOBI) GetWithdrawalHistory(cryptocurrency string) ([]WithdrawDepositHistory, error)

GetWithdrawalHistory returns the withdrawal history

func (*HUOBI) MarginOrder

func (h *HUOBI) MarginOrder(symbol, currency string, amount float64) (int64, error)

MarginOrder submits a margin order application

func (*HUOBI) MarginRepayment

func (h *HUOBI) MarginRepayment(orderID int64, amount float64) (int64, error)

MarginRepayment repays a margin amount for a margin ID

func (*HUOBI) MarginTransfer

func (h *HUOBI) MarginTransfer(symbol, currency string, amount float64, in bool) (int64, error)

MarginTransfer transfers assets into or out of the margin account

func (*HUOBI) ModifyOrder

func (h *HUOBI) ModifyOrder(action *order.Modify) (string, error)

ModifyOrder will allow of changing orderbook placement and limit to market conversion

func (*HUOBI) QueryDepositAddress

func (h *HUOBI) QueryDepositAddress(cryptocurrency string) (DepositAddress, error)

QueryDepositAddress returns the deposit address for a specified currency

func (*HUOBI) QueryDepositAddresses

func (h *HUOBI) QueryDepositAddresses(cryptocurrency string) ([]DepositAddress, error)

QueryDepositAddresses returns the deposit address for a specified currency

func (*HUOBI) QueryWithdrawQuotas

func (h *HUOBI) QueryWithdrawQuotas(cryptocurrency string) (WithdrawQuota, error)

QueryWithdrawQuotas returns the users cryptocurrency withdraw quotas

func (*HUOBI) Run

func (h *HUOBI) Run()

Run implements the HUOBI wrapper

func (*HUOBI) SendAuthenticatedHTTPRequest

func (h *HUOBI) SendAuthenticatedHTTPRequest(method, endpoint string, values url.Values, data, result interface{}, isVersion2API bool) error

SendAuthenticatedHTTPRequest sends authenticated requests to the HUOBI API

func (*HUOBI) SendHTTPRequest

func (h *HUOBI) SendHTTPRequest(path string, result interface{}) error

SendHTTPRequest sends an unauthenticated HTTP request

func (*HUOBI) SetDefaults

func (h *HUOBI) SetDefaults()

SetDefaults sets default values for the exchange

func (*HUOBI) Setup

func (h *HUOBI) Setup(exch *config.ExchangeConfig) error

Setup sets user configuration

func (*HUOBI) SpotNewOrder

func (h *HUOBI) SpotNewOrder(arg SpotNewOrderRequestParams) (int64, error)

SpotNewOrder submits an order to Huobi

func (*HUOBI) Start

func (h *HUOBI) Start(wg *sync.WaitGroup)

Start starts the HUOBI go routine

func (*HUOBI) SubmitOrder

func (h *HUOBI) SubmitOrder(s *order.Submit) (order.SubmitResponse, error)

SubmitOrder submits a new order

func (*HUOBI) Subscribe

func (h *HUOBI) Subscribe(channelToSubscribe wshandler.WebsocketChannelSubscription) error

Subscribe sends a websocket message to receive data from the channel

func (*HUOBI) SubscribeToWebsocketChannels

func (h *HUOBI) SubscribeToWebsocketChannels(channels []wshandler.WebsocketChannelSubscription) error

SubscribeToWebsocketChannels appends to ChannelsToSubscribe which lets websocket.manageSubscriptions handle subscribing

func (*HUOBI) Unsubscribe

func (h *HUOBI) Unsubscribe(channelToSubscribe wshandler.WebsocketChannelSubscription) error

Unsubscribe sends a websocket message to stop receiving data from the channel

func (*HUOBI) UnsubscribeToWebsocketChannels

func (h *HUOBI) UnsubscribeToWebsocketChannels(channels []wshandler.WebsocketChannelSubscription) error

UnsubscribeToWebsocketChannels removes from ChannelsToSubscribe which lets websocket.manageSubscriptions handle unsubscribing

func (*HUOBI) UpdateAccountInfo

func (h *HUOBI) UpdateAccountInfo() (account.Holdings, error)

UpdateAccountInfo retrieves balances for all enabled currencies for the HUOBI exchange - to-do

func (*HUOBI) UpdateOrderbook

func (h *HUOBI) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*orderbook.Base, error)

UpdateOrderbook updates and returns the orderbook for a currency pair

func (*HUOBI) UpdateTicker

func (h *HUOBI) UpdateTicker(p currency.Pair, assetType asset.Item) (*ticker.Price, error)

UpdateTicker updates and returns the ticker for a currency pair

func (*HUOBI) UpdateTradablePairs

func (h *HUOBI) UpdateTradablePairs(forceUpdate bool) error

UpdateTradablePairs updates the exchanges available pairs and stores them in the exchanges config

func (*HUOBI) ValidateCredentials

func (h *HUOBI) ValidateCredentials() error

ValidateCredentials validates current credentials used for wrapper functionality

func (*HUOBI) Withdraw

func (h *HUOBI) Withdraw(c currency.Code, address, addrTag string, amount, fee float64) (int64, error)

Withdraw withdraws the desired amount and currency

func (*HUOBI) WithdrawCryptocurrencyFunds

func (h *HUOBI) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error)

WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is submitted

func (*HUOBI) WithdrawFiatFunds

func (h *HUOBI) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error)

WithdrawFiatFunds returns a withdrawal ID when a withdrawal is submitted

func (*HUOBI) WithdrawFiatFundsToInternationalBank

func (h *HUOBI) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error)

WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a withdrawal is submitted

func (*HUOBI) WsConnect

func (h *HUOBI) WsConnect() error

WsConnect initiates a new websocket connection

func (*HUOBI) WsProcessOrderbook

func (h *HUOBI) WsProcessOrderbook(update *WsDepth, symbol string) error

WsProcessOrderbook processes new orderbook data

type KlineItem

type KlineItem struct {
	ID     int64   `json:"id"`
	Open   float64 `json:"open"`
	Close  float64 `json:"close"`
	Low    float64 `json:"low"`
	High   float64 `json:"high"`
	Amount float64 `json:"amount"`
	Volume float64 `json:"vol"`
	Count  int     `json:"count"`
}

KlineItem stores a kline item

type KlinesRequestParams

type KlinesRequestParams struct {
	Symbol string       // Symbol to be used; example btcusdt, bccbtc......
	Period TimeInterval // Kline time interval; 1min, 5min, 15min......
	Size   int          // Size; [1-2000]
}

KlinesRequestParams represents Klines request data.

type MarginAccountBalance

type MarginAccountBalance struct {
	ID       int              `json:"id"`
	Type     string           `json:"type"`
	State    string           `json:"state"`
	Symbol   string           `json:"symbol"`
	FlPrice  string           `json:"fl-price"`
	FlType   string           `json:"fl-type"`
	RiskRate string           `json:"risk-rate"`
	List     []AccountBalance `json:"list"`
}

MarginAccountBalance stores the margin account balance info

type MarginOrder

type MarginOrder struct {
	Currency        string `json:"currency"`
	Symbol          string `json:"symbol"`
	AccruedAt       int64  `json:"accrued-at"`
	LoanAmount      string `json:"loan-amount"`
	LoanBalance     string `json:"loan-balance"`
	InterestBalance string `json:"interest-balance"`
	CreatedAt       int64  `json:"created-at"`
	InterestAmount  string `json:"interest-amount"`
	InterestRate    string `json:"interest-rate"`
	AccountID       int    `json:"account-id"`
	UserID          int    `json:"user-id"`
	UpdatedAt       int64  `json:"updated-at"`
	ID              int    `json:"id"`
	State           string `json:"state"`
}

MarginOrder stores the margin order info

type OrderBookDataRequestParams

type OrderBookDataRequestParams struct {
	Symbol string                         `json:"symbol"` // Required; example LTCBTC,BTCUSDT
	Type   OrderBookDataRequestParamsType `json:"type"`   // step0, step1, step2, step3, step4, step5 (combined depth 0-5); when step0, no depth is merged
}

OrderBookDataRequestParams represents Klines request data.

type OrderBookDataRequestParamsType

type OrderBookDataRequestParamsType string

OrderBookDataRequestParamsType var for request param types

type OrderInfo

type OrderInfo struct {
	ID               int64   `json:"id"`
	Symbol           string  `json:"symbol"`
	AccountID        int64   `json:"account-id"`
	Amount           float64 `json:"amount,string"`
	Price            float64 `json:"price,string"`
	CreatedAt        int64   `json:"created-at"`
	Type             string  `json:"type"`
	FieldAmount      float64 `json:"field-amount,string"`
	FieldCashAmount  float64 `json:"field-cash-amount,string"`
	FilledAmount     float64 `json:"filled-amount,string"`
	FilledCashAmount float64 `json:"filled-cash-amount,string"`
	FilledFees       float64 `json:"filled-fees,string"`
	FinishedAt       int64   `json:"finished-at"`
	UserID           int64   `json:"user-id"`
	Source           string  `json:"source"`
	State            string  `json:"state"`
	CanceledAt       int64   `json:"canceled-at"`
	Exchange         string  `json:"exchange"`
	Batch            string  `json:"batch"`
}

OrderInfo stores the order info

type OrderMatchInfo

type OrderMatchInfo struct {
	ID           int    `json:"id"`
	OrderID      int    `json:"order-id"`
	MatchID      int    `json:"match-id"`
	Symbol       string `json:"symbol"`
	Type         string `json:"type"`
	Source       string `json:"source"`
	Price        string `json:"price"`
	FilledAmount string `json:"filled-amount"`
	FilledFees   string `json:"filled-fees"`
	CreatedAt    int64  `json:"created-at"`
}

OrderMatchInfo stores the order match info

type Orderbook

type Orderbook struct {
	ID         int64       `json:"id"`
	Timetstamp int64       `json:"ts"`
	Bids       [][]float64 `json:"bids"`
	Asks       [][]float64 `json:"asks"`
}

Orderbook stores the orderbook data

type RateLimit

type RateLimit struct {
	Spot          *rate.Limiter
	FuturesAuth   *rate.Limiter
	FuturesUnauth *rate.Limiter
	SwapAuth      *rate.Limiter
	SwapUnauth    *rate.Limiter
	FuturesXfer   *rate.Limiter
}

RateLimit implements the request.Limiter interface

func SetRateLimit

func SetRateLimit() *RateLimit

SetRateLimit returns the rate limit for the exchange

func (*RateLimit) Limit

func (r *RateLimit) Limit(f request.EndpointLimit) error

Limit limits outbound requests

type Response

type Response struct {
	Status       string `json:"status"`
	Channel      string `json:"ch"`
	Timestamp    int64  `json:"ts"`
	ErrorCode    string `json:"err-code"`
	ErrorMessage string `json:"err-msg"`
}

Response stores the Huobi response information

type ResponseV2

type ResponseV2 struct {
	Code    int32  `json:"code"`
	Message string `json:"message"`
}

ResponseV2 stores the Huobi generic response info

type SpotNewOrderRequestParams

type SpotNewOrderRequestParams struct {
	AccountID int                           `json:"account-id,string"` // Account ID, obtained using the accounts method. Curency trades use the accountid of the ‘spot’ account; for loan asset transactions, please use the accountid of the ‘margin’ account.
	Amount    float64                       `json:"amount"`            // The limit price indicates the quantity of the order, the market price indicates how much to buy when the order is paid, and the market price indicates how much the coin is sold when the order is sold.
	Price     float64                       `json:"price"`             // Order price, market price does not use  this parameter
	Source    string                        `json:"source"`            // Order source, api: API call, margin-api: loan asset transaction
	Symbol    string                        `json:"symbol"`            // The symbol to use; example btcusdt, bccbtc......
	Type      SpotNewOrderRequestParamsType `json:"type"`              // 订单类型, buy-market: 市价买, sell-market: 市价卖, buy-limit: 限价买, sell-limit: 限价卖
}

SpotNewOrderRequestParams holds the params required to place an order

type SpotNewOrderRequestParamsType

type SpotNewOrderRequestParamsType string

SpotNewOrderRequestParamsType order type

type Symbol

type Symbol struct {
	BaseCurrency       string  `json:"base-currency"`
	QuoteCurrency      string  `json:"quote-currency"`
	PricePrecision     int     `json:"price-precision"`
	AmountPrecision    int     `json:"amount-precision"`
	SymbolPartition    string  `json:"symbol-partition"`
	Innovation         string  `json:"innovation"`
	State              string  `json:"state"`
	ValuePrecision     int     `json:"value-precision"`
	MinimumOrderAmount float64 `json:"min-order-amt"`
	MaximumOrderAmount float64 `json:"max-order-amt"`
	MinimumOrderValue  float64 `json:"min-order-value"`
}

Symbol stores the symbol data

type Ticker

type Ticker struct {
	Amount float64 `json:"amount"`
	Close  float64 `json:"close"`
	Count  int64   `json:"count"`
	High   float64 `json:"high"`
	Low    float64 `json:"low"`
	Open   float64 `json:"open"`
	Symbol string  `json:"symbol"`
	Volume float64 `json:"vol"`
}

Ticker latest ticker data

type Tickers

type Tickers struct {
	Data []Ticker `json:"data"`
}

Tickers contain all tickers

type TimeInterval

type TimeInterval string

TimeInterval base type

type Trade

type Trade struct {
	ID        float64 `json:"id"`
	Price     float64 `json:"price"`
	Amount    float64 `json:"amount"`
	Direction string  `json:"direction"`
	Timestamp int64   `json:"ts"`
}

Trade stores the trade data

type TradeHistory

type TradeHistory struct {
	ID        int64   `json:"id"`
	Timestamp int64   `json:"ts"`
	Trades    []Trade `json:"data"`
}

TradeHistory stores the the trade history data

type WithdrawDepositHistory

type WithdrawDepositHistory struct {
	ID         int     `json:"id"`
	Type       string  `json:"type"`
	Currency   string  `json:"currency"`
	TxID       string  `json:"tx-hash"`
	Amount     float64 `json:"amount"`
	Address    string  `json:"address"`
	AddressTag string  `json:"address-tag"`
	Fee        float64 `json:"fee"`
	State      string  `json:"state"`
	CreatedAt  int     `json:"created-at"`
	UpdatedAt  int     `json:"updated-at"`
}
WithdrawDepositHistory ...
{
	"id": 1171,
	"type": "deposit",
	"currency": "xrp",
	"tx-hash": "ed03094b84eafbe4bc16e7ef766ee959885ee5bcb265872baaa9c64e1cf86c2b",
	"amount": 7.457467,
	"address": "rae93V8d2mdoUQHwBDBdM4NHCMehRJAsbm",
	"address-tag": "100040",
	"fee": 0,
	"state": "safe",
	"created-at": 1510912472199,
	"updated-at": 1511145876575
}

type WithdrawQuota

type WithdrawQuota struct {
	Currency string       `json:"currency"`
	Chains   []ChainQuota `json:"chains"`
}

WithdrawQuota stores the users withdraw quotas

type WsAuthenticatedAccountsListRequest

type WsAuthenticatedAccountsListRequest struct {
	Op               string `json:"op"`
	AccessKeyID      string `json:"AccessKeyId"`
	SignatureMethod  string `json:"SignatureMethod"`
	SignatureVersion string `json:"SignatureVersion"`
	Timestamp        string `json:"Timestamp"`
	Signature        string `json:"Signature"`
	Topic            string `json:"topic"`
	Symbol           string `json:"symbol"`
	ClientID         int64  `json:"cid,string,omitempty"`
}

WsAuthenticatedAccountsListRequest request for account list authenticated connection

type WsAuthenticatedAccountsListResponse

type WsAuthenticatedAccountsListResponse struct {
	WsResponse
	Data []WsAuthenticatedAccountsListResponseData `json:"data"`
}

WsAuthenticatedAccountsListResponse response from AccountsList authenticated endpoint

type WsAuthenticatedAccountsListResponseData

type WsAuthenticatedAccountsListResponseData struct {
	ID    int64                                         `json:"id"`
	Type  string                                        `json:"type"`
	State string                                        `json:"state"`
	List  []WsAuthenticatedAccountsListResponseDataList `json:"list"`
}

WsAuthenticatedAccountsListResponseData account data

type WsAuthenticatedAccountsListResponseDataList

type WsAuthenticatedAccountsListResponseDataList struct {
	Currency string  `json:"currency"`
	Type     string  `json:"type"`
	Balance  float64 `json:"balance,string"`
}

WsAuthenticatedAccountsListResponseDataList detailed account data

type WsAuthenticatedAccountsResponse

type WsAuthenticatedAccountsResponse struct {
	WsResponse
	Data WsAuthenticatedAccountsResponseData `json:"data"`
}

WsAuthenticatedAccountsResponse response from Accounts authenticated subscription

type WsAuthenticatedAccountsResponseData

type WsAuthenticatedAccountsResponseData struct {
	Event string                                    `json:"event"`
	List  []WsAuthenticatedAccountsResponseDataList `json:"list"`
}

WsAuthenticatedAccountsResponseData account data

type WsAuthenticatedAccountsResponseDataList

type WsAuthenticatedAccountsResponseDataList struct {
	AccountID int64   `json:"account-id"`
	Currency  string  `json:"currency"`
	Type      string  `json:"type"`
	Balance   float64 `json:"balance,string"`
}

WsAuthenticatedAccountsResponseDataList detailed account data

type WsAuthenticatedOrderDetailResponse

type WsAuthenticatedOrderDetailResponse struct {
	WsResponse
	Data OrderInfo `json:"data"`
}

WsAuthenticatedOrderDetailResponse response from OrderDetail authenticated endpoint

type WsAuthenticatedOrderDetailsRequest

type WsAuthenticatedOrderDetailsRequest struct {
	Op               string `json:"op"`
	AccessKeyID      string `json:"AccessKeyId"`
	SignatureMethod  string `json:"SignatureMethod"`
	SignatureVersion string `json:"SignatureVersion"`
	Timestamp        string `json:"Timestamp"`
	Signature        string `json:"Signature"`
	Topic            string `json:"topic"`
	OrderID          string `json:"order-id"`
	ClientID         int64  `json:"cid,string,omitempty"`
}

WsAuthenticatedOrderDetailsRequest request for order details authenticated connection

type WsAuthenticatedOrdersListRequest

type WsAuthenticatedOrdersListRequest struct {
	Op               string `json:"op"`
	AccessKeyID      string `json:"AccessKeyId"`
	SignatureMethod  string `json:"SignatureMethod"`
	SignatureVersion string `json:"SignatureVersion"`
	Timestamp        string `json:"Timestamp"`
	Signature        string `json:"Signature"`
	Topic            string `json:"topic"`
	States           string `json:"states"`
	AccountID        int64  `json:"account-id"`
	Symbol           string `json:"symbol"`
	ClientID         int64  `json:"cid,string,omitempty"`
}

WsAuthenticatedOrdersListRequest request for orderslist authenticated connection

type WsAuthenticatedOrdersListResponse

type WsAuthenticatedOrdersListResponse struct {
	WsResponse
	Data []OrderInfo `json:"data"`
}

WsAuthenticatedOrdersListResponse response from OrdersList authenticated endpoint

type WsAuthenticatedOrdersResponse

type WsAuthenticatedOrdersResponse struct {
	WsResponse
	Data []WsAuthenticatedOrdersResponseData `json:"data"`
}

WsAuthenticatedOrdersResponse response from Orders authenticated subscription

type WsAuthenticatedOrdersResponseData

type WsAuthenticatedOrdersResponseData struct {
	SeqID            int64   `json:"seq-id"`
	OrderID          int64   `json:"order-id"`
	Symbol           string  `json:"symbol"`
	AccountID        int64   `json:"account-id"`
	OrderAmount      float64 `json:"order-amount,string"`
	OrderPrice       float64 `json:"order-price,string"`
	CreatedAt        int64   `json:"created-at"`
	OrderType        string  `json:"order-type"`
	OrderSource      string  `json:"order-source"`
	OrderState       string  `json:"order-state"`
	Role             string  `json:"role"`
	Price            float64 `json:"price,string"`
	FilledAmount     float64 `json:"filled-amount,string"`
	UnfilledAmount   float64 `json:"unfilled-amount,string"`
	FilledCashAmount float64 `json:"filled-cash-amount,string"`
	FilledFees       float64 `json:"filled-fees,string"`
}

WsAuthenticatedOrdersResponseData order data

type WsAuthenticatedOrdersUpdateResponse

type WsAuthenticatedOrdersUpdateResponse struct {
	WsResponse
	Data WsAuthenticatedOrdersUpdateResponseData `json:"data"`
}

WsAuthenticatedOrdersUpdateResponse response from OrdersUpdate authenticated subscription

type WsAuthenticatedOrdersUpdateResponseData

type WsAuthenticatedOrdersUpdateResponseData struct {
	UnfilledAmount   float64 `json:"unfilled-amount,string"`
	FilledAmount     float64 `json:"filled-amount,string"`
	Price            float64 `json:"price,string"`
	OrderID          int64   `json:"order-id"`
	Symbol           string  `json:"symbol"`
	MatchID          int64   `json:"match-id"`
	FilledCashAmount float64 `json:"filled-cash-amount,string"`
	Role             string  `json:"role"`
	OrderState       string  `json:"order-state"`
	OrderType        string  `json:"order-type"`
}

WsAuthenticatedOrdersUpdateResponseData order update data

type WsAuthenticatedSubscriptionRequest

type WsAuthenticatedSubscriptionRequest struct {
	Op               string `json:"op"`
	AccessKeyID      string `json:"AccessKeyId"`
	SignatureMethod  string `json:"SignatureMethod"`
	SignatureVersion string `json:"SignatureVersion"`
	Timestamp        string `json:"Timestamp"`
	Signature        string `json:"Signature"`
	Topic            string `json:"topic"`
	ClientID         int64  `json:"cid,string,omitempty"`
}

WsAuthenticatedSubscriptionRequest request for subscription on authenticated connection

type WsAuthenticationRequest

type WsAuthenticationRequest struct {
	Op               string `json:"op"`
	AccessKeyID      string `json:"AccessKeyId"`
	SignatureMethod  string `json:"SignatureMethod"`
	SignatureVersion string `json:"SignatureVersion"`
	Timestamp        string `json:"Timestamp"`
	Signature        string `json:"Signature"`
	ClientID         int64  `json:"cid,string,omitempty"`
}

WsAuthenticationRequest data for login

type WsDepth

type WsDepth struct {
	Channel   string `json:"ch"`
	Timestamp int64  `json:"ts"`
	Tick      struct {
		Bids      [][]interface{} `json:"bids"`
		Asks      [][]interface{} `json:"asks"`
		Timestamp int64           `json:"ts"`
		Version   int64           `json:"version"`
	} `json:"tick"`
}

WsDepth defines market depth websocket response

type WsHeartBeat

type WsHeartBeat struct {
	ClientNonce int64 `json:"ping"`
}

WsHeartBeat defines a heartbeat request

type WsKline

type WsKline struct {
	Channel   string `json:"ch"`
	Timestamp int64  `json:"ts"`
	Tick      struct {
		ID     int64   `json:"id"`
		Open   float64 `json:"open"`
		Close  float64 `json:"close"`
		Low    float64 `json:"low"`
		High   float64 `json:"high"`
		Amount float64 `json:"amount"`
		Volume float64 `json:"vol"`
		Count  int64   `json:"count"`
	}
}

WsKline defines market kline websocket response

type WsMessage

type WsMessage struct {
	Raw []byte
	URL string
}

WsMessage defines read data from the websocket connection

type WsOldOrderUpdate

type WsOldOrderUpdate struct {
	WsResponse
	Data WsAuthenticatedOrdersResponseData `json:"data"`
}

WsOldOrderUpdate response from Orders authenticated subscription

type WsPong

type WsPong struct {
	Pong int64 `json:"pong"`
}

WsPong sent for pong messages

type WsRequest

type WsRequest struct {
	Topic       string `json:"req,omitempty"`
	Subscribe   string `json:"sub,omitempty"`
	Unsubscribe string `json:"unsub,omitempty"`
	ClientID    int64  `json:"cid,string,omitempty"`
}

WsRequest defines a request data structure

type WsResponse

type WsResponse struct {
	Op           string `json:"op"`
	TS           int64  `json:"ts"`
	Status       string `json:"status"`
	ErrorCode    int64  `json:"err-code"`
	ErrorMessage string `json:"err-msg"`
	Ping         int64  `json:"ping"`
	Channel      string `json:"ch"`
	Rep          string `json:"rep"`
	Topic        string `json:"topic"`
	Subscribed   string `json:"subbed"`
	UnSubscribed string `json:"unsubbed"`
	ClientID     int64  `json:"cid,string"`
}

WsResponse defines a response from the websocket connection when there is an error

type WsTick

type WsTick struct {
	Channel   string `json:"ch"`
	Rep       string `json:"rep"`
	Timestamp int64  `json:"ts"`
	Tick      struct {
		Amount    float64 `json:"amount"`
		Close     float64 `json:"close"`
		Count     float64 `json:"count"`
		High      float64 `json:"high"`
		ID        float64 `json:"id"`
		Low       float64 `json:"low"`
		Open      float64 `json:"open"`
		Timestamp float64 `json:"ts"`
		Volume    float64 `json:"vol"`
	} `json:"tick"`
}

WsTick stores websocket ticker data

type WsTrade

type WsTrade struct {
	Channel   string `json:"ch"`
	Timestamp int64  `json:"ts"`
	Tick      struct {
		ID        int64 `json:"id"`
		Timestamp int64 `json:"ts"`
		Data      []struct {
			Amount    float64 `json:"amount"`
			Timestamp int64   `json:"ts"`
			ID        float64 `json:"id"`
			Price     float64 `json:"price"`
			Direction string  `json:"direction"`
		} `json:"data"`
	}
}

WsTrade defines market trade websocket response

Jump to

Keyboard shortcuts

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