huobi

package
v0.0.202 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RequestsPerSecond float64                         = 10
	BeforeRequest     func(method, path string) error = nil
	AfterRequest      func()                          = nil
)

Functions

func IsError

func IsError(body []byte) (bool, string)

Types

type Account

type Account struct {
	Id          int64        `json:"id"`    // unique account id
	AccountType AccountType  `json:"type"`  // the type of this account (see above)
	State       AccountState `json:"state"` // account state (see above)
}

type AccountState

type AccountState string
const (
	AccountStateWorking AccountState = "working"
	AccountStateLock    AccountState = "lock"
)

type AccountType

type AccountType string
const (
	AccountTypeSpot        AccountType = "spot"
	AccountTypeMargin      AccountType = "margin"
	AccountTypeOTC         AccountType = "otc"
	AccountTypePoint       AccountType = "point"
	AccountTypeSuperMargin AccountType = "super-margin"
	AccountTypeInvestment  AccountType = "investment"
	AccountTypeBorrow      AccountType = "borrow"
)

type BookEntry

type BookEntry []float64

func (*BookEntry) Price

func (be *BookEntry) Price() float64

func (*BookEntry) Size

func (be *BookEntry) Size() float64

type Client

type Client struct {
	URL string
	// contains filtered or unexported fields
}

func New

func New(URL, apiKey, apiSecret string) *Client

func (*Client) Account

func (client *Client) Account(accountType AccountType, accountState AccountState) (*Account, error)

func (*Client) Accounts

func (client *Client) Accounts() ([]Account, error)

func (*Client) CancelOrder

func (client *Client) CancelOrder(orderId int64) error

func (*Client) OpenOrders

func (client *Client) OpenOrders(symbol string) ([]Order, error)

func (*Client) OrderBook

func (client *Client) OrderBook(symbol string) (*OrderBook, error)

func (*Client) PastOrders

func (client *Client) PastOrders(symbol string, days int, state OrderState) ([]Order, error)

func (*Client) PlaceOrder

func (client *Client) PlaceOrder(symbol string, orderType OrderType, amount, price float64, metadata string) ([]byte, error)

func (*Client) Summary

func (client *Client) Summary(symbol string) (*Summary, error)

func (*Client) Symbols

func (client *Client) Symbols() ([]Symbol, error)

func (*Client) Ticker

func (client *Client) Ticker(symbol string) (*Ticker, error)

type Order

type Order struct {
	Symbol           string     `json:"symbol"` // the trading symbol to trade, e.g. btcusdt, bccbtc
	Amount           float64    `json:"amount,string"`
	Price            float64    `json:"price,string"` // the limit price of limit order
	CreatedAt        int64      `json:"created-at"`   // the timestamp in milliseconds when the order was created
	AccountId        int64      `json:"account-id"`
	ClientOrderId    string     `json:"client-order-id"`          // the identity defined by the client
	FilledAmount     float64    `json:"field-amount,string"`      // the amount which has been filled
	FilledCashAmount float64    `json:"field-cash-amount,string"` // the filled total in quote currency
	FilledFees       float64    `json:"field-fees,string"`        // transaction fee
	Id               int64      `json:"id"`                       // the unique identity for the order
	State            OrderState `json:"state"`                    // order status (see above)
	OrderType        OrderType  `json:"type"`                     // order type (see above)
}

func (*Order) GetCreatedAt

func (order *Order) GetCreatedAt() time.Time

func (*Order) IsBuy

func (order *Order) IsBuy() bool

func (*Order) IsSell

func (order *Order) IsSell() bool

func (*Order) Side

func (order *Order) Side() string

type OrderBook

type OrderBook struct {
	Bids []BookEntry `json:"bids"`
	Asks []BookEntry `json:"asks"`
}

type OrderState

type OrderState string
const (
	OrderStateCreated         OrderState = "created"          // The order is created, and not in the matching queue yet.
	OrderStateSubmitted       OrderState = "submitted"        // The order is submitted, and already in the matching queue, waiting for deal.
	OrderStatePartialFilled   OrderState = "partial-filled"   // The order is already in the matching queue and partially traded, and is waiting for further matching and trade.
	OrderStateFilled          OrderState = "filled"           // The order is already traded and not in the matching queue any more.
	OrderStatePartialCanceled OrderState = "partial-canceled" // The order is not in the matching queue any more. The status is transferred from 'partial-filled', the order is partially trade, but remaining is canceled.
	OrderStateCanceling       OrderState = "canceling"        // The order is under canceling, but haven't been removed from matching queue yet.
	OrderStateCanceled        OrderState = "canceled"         // The order is not in the matching queue any more, and completely canceled. There is no trade associated with this order.
)

type OrderType

type OrderType string
const (
	OrderTypeBuyMarket        OrderType = "buy-market"
	OrderTypeSellMarket       OrderType = "sell-market"
	OrderTypeBuyLimit         OrderType = "buy-limit"
	OrderTypeSellLimit        OrderType = "sell-limit"
	OrderTypeBuyIOC           OrderType = "buy-ioc"  // IOC stands for "immediately or cancel", it means the order will be canceled if it couldn't be matched. If the order is partially traded, the remaining part will be canceled.
	OrderTypeSellIOC          OrderType = "sell-ioc" // IOC stands for "immediately or cancel", it means the order will be canceled if it couldn't be matched. If the order is partially traded, the remaining part will be canceled.
	OrderTypeBuyLimitMaker    OrderType = "buy-limit-maker"
	OrderTypeSellLimitMaker   OrderType = "sell-limit-maker"
	OrderTypeBuyStopLimit     OrderType = "buy-stop-limit"
	OrderTypeSellStopLimit    OrderType = "sell-stop-limit"
	OrderTypeBuyLimitFOK      OrderType = "buy-limit-fok"  // FOK stands for "fill or kill", it means the order will be cancelled if it couldn't be fully matched. Even if the order can be partially filled, the entire order will be cancelled.
	OrderTypeSellLimitFOK     OrderType = "sell-limit-fok" // FOK stands for "fill or kill", it means the order will be cancelled if it couldn't be fully matched. Even if the order can be partially filled, the entire order will be cancelled.
	OrderTypeBuyStopLimitFOK  OrderType = "buy-stop-limit-fok"
	OrderTypeSellStopLimitFOK OrderType = "sell-stop-limit-fok"
)

type Response

type Response struct {
	Status string `json:"status"`
	ErrMsg string `json:"err-msg"`
}

type Summary

type Summary struct {
	Low    float64 `json:"low"`    // the lowest price of last 24 hours
	High   float64 `json:"high"`   // the highest price of last 24 hours
	Open   float64 `json:"open"`   // the opening price of last 24 hours
	Close  float64 `json:"close"`  // the closing price of last 24 hours
	Volume float64 `json:"vol"`    // the trading volume in base currency of last 24 hours
	Amount float64 `json:"amount"` // the aggregated trading volume in USDT of last 24 hours
}

type Symbol

type Symbol struct {
	BaseCurrency           string  `json:"base-currency"`
	QuoteCurrency          string  `json:"quote-currency"`
	PricePrecision         int     `json:"price-precision"`  // quote currency precision
	AmountPrecision        int     `json:"amount-precision"` // base currency precision
	Partition              string  `json:"symbol-partition"`
	Symbol                 string  `json:"symbol"`
	State                  string  `json:"state"`                      // "online" or "offline" or "suspended"
	ValuePrecision         int     `json:"value-precision"`            // precision of value in quote currency (value = price * amount)
	LimitOrderMinOrderAmt  float64 `json:"limit-order-min-order-amt"`  // minimum order amount of limit order in base currency
	LimitOrderMaxOrderAmt  float64 `json:"limit-order-max-order-amt"`  // max order amount of limit order in base currency
	SellMarketMinOrderAmt  float64 `json:"sell-market-min-order-amt"`  // minimum order amount of sell-market order in base currency
	SellMarketMaxOrderAmt  float64 `json:"sell-market-max-order-amt"`  // max order amount of sell-market order in base currency
	BuyMarketMaxOrderValue float64 `json:"buy-market-max-order-value"` // max order value of buy-market order in quote currency
	MinOrderValue          float64 `json:"min-order-value"`            // minimum order value of limit order and buy-market order in quote currency
	ApiTrading             string  `json:"api-trading"`                // "enabled" or "disabled"
}

func (*Symbol) Enabled

func (symbol *Symbol) Enabled() bool

func (*Symbol) Online

func (symbol *Symbol) Online() bool

type Ticker

type Ticker struct {
	Amount    float64 `json:"amount"`
	Price     float64 `json:"price"`
	Direction string  `json:"direction"`
}

Jump to

Keyboard shortcuts

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