huobi

package
v0.0.0-...-eb07c7e Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2019 License: MIT Imports: 25 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 progresss 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.GetTickerPrice()
if err != nil {
  // Handle error
}

// Fetches current orderbook information
ob, err := h.GetOrderbookEx()
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:

1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB

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 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        int     `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 int       `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              *websocket.Conn
	AuthenticatedWebsocketConn *websocket.Conn
	// contains filtered or unexported fields
}

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 *exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, 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 *exchange.OrderCancellation) 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) 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) GetAccountInfo

func (h *HUOBI) GetAccountInfo() (exchange.AccountInfo, error)

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

func (*HUOBI) GetAccounts

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

GetAccounts returns the Huobi user accounts

func (*HUOBI) GetActiveOrders

func (h *HUOBI) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, 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) GetDepositAddress

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

GetDepositAddress returns a deposit address for a specified currency

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 string) ([]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) 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 int) ([]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(getOrdersRequest *exchange.GetOrdersRequest) ([]exchange.OrderDetail, error)

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

func (*HUOBI) GetOrderInfo

func (h *HUOBI) GetOrderInfo(orderID string) (exchange.OrderDetail, 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) GetOrderbookEx

func (h *HUOBI) GetOrderbookEx(p currency.Pair, assetType string) (orderbook.Base, error)

GetOrderbookEx returns orderbook base on the currency pair

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() ([]exchange.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) GetTickerPrice

func (h *HUOBI) GetTickerPrice(p currency.Pair, assetType string) (ticker.Price, error)

GetTickerPrice returns the ticker for a currency pair

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() (*exchange.Websocket, error)

GetWebsocket returns a pointer to the exchange websocket

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 *exchange.ModifyOrder) (string, error)

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

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{}) 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)

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(p currency.Pair, side exchange.OrderSide, orderType exchange.OrderType, amount, price float64, clientID string) (exchange.SubmitOrderResponse, error)

SubmitOrder submits a new order

func (*HUOBI) Subscribe

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

Subscribe sends a websocket message to receive data from the channel

func (*HUOBI) SubscribeToWebsocketChannels

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

SubscribeToWebsocketChannels appends to ChannelsToSubscribe which lets websocket.manageSubscriptions handle subscribing

func (*HUOBI) Unsubscribe

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

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

func (*HUOBI) UnsubscribeToWebsocketChannels

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

UnsubscribeToWebsocketChannels removes from ChannelsToSubscribe which lets websocket.manageSubscriptions handle unsubscribing

func (*HUOBI) UpdateOrderbook

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

UpdateOrderbook updates and returns the orderbook for a currency pair

func (*HUOBI) UpdateTicker

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

UpdateTicker updates and returns the ticker for a currency pair

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 *exchange.WithdrawRequest) (string, error)

WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is submitted

func (*HUOBI) WithdrawFiatFunds

func (h *HUOBI) WithdrawFiatFunds(withdrawRequest *exchange.WithdrawRequest) (string, error)

WithdrawFiatFunds returns a withdrawal ID when a withdrawal is submitted

func (*HUOBI) WithdrawFiatFundsToInternationalBank

func (h *HUOBI) WithdrawFiatFundsToInternationalBank(withdrawRequest *exchange.WithdrawRequest) (string, 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) WsHandleData

func (h *HUOBI) WsHandleData()

WsHandleData handles data read from the websocket connection

func (*HUOBI) WsProcessOrderbook

func (h *HUOBI) WsProcessOrderbook(ob *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"`
	Vol    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               int     `json:"id"`
	Symbol           string  `json:"symbol"`
	AccountID        float64 `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"`
	Fieldees         float64 `json:"field-fees,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           int     `json:"user-id"`
	Source           string  `json:"source"`
	State            string  `json:"state"`
	CanceledAt       int     `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 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 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"`
}

Symbol stores the symbol data

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 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           currency.Pair `json:"symbol"`
}

WsAuthenticatedAccountsListRequest request for account list authenticated connection

type WsAuthenticatedAccountsListResponse

type WsAuthenticatedAccountsListResponse struct {
	WsAuthenticatedDataResponse
	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 {
	WsAuthenticatedDataResponse
	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 WsAuthenticatedDataResponse

type WsAuthenticatedDataResponse struct {
	Op           string `json:"op,omitempty"`
	Ts           int64  `json:"ts,omitempty"`
	Topic        string `json:"topic,omitempty"`
	ErrorCode    int64  `json:"err-code,omitempty"`
	ErrorMessage string `json:"err-msg,omitempty"`
	Ping         int64  `json:"ping,omitempty"`
	CID          string `json:"cid,omitempty"`
}

WsAuthenticatedDataResponse response from authenticated connection

type WsAuthenticatedOrderDetailResponse

type WsAuthenticatedOrderDetailResponse struct {
	WsAuthenticatedDataResponse
	Data WsAuthenticatedOrdersListResponseData `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"`
}

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           currency.Pair `json:"symbol"`
}

WsAuthenticatedOrdersListRequest request for orderslist authenticated connection

type WsAuthenticatedOrdersListResponse

type WsAuthenticatedOrdersListResponse struct {
	WsAuthenticatedDataResponse
	Data []WsAuthenticatedOrdersListResponseData `json:"data"`
}

WsAuthenticatedOrdersListResponse response from OrdersList authenticated endpoint

type WsAuthenticatedOrdersListResponseData

type WsAuthenticatedOrdersListResponseData struct {
	ID               int64         `json:"id"`
	Symbol           currency.Pair `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"`
	FilledAmount     float64       `json:"filled-amount,string"`
	FilledCashAmount float64       `json:"filled-cash-amount,string"`
	FilledFees       float64       `json:"filled-fees,string"`
	FinishedAt       int64         `json:"finished-at"`
	Source           string        `json:"source"`
	State            string        `json:"state"`
	CanceledAt       int64         `json:"canceled-at"`
}

WsAuthenticatedOrdersListResponseData contains order details

type WsAuthenticatedOrdersResponse

type WsAuthenticatedOrdersResponse struct {
	WsAuthenticatedDataResponse
	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           currency.Pair `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 {
	WsAuthenticatedDataResponse
	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           currency.Pair `json:"symbol"`
	MatchID          int64         `json:"match-id"`
	FilledCashAmount float64       `json:"filled-cash-amount,string"`
	Role             string        `json:"role"`
	OrderState       string        `json:"order-state"`
}

WsAuthenticatedOrdersUpdateResponseData order updatedata

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"`
}

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"`
}

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 WsRequest

type WsRequest struct {
	Topic             string `json:"req,omitempty"`
	Subscribe         string `json:"sub,omitempty"`
	Unsubscribe       string `json:"unsub,omitempty"`
	ClientGeneratedID string `json:"id,omitempty"`
}

WsRequest defines a request data structure

type WsResponse

type WsResponse struct {
	TS           int64       `json:"ts"`
	Status       string      `json:"status"`
	ErrorCode    interface{} `json:"err-code"`
	ErrorMessage string      `json:"err-msg"`
	Ping         int64       `json:"ping"`
	Channel      string      `json:"ch"`
	Subscribed   string      `json:"subbed"`
}

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

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