huobi

package
v0.0.0-...-b8e8dbd Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2018 License: MIT Imports: 16 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
  • Initial generation
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 HuobiSocket *socketio.SocketIO

HuobiSocket is a pointer to a IO Socket

Functions

This section is empty.

Types

type Account

type Account struct {
	ID     int64  `json:"id"`
	Type   string `json:"type"`
	State  string `json:"working"`
	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 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 Depth

type Depth struct {
	SymbolID  string    `json:"symbolId"`
	Time      float64   `json:"time"`
	Version   float64   `json:"version"`
	BidName   string    `json:"bidName"`
	BidPrice  []float64 `json:"bidPrice"`
	BidTotal  []float64 `json:"bidTotal"`
	BidAmount []float64 `json:"bidAmount"`
	AskName   string    `json:"askName"`
	AskPrice  []float64 `json:"askPrice"`
	AskTotal  []float64 `json:"askTotal"`
	AskAmount []float64 `json:"askAmount"`
}

Depth holds depth information

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
}

HUOBI is the overarching type across this package

func (*HUOBI) BuildHuobiWebsocketParamsList

func (h *HUOBI) BuildHuobiWebsocketParamsList(objectName, currency, pushType, period, count, from, to, percentage string) interface{}

BuildHuobiWebsocketParamsList packages a parameter list

func (*HUOBI) BuildHuobiWebsocketRequest

func (h *HUOBI) BuildHuobiWebsocketRequest(msgType string, requestIndex int64, symbolRequest []string) map[string]interface{}

BuildHuobiWebsocketRequest packages a new request

func (*HUOBI) BuildHuobiWebsocketRequestExtra

func (h *HUOBI) BuildHuobiWebsocketRequestExtra(msgType string, requestIndex int64, symbolIDList interface{}) interface{}

BuildHuobiWebsocketRequestExtra packages an extra request

func (*HUOBI) CancelAllExchangeOrders

func (h *HUOBI) CancelAllExchangeOrders(p pair.CurrencyPair) error

CancelAllExchangeOrders cancels all orders associated with a currency pair

func (*HUOBI) CancelExchangeOrder

func (h *HUOBI) CancelExchangeOrder(p pair.CurrencyPair, orderID int64) (int64, error)

CancelExchangeOrder cancels an order by its corresponding ID number

func (*HUOBI) CancelOrder

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

CancelOrder cancels an order on Huobi

func (*HUOBI) CancelOrderBatch

func (h *HUOBI) CancelOrderBatch(orderIDs []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) GetAccountBalance

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

GetAccountBalance returns the users Huobi account balance

func (*HUOBI) GetAccounts

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

GetAccounts returns the Huobi user accounts

func (*HUOBI) GetCurrencies

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

GetCurrencies returns a list of currencies supported by Huobi

func (*HUOBI) GetDepth

func (h *HUOBI) GetDepth(symbol, depthType string) (Orderbook, error)

GetDepth returns the depth for the specified symbol

func (*HUOBI) GetExchangeAccountInfo

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

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

func (*HUOBI) GetExchangeDepositAddress

func (h *HUOBI) GetExchangeDepositAddress(p pair.CurrencyPair) (string, error)

GetExchangeDepositAddress returns a deposit address for a specified currency

func (*HUOBI) GetExchangeHistory

func (h *HUOBI) GetExchangeHistory(p pair.CurrencyPair, assetType string) ([]exchange.TradeHistory, error)

GetExchangeHistory returns historic trade data since exchange opening.

func (*HUOBI) GetExchangeOrderInfo

func (h *HUOBI) GetExchangeOrderInfo(orderID int64) (float64, error)

GetExchangeOrderInfo returns information on a current open order

func (*HUOBI) GetFee

func (h *HUOBI) GetFee() float64

GetFee returns Huobi fee

func (*HUOBI) GetKline

func (h *HUOBI) GetKline(symbol, period, size string) ([]KlineItem, error)

GetKline returns kline data

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

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

GetOrder returns order information for the specified 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 pair.CurrencyPair, 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) GetSymbols

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

GetSymbols returns an array of symbols supported by Huobi

func (*HUOBI) GetTickerPrice

func (h *HUOBI) GetTickerPrice(p pair.CurrencyPair, 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) 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) ModifyExchangeOrder

func (h *HUOBI) ModifyExchangeOrder(p pair.CurrencyPair, orderID, action int64) (int64, error)

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

func (*HUOBI) OnConnect

func (h *HUOBI) OnConnect(output chan socketio.Message)

OnConnect handles connection establishment

func (*HUOBI) OnDisconnect

func (h *HUOBI) OnDisconnect(output chan socketio.Message)

OnDisconnect handles disconnection

func (*HUOBI) OnError

func (h *HUOBI) OnError()

OnError handles error issues

func (*HUOBI) OnMessage

func (h *HUOBI) OnMessage(message []byte, output chan socketio.Message)

OnMessage handles messages from the exchange

func (*HUOBI) OnRequest

func (h *HUOBI) OnRequest(message []byte, output chan socketio.Message)

OnRequest handles requests

func (*HUOBI) PlaceOrder

func (h *HUOBI) PlaceOrder(symbol, source, accountID, orderType string, amount, price float64) (int64, error)

PlaceOrder submits an order to Huobi

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, 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) Start

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

Start starts the HUOBI go routine

func (*HUOBI) SubmitExchangeOrder

func (h *HUOBI) SubmitExchangeOrder(p pair.CurrencyPair, side string, orderType int, amount, price float64) (int64, error)

SubmitExchangeOrder submits a new order

func (*HUOBI) UpdateOrderbook

func (h *HUOBI) UpdateOrderbook(p pair.CurrencyPair, assetType string) (orderbook.Base, error)

UpdateOrderbook updates and returns the orderbook for a currency pair

func (*HUOBI) UpdateTicker

func (h *HUOBI) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error)

UpdateTicker updates and returns the ticker for a currency pair

func (*HUOBI) WebsocketClient

func (h *HUOBI) WebsocketClient()

WebsocketClient creates a new websocket client

func (*HUOBI) Withdraw

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

Withdraw withdraws the desired amount and currency

func (*HUOBI) WithdrawExchangeFunds

func (h *HUOBI) WithdrawExchangeFunds(address string, p pair.CurrencyPair, amount float64) (string, error)

WithdrawExchangeFunds returns a withdrawal ID when a withdrawal is submitted

type KlineItem

type KlineItem struct {
	ID     int     `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 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 OrderInfo

type OrderInfo struct {
	ID              int    `json:"id"`
	Symbol          string `json:"symbol"`
	AccountID       int    `json:"account-id"`
	Amount          string `json:"amount"`
	Price           string `json:"price"`
	CreatedAt       int64  `json:"created-at"`
	Type            string `json:"type"`
	FieldAmount     string `json:"field-amount"`
	FieldCashAmount string `json:"field-cash-amount"`
	FieldFees       string `json:"field-fees"`
	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 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 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 WebsocketLastTimeline

type WebsocketLastTimeline struct {
	ID        int64   `json:"_id"`
	SymbolID  string  `json:"symbolId"`
	Time      int64   `json:"time"`
	LastPrice float64 `json:"priceLast"`
	Amount    float64 `json:"amount"`
	Volume    float64 `json:"volume"`
	Count     int64   `json:"count"`
}

WebsocketLastTimeline holds timeline data

type WebsocketMarketOverview

type WebsocketMarketOverview struct {
	SymbolID    string  `json:"symbolId"`
	Last        float64 `json:"priceNew"`
	Open        float64 `json:"priceOpen"`
	High        float64 `json:"priceHigh"`
	Low         float64 `json:"priceLow"`
	Ask         float64 `json:"priceAsk"`
	Bid         float64 `json:"priceBid"`
	Volume      float64 `json:"totalVolume"`
	TotalAmount float64 `json:"totalAmount"`
}

WebsocketMarketOverview holds market overview data

type WebsocketResponse

type WebsocketResponse struct {
	Version      int                    `json:"version"`
	MsgType      string                 `json:"msgType"`
	RequestIndex int64                  `json:"requestIndex"`
	RetCode      int64                  `json:"retCode"`
	RetMessage   string                 `json:"retMsg"`
	Payload      map[string]interface{} `json:"payload"`
}

WebsocketResponse is a general response type for websocket

type WebsocketTrade

type WebsocketTrade struct {
	Price      []float64 `json:"price"`
	Level      []float64 `json:"level"`
	Amount     []float64 `json:"amount"`
	AccuAmount []float64 `json:"accuAmount"`
}

WebsocketTrade holds full trade data

type WebsocketTradeDetail

type WebsocketTradeDetail struct {
	SymbolID string           `json:"symbolId"`
	TradeID  []int64          `json:"tradeId"`
	Price    []float64        `json:"price"`
	Time     []int64          `json:"time"`
	Amount   []float64        `json:"amount"`
	TopBids  []WebsocketTrade `json:"topBids"`
	TopAsks  []WebsocketTrade `json:"topAsks"`
}

WebsocketTradeDetail holds specific trade details

Jump to

Keyboard shortcuts

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