spot

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2021 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AccountsEndPoint = "/v1/account/accounts"
	TypeFrozen       = "frozen"
	TypeTrade        = "trade"
)
View Source
const (
	ActionPing = "ping"
	ActionPong = "pong"
	ActionReq  = "req"
	ActionSub  = "sub"
	ActionPush = "push"
)
View Source
const (
	DirectNone Direct = ""
	DirectPrev Direct = "forward"
	DirectNext Direct = "next"

	MatchResutEndPoint = "/v1/order/matchresults"

	MatchRoleMaker = "maker"
	MatchRoleTaker = "taker"
)
View Source
const (
	MBPAddr = "wss://api-aws.huobi.pro/feed"
)
View Source
const (
	PlaceOrderEndPoint = "/v1/order/orders/place"
)
View Source
const (
	PrivateWSClientAddr = "wss://api.huobi.pro/ws/v2"
)
View Source
const (
	SpotHost = "api.huobi.pro"
)
View Source
const (
	TransactFeeRateEndPoint = "/v2/reference/transact-fee-rate"
)

Variables

This section is empty.

Functions

func Init added in v0.3.0

func Init(ctx context.Context) error

func NewMBPChannel added in v0.5.0

func NewMBPChannel(sym exchange.Symbol, size int) exchange.Channel

func ParseDepth added in v0.5.0

func ParseDepth(ch string, ts int64, tick json.RawMessage) (interface{}, error)

func ParseOrder added in v0.5.0

func ParseOrder(data json.RawMessage) (interface{}, error)

func ParseOrderStatus added in v0.5.0

func ParseOrderStatus(state string) (exchange.OrderStatus, error)

func ParseOrderType added in v0.5.0

func ParseOrderType(oType string) (exchange.OrderSide, exchange.OrderType, error)

func ParseSymbol added in v0.3.0

func ParseSymbol(symbol string) (exchange.SpotSymbol, error)

Types

type Account added in v0.5.0

type Account struct {
	ID      int64  `json:"id"`
	Type    string `json:"type"`
	State   string `json:"state"`
	SubType string `json:"subtype"`
}

type Balance added in v0.5.2

type Balance struct {
	Currency string `json:"currency"`
	Type     string `json:"type"`
	Balance  string `json:"balance"`
	SeqNum   string `json:"seq-num"`
}

type BalanceReq added in v0.5.2

type BalanceReq struct {
	AccountID int
}

type BalanceResp added in v0.5.2

type BalanceResp struct {
	ID    int       `json:"id"`
	Type  string    `json:"type"`
	State string    `json:"state"`
	List  []Balance `json:"list"`
}

type CodeC added in v0.5.0

type CodeC struct {
	*huobi.CodeC
}

func NewCodeC added in v0.5.0

func NewCodeC() *CodeC

func (*CodeC) Decode added in v0.5.0

func (cc *CodeC) Decode(raw []byte) (rpc.Response, error)

type Depth added in v0.5.0

type Depth struct {
	SeqNum     int64        `json:"seqNum"`
	PrevSeqNum int64        `json:"prevSeqNum"`
	Bids       [][2]float64 `json:"bids"`
	Asks       [][2]float64 `json:"asks"`
}

type Direct added in v0.3.0

type Direct string

type MBPChannel added in v0.5.0

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

func (*MBPChannel) String added in v0.5.0

func (mc *MBPChannel) String() string

type MBPDepthDS added in v0.5.0

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

MBPDepthDS build depth according incremental updates and refresh message the ds is inited which means the refresh message has been push int ods

func NewMBPDepthDS added in v0.5.0

func NewMBPDepthDS(symbol exchange.Symbol) *MBPDepthDS

func (*MBPDepthDS) AddRefresh added in v0.5.0

func (ds *MBPDepthDS) AddRefresh(d *Depth)

func (*MBPDepthDS) OrderBook added in v0.5.0

func (ds *MBPDepthDS) OrderBook(size int) *exchange.OrderBook

OrderBook generate orderbook according ds bids, asks structure size specific orderbook size. -1 means use bids, asks size

func (*MBPDepthDS) Push added in v0.5.0

func (ds *MBPDepthDS) Push(d *Depth, ts time.Time) (inited bool, err error)

Push add incremental updates into ds, return wether the has have been inited

type MBPFullReq added in v0.5.0

type MBPFullReq struct {
	Req string `json:"req"`
	ID  string `json:"id"`
}

func NewMBPFullReq added in v0.5.0

func NewMBPFullReq(symbol exchange.Symbol, size int) *MBPFullReq

type MBPFullResp added in v0.5.0

type MBPFullResp struct {
	ID     string
	Status string
	TS     int64
	Req    string
	Data   Depth
}

type MatchResult added in v0.3.0

type MatchResult struct {
	ID                int64           `json:"id"`
	MatchID           int64           `json:"match-id"`
	OrderID           int64           `json:"order-id"`
	TradeID           int64           `json:"trade-id"`
	CreatedAt         int64           `json:"created-at"`
	FilledAmount      decimal.Decimal `json:"filled-amount"`
	FilledFees        decimal.Decimal `json:"filled-fees"`
	FilledPoints      decimal.Decimal `json:"filled-points"`
	FeeCurrency       string          `json:"fee-currency"`
	Price             decimal.Decimal `json:"price"`
	Source            string          `json:"source"`
	Symbol            string          `json:"symbol"`
	Type              string          `json:"type"`
	Role              string          `json:"role"`
	FeeDeductCurrency string          `json:"fee-deduct-currency"`
	FeeDeductState    string          `json:"fee-deduct-state"`
}

func (*MatchResult) Parse added in v0.3.0

func (mr *MatchResult) Parse() (*exchange.Trade, error)

type MatchResultReq added in v0.5.0

type MatchResultReq OrdersReq

func NewMatchResultReq added in v0.5.0

func NewMatchResultReq(orderID string) *MatchResultReq

type OrderData added in v0.5.0

type OrderData struct {
	EventType       string `json:"eventType"`
	Symbol          string `json:"symbol"`
	AccountID       int64  `json:"accountId"`
	OrderID         int64  `json:"orderId"`
	ClientOrderID   string `json:"clientOrderId"`
	OrderStatus     string `json:"orderStatus"`
	OrderPrice      string `json:"orderPrice"`
	OrderSize       string `json:"orderSize"`
	OrderValue      string `json:"orderValue"`
	Type            string `json:"type"`
	OrderCreateTime int64  `json:"orderCreateTime"`
	OrderSource     string `json:"orderSource"`
	TradePrice      string `json:"tradePrice"`
	TradeVolume     string `json:"tradeVolume"`
	TradeID         int64  `json:"tradeId"`
	TradeTime       int64  `json:"tradeTime"`
	Aggressor       bool   `json:"aggressor"`
	RemainAmt       string `json:"remainAmt"`
	ExecAmt         string `json:"execAmt"`
	LastActTime     int64  `json:"lastActTime"`
}

func (*OrderData) Parse added in v0.5.0

func (od *OrderData) Parse() (*exchange.Order, error)

type OrdersChannel added in v0.5.0

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

func NewOrdersChannel added in v0.5.0

func NewOrdersChannel(sym string) *OrdersChannel

func (*OrdersChannel) String added in v0.5.0

func (oc *OrdersChannel) String() string

type OrdersReq added in v0.5.0

type OrdersReq struct {
	OrderID string
}

func NewOrdersReq added in v0.5.0

func NewOrdersReq(orderID string) *OrdersReq

type OrdersResp added in v0.5.0

type OrdersResp struct {
	Data OrdersRespDetail `json:"data"`
}

func (*OrdersResp) Transform added in v0.5.0

func (r *OrdersResp) Transform() (*exchange.Order, error)

type OrdersRespDetail added in v0.5.0

type OrdersRespDetail struct {
	ID               int64  `json:"id"`
	Symbol           string `json:"symbol"`
	AccountID        int64  `json:"account-id"`
	Amount           string `json:"amount"`
	Price            string `json:"price"`
	CreatedAt        int64  `json:"created-at"`
	Type             string `json:"type"`
	FilledAmount     string `json:"filled-amount"`
	FilledCashAmount string `json:"filled-cash-amount"`
	FilledFees       string `json:"filled-fees"`
	FinishedAt       int64  `json:"finished-at"`
	UserID           int64  `json:"user-id"`
	Source           string `json:"source"`
	State            string `json:"state"`
	CanceledAt       int64  `json:"canceled-at"`
}

type PlaceReq added in v0.5.0

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

func NewPlaceReq added in v0.5.0

func NewPlaceReq(accountID string, symbol string, typ string, amount string) *PlaceReq

func (*PlaceReq) ClientOrderID added in v0.5.0

func (pr *PlaceReq) ClientOrderID(coi string) *PlaceReq

func (*PlaceReq) Operator added in v0.5.0

func (pr *PlaceReq) Operator(op string) *PlaceReq

func (*PlaceReq) Price added in v0.5.0

func (pr *PlaceReq) Price(price string) *PlaceReq

func (*PlaceReq) Serialize added in v0.5.0

func (pr *PlaceReq) Serialize() ([]byte, error)

func (*PlaceReq) Source added in v0.5.0

func (pr *PlaceReq) Source(source string) *PlaceReq

func (*PlaceReq) StopPrice added in v0.5.0

func (pr *PlaceReq) StopPrice(sp string) *PlaceReq

type PlaceResp added in v0.5.0

type PlaceResp struct {
	Status  string `json:"status"`
	Data    string `json:"data"`
	ErrCode string `json:"err-code"`
	ErrMsg  string `json:"err-msg"`
}

type PrivateCodeC added in v0.5.0

type PrivateCodeC struct {
}

func NewPrivateCodeC added in v0.5.0

func NewPrivateCodeC() *PrivateCodeC

func (*PrivateCodeC) Decode added in v0.5.0

func (pcc *PrivateCodeC) Decode(raw []byte) (rpc.Response, error)

func (*PrivateCodeC) Encode added in v0.5.0

func (pcc *PrivateCodeC) Encode(req rpc.Request) ([]byte, error)

type PrivateWSClient added in v0.5.0

type PrivateWSClient struct {
	*exchange.WSClient
	// contains filtered or unexported fields
}

func NewPrivateWSClient added in v0.5.0

func NewPrivateWSClient(key, secret string, data chan interface{}) *PrivateWSClient

func (*PrivateWSClient) Auth added in v0.5.0

func (pws *PrivateWSClient) Auth(ctx context.Context) error

func (*PrivateWSClient) Handle added in v0.5.0

func (pws *PrivateWSClient) Handle(ctx context.Context, n *rpc.Notify)

func (*PrivateWSClient) Run added in v0.5.0

func (pws *PrivateWSClient) Run(ctx context.Context) error

func (*PrivateWSClient) Subscribe added in v0.5.0

func (pws *PrivateWSClient) Subscribe(ctx context.Context, channels ...exchange.Channel) error

type PrivateWSReq added in v0.5.0

type PrivateWSReq struct {
	Action string      `json:"action"`
	Ch     string      `json:"ch"`
	Params interface{} `json:"params,omitempty"`
}

type PrivateWSResp added in v0.5.0

type PrivateWSResp struct {
	Action string          `json:"action"`
	Code   int             `json:"code"`
	Ch     string          `json:"ch"`
	Data   json.RawMessage `json:"data"`
}

type RestClient

type RestClient struct {
	*huobi.RestClient
	// contains filtered or unexported fields
}

func NewRestClient

func NewRestClient(key, secret string) *RestClient

func (*RestClient) Accounts added in v0.5.0

func (rc *RestClient) Accounts(ctx context.Context) ([]Account, error)

func (*RestClient) Balance added in v0.5.2

func (rc *RestClient) Balance(ctx context.Context, req *BalanceReq) (*BalanceResp, error)

func (*RestClient) FeeRate

func (rc *RestClient) FeeRate(ctx context.Context, symbols []exchange.Symbol) ([]*exchange.TradeFee, error)

func (*RestClient) FetchBalance added in v0.5.2

func (rc *RestClient) FetchBalance(ctx context.Context, currencies ...string) (*exchange.Balances, error)

func (*RestClient) FetchOrder added in v0.5.0

func (rc *RestClient) FetchOrder(ctx context.Context, order *exchange.Order) (*exchange.Order, error)

func (*RestClient) FetchSymbols added in v0.3.0

func (rc *RestClient) FetchSymbols(ctx context.Context) ([]Symbol, error)

func (*RestClient) Init

func (rc *RestClient) Init(ctx context.Context) error

Init spot account id for Balance request

func (*RestClient) MatchResult added in v0.5.0

func (rc *RestClient) MatchResult(ctx context.Context, req *MatchResultReq) ([]MatchResult, error)

func (*RestClient) MatchResults added in v0.3.0

func (rc *RestClient) MatchResults(ctx context.Context, symbol string, types []string, st int64, et int64, from string, d Direct, size int) ([]MatchResult, error)

func (*RestClient) Orders added in v0.5.0

func (rc *RestClient) Orders(ctx context.Context, req *OrdersReq) (*OrdersResp, error)

func (*RestClient) Place added in v0.5.0

func (rc *RestClient) Place(ctx context.Context, req *PlaceReq) (*PlaceResp, error)

func (*RestClient) SubmitCancel added in v0.5.0

func (rc *RestClient) SubmitCancel(ctx context.Context, req *SubmitCancelReq) (*PlaceResp, error)

func (*RestClient) Symbols added in v0.3.0

func (rc *RestClient) Symbols(ctx context.Context) ([]exchange.SpotSymbol, error)

func (*RestClient) Trades added in v0.3.0

func (rc *RestClient) Trades(ctx context.Context, req *exchange.TradeReqParam) ([]exchange.Trade, error)

func (*RestClient) TransactFeeRate added in v0.3.0

func (rc *RestClient) TransactFeeRate(ctx context.Context, symbols []string) ([]TransactFeeRate, error)

type SpotSymbol

type SpotSymbol struct {
	*exchange.BaseSpotSymbol
	Symbol string
}

func (*SpotSymbol) String

func (ss *SpotSymbol) String() string

type SubmitCancelReq added in v0.5.0

type SubmitCancelReq OrdersReq

func NewSubmitCancelReq added in v0.5.0

func NewSubmitCancelReq(orderID string) *SubmitCancelReq

type Symbol

type Symbol struct {
	BaseCurrency    string  `json:"base-currency"`
	QuoteCurreny    string  `json:"quote-currency"`
	Symbol          string  `json:"symbol"`
	MinOrderAmt     float64 `json:"min-order-amt"`
	MaxOrderAmt     float64 `json:"max-order-amt"`
	MinOrderValue   float64 `json:"min-order-value"`
	PricePrecision  int     `json:"price-precision"`
	AmountPrecision int     `json:"amount-precision"`
	ValuePrecision  int     `json:"value-precision"`
}

TODO add precision

func (*Symbol) Parse added in v0.3.0

func (s *Symbol) Parse() (exchange.SpotSymbol, error)

type SymbolResp

type SymbolResp struct {
	Status string   `json:"status"`
	Data   []Symbol `json:"data"`
}

type TransactFeeRate

type TransactFeeRate struct {
	Symbol          string
	MakerFeeRate    decimal.Decimal `json:"makerFeeRate"`
	TakerFeeRate    decimal.Decimal `json:"takerFeeRate"`
	ActualMakerRate decimal.Decimal `json:"actualMakerRate"`
	ActualTakerRate decimal.Decimal `json:"actualTakerRate"`
}

func (*TransactFeeRate) Parse added in v0.3.0

func (tfr *TransactFeeRate) Parse() (*exchange.TradeFee, error)

type WSClient added in v0.5.0

type WSClient struct {
	*huobi.WSClient
}

func NewMBPWSClient added in v0.5.0

func NewMBPWSClient(data chan interface{}) *WSClient

func (*WSClient) Subscribe added in v0.5.0

func (ws *WSClient) Subscribe(ctx context.Context, channelds ...exchange.Channel) error

Jump to

Keyboard shortcuts

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