gateio

package
v0.29.6 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2022 License: MIT Imports: 23 Imported by: 0

README

gate.io API 封装说明

此文档中,记录了gate接口的一些重要细节和封装后的使用注意事项。

V4版本API

V4版本分为

  • spot: 现货
  • margin: 杠杆
  • future: 永续合约
  • delivery: 交割合约
order.query

返回的数据如下:

{
  "id": 21953668381,
  "market": "SERO_USDT",
  "tif": 1,
  "user": 2931605,
  "ctime": 1608694438.202096,
  "mtime": 1608694438.202096,
  "price": "0.1062",
  "amount": "235.627",
  "iceberg": "0",
  "left": "235.627",
  "deal_fee_rebate": "0",
  "deal_point_fee": "0",
  "gt_discount": "1",
  "gt_taker_fee": "0.00045",
  "gt_maker_fee": "0.00015",
  "deal_gt_fee": "0",
  "orderType": 1,
  "type": 1,
  "dealFee": "0",
  "filledAmount": "0",
  "filledTotal": "0"
}

Documentation

Index

Constants

View Source
const (
	DefaultMaker = 0.002
	DefaultTaker = 0.002
)
View Source
const (
	// 订单类型("gtc":普通订单(默认);
	// “ioc”:立即执行否则取消订单(Immediate-Or-Cancel,IOC);
	// "poc":被动委托(只挂单,不吃单)(Pending-Or-Cancelled,POC))
	OrderTypeNormal = "gtc"
	OrderTypeGTC    = "gtc"
	OrderTypeIOC    = "ioc"
	OrderTypePOC    = "poc"
)

used by buy/sell

View Source
const (
	OrderStatusOpen      = "open"
	OrderStatusCancelled = "cancelled"
	OrderStatusClosed    = "closed"

	OrderTypeBuy  = "buy"
	OrderTypeSell = "sell"
)
View Source
const (
	WsIntervalSecond  = 5
	WsReconnectSecond = 60
)
View Source
const (
	DefaultHost = "gateio.life"

	WsPathV3 = "/v3"
	WsPathV4 = "/v4"
)
View Source
const (
	GET  = "GET"
	POST = "POST"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthenticationRequest

type AuthenticationRequest struct {
	Apikey    string `json:"apikey"`
	Signature string `json:"signature"`
	Nonce     int64  `json:"nonce"`
}

func (AuthenticationRequest) ToJson

func (ar AuthenticationRequest) ToJson() (string, error)

type Futures

type Futures struct {
	Key    string
	Secret string

	Logger *zap.SugaredLogger
	// contains filtered or unexported fields
}

func NewFutures

func NewFutures(key, secret, host string, logger *zap.SugaredLogger) *Futures

func (*Futures) AddDualMargin

func (f *Futures) AddDualMargin(ctx context.Context, settle, contract string, margin decimal.Decimal) ([]exchange.Position, error)

func (*Futures) AddMargin

func (f *Futures) AddMargin(ctx context.Context, settle, contract string, margin decimal.Decimal) (exchange.Position, error)

func (*Futures) Candle

func (f *Futures) Candle(ctx context.Context, settle string, contract string, from, to int64, limit int, interval time.Duration) (fym.Candle, error)

from, to is unix timestamp in seconds

func (*Futures) CommonLiquidation

func (f *Futures) CommonLiquidation(ctx context.Context, settle, contract string, from, to int64, limit int) ([]exchange.FuturesLiquidation, error)

func (*Futures) GetContract

func (f *Futures) GetContract(ctx context.Context, settle, contract string) (exchange.Contract, error)

func (*Futures) GetDualPosition

func (f *Futures) GetDualPosition(ctx context.Context, settle string, contract string) ([]exchange.Position, error)

func (*Futures) GetPosition

func (f *Futures) GetPosition(ctx context.Context, settle, contract string) (exchange.Position, error)

func (*Futures) ListContracts

func (f *Futures) ListContracts(ctx context.Context, settle string) ([]exchange.Contract, error)

func (*Futures) ListFuturesAccounts

func (f *Futures) ListFuturesAccounts(ctx context.Context, settle string) (exchange.FuturesBalance, error)

func (*Futures) ListPositions

func (f *Futures) ListPositions(ctx context.Context, settle string) ([]exchange.Position, error)

func (*Futures) ListTrades

func (f *Futures) ListTrades(ctx context.Context, settle string, contract string, limit int, from, to int64) ([]exchange.FuturesTrade, error)

func (*Futures) Orderbook

func (f *Futures) Orderbook(ctx context.Context, settle, contract string, limit int, interval float32) (exchange.FuturesOrderbook, error)

func (*Futures) SetDualMode

func (f *Futures) SetDualMode(ctx context.Context, settle string, newDualMode bool) (exchange.FuturesBalance, error)

设置持仓模式

func (*Futures) UpdateDualLeverage

func (f *Futures) UpdateDualLeverage(ctx context.Context, settle, contract string, newLeverage int) ([]exchange.Position, error)

更新双仓模式下的头寸杠杆

func (*Futures) UpdateDualRiskLimit

func (f *Futures) UpdateDualRiskLimit(ctx context.Context, settle, contract string, newRiskLimit int) ([]exchange.Position, error)

更新双仓模式下的头寸风险限额

func (*Futures) UpdateLeverage

func (f *Futures) UpdateLeverage(ctx context.Context, settle, contract string, newLeverage int) (exchange.Position, error)

更新头寸杠杆

func (*Futures) UpdateRiskLimit

func (f *Futures) UpdateRiskLimit(ctx context.Context, settle, contract string, newRiskLimit int) (exchange.Position, error)

更新头寸风险限额

type GateAuthentication

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

func (*GateAuthentication) Build

func (a *GateAuthentication) Build() (string, error)

func (*GateAuthentication) Init

func (a *GateAuthentication) Init(apiKey, secretKey string)

type GateIO

type GateIO struct {
	Key    string
	Secret string

	Logger *zap.SugaredLogger
	// contains filtered or unexported fields
}

gateio APIv4 版本的RESTful接口封装

func New

func New(key, secret, host string, logger *zap.SugaredLogger) *GateIO

func (*GateIO) AllSymbols

func (g *GateIO) AllSymbols(ctx context.Context) (symbols []exchange.Symbol, err error)

func (*GateIO) BuyFromOrderBook

func (g *GateIO) BuyFromOrderBook(symbol exchange.Symbol, clientOrderId string, total decimal.Decimal) (orderId uint64, err error)

BuyFromOrderBook use order book and take the sell1

func (*GateIO) BuyFromTicker

func (g *GateIO) BuyFromTicker(symbol exchange.Symbol, clientOrderId string, total decimal.Decimal) (orderId uint64, err error)

BuyFromTicker use Ticker's last price to place order. // may can't fill when big bull

func (*GateIO) BuyLimit

func (g *GateIO) BuyLimit(symbol, text string, price, amount decimal.Decimal) (orderId uint64, err error)

订单类型("gtc":普通订单(默认);“ioc”:立即执行否则取消订单(Immediate-Or-Cancel,IOC);"poc":被动委托(只挂单,不吃单)(Pending-Or-Cancelled,POC)) Place order buy

func (*GateIO) BuyMarket

func (g *GateIO) BuyMarket(symbol exchange.Symbol, clientOrderId string, total decimal.Decimal) (orderId uint64, err error)

BuyMarket use Ticker's last price to place order. may can't fill when big bull

func (*GateIO) BuyOrder

func (g *GateIO) BuyOrder(symbol string, price, amount decimal.Decimal, orderType, text string) (resp ResponseOrder, err error)

func (*GateIO) BuyStopLimit

func (g *GateIO) BuyStopLimit(symbol, clientOrderId string, price, amount, stopPrice decimal.Decimal) (orderId uint64, err error)

func (*GateIO) CancelAllOrders

func (g *GateIO) CancelAllOrders(types string, currencyPair string) (res ResponseCancel, err error)

Cancel all orders

func (*GateIO) CancelOrder

func (g *GateIO) CancelOrder(symbol string, orderNumber uint64) error

Cancel order

func (*GateIO) CandleBySize

func (g *GateIO) CandleBySize(symbol string, period time.Duration, size int) (candle fym.Candle, err error)

获取Candle

func (*GateIO) CandleFrom

func (g *GateIO) CandleFrom(symbol, clientId string, period time.Duration, from, to time.Time) (fym.Candle, error)

func (GateIO) FormatSymbol

func (g GateIO) FormatSymbol(base, quote string) string

func (*GateIO) GetCandle

func (g *GateIO) GetCandle(symbol string, groupSec, rangeHour int) (candles fym.Candle, err error)

获取Candle

func (*GateIO) GetFee

func (g *GateIO) GetFee(symbol string) (fee exchange.Fee, err error)

func (*GateIO) GetOrder

func (g *GateIO) GetOrder(orderId uint64, symbol string) (order exchange.Order, err error)

Get order status

func (*GateIO) GetOrderById

func (g *GateIO) GetOrderById(orderId uint64, symbol string) (order exchange.Order, err error)

func (*GateIO) GetOrderString

func (g *GateIO) GetOrderString(orderId uint64, symbol string) (string, error)

Get order as string, just for test gate's getOrder interface, only use in gateio_test.go

func (*GateIO) GetPairs

func (g *GateIO) GetPairs() (pairs []string, err error)

all support pairs

func (*GateIO) GetSymbol

func (g *GateIO) GetSymbol(ctx context.Context, symbol string) (s exchange.Symbol, err error)

func (*GateIO) IsFullFilled

func (g *GateIO) IsFullFilled(symbol string, orderId uint64) (order exchange.Order, filled bool, err error)

func (*GateIO) Last24hVolume

func (g *GateIO) Last24hVolume(symbol string) (decimal.Decimal, error)

func (*GateIO) LastPrice

func (g *GateIO) LastPrice(symbol string) (decimal.Decimal, error)

func (*GateIO) MarketInfo

func (g *GateIO) MarketInfo() (res ResponseMarketInfo, err error)

Market Info

func (*GateIO) MyTradeHistory

func (g *GateIO) MyTradeHistory(currencyPair string) (*MyTradeHistoryResult, error)

获取我的24小时内成交记录

func (*GateIO) OpenOrders

func (g *GateIO) OpenOrders() (res ResponseOpenOrders, err error)

Get my open order list

func (*GateIO) OrderBook

func (g *GateIO) OrderBook(symbol string) (ResponseOrderBook, error)

Depth of pair

func (*GateIO) ReqBalance

func (g *GateIO) ReqBalance(ctx context.Context, currencies []string)

func (*GateIO) ReqCandlestick

func (g *GateIO) ReqCandlestick(ctx context.Context, symbol, clientId string, period time.Duration, from, to time.Time) (fym.Candle, error)

func (*GateIO) ReqOrder

func (g *GateIO) ReqOrder(ctx context.Context, symbol, clientId string) (orders []exchange.Order, err error)

func (*GateIO) ReqPing

func (g *GateIO) ReqPing(ctx context.Context, id int64) (string, error)

always call ReqPing use context context with a timeout

func (*GateIO) ReqTicker

func (g *GateIO) ReqTicker(ctx context.Context, id int64, symbol string, period time.Duration) (fym.Ticker, error)

func (*GateIO) ReqTime

func (g *GateIO) ReqTime(ctx context.Context, id int64) (int64, error)

func (*GateIO) SellFromOrderBook

func (g *GateIO) SellFromOrderBook(symbol exchange.Symbol, clientOrderId string, amount decimal.Decimal) (orderId uint64, err error)

SellFromOrderBook use order book and take the buy1

func (*GateIO) SellFromTicker

func (g *GateIO) SellFromTicker(symbol exchange.Symbol, clientOrderId string, amount decimal.Decimal) (orderId uint64, err error)

SellFromTicker use Ticker's last price to place order. may can't fill when big bear

func (*GateIO) SellLimit

func (g *GateIO) SellLimit(symbol, text string, price, amount decimal.Decimal) (orderId uint64, err error)

Place order sell

func (*GateIO) SellMarket

func (g *GateIO) SellMarket(symbol exchange.Symbol, clientOrderId string, amount decimal.Decimal) (orderId uint64, err error)

SellMarket use Ticker's last price to place order. may can't fill when big bear

func (*GateIO) SellStopLimit

func (g *GateIO) SellStopLimit(symbol, clientOrderId string, price, amount, stopPrice decimal.Decimal) (orderId uint64, err error)

func (*GateIO) SpotAvailableBalance

func (g *GateIO) SpotAvailableBalance() (map[string]decimal.Decimal, error)

Get account fund balances

func (*GateIO) SpotBalance

func (g *GateIO) SpotBalance() (map[string]decimal.Decimal, error)

Get account fund balances

func (*GateIO) SubBalance

func (g *GateIO) SubBalance(currencies []string)

func (*GateIO) SubCandlestick

func (g *GateIO) SubCandlestick(symbol, clientId string, period time.Duration,
	responseHandler exchange.ResponseHandler)

func (*GateIO) SubOrder

func (g *GateIO) SubOrder(symbol, clientId string, responseHandler exchange.ResponseHandler)

func (*GateIO) SubTicker

func (g *GateIO) SubTicker(id int64, symbol string, responseHandler exchange.ResponseHandler)

func (*GateIO) SubscribeCandlestick

func (g *GateIO) SubscribeCandlestick(symbol, clientId string, period time.Duration, responseHandler exchange.ResponseHandler)

func (*GateIO) SubscribeCandlestickWithReq

func (g *GateIO) SubscribeCandlestickWithReq(symbol, clientId string, period time.Duration, responseHandler exchange.ResponseHandler)

func (*GateIO) SubscribeOrder

func (g *GateIO) SubscribeOrder(symbol, clientId string, responseHandler exchange.ResponseHandler)

func (*GateIO) Ticker

func (g *GateIO) Ticker(currencyPair string) (*exchange.Ticker, error)

// Market Details

func (g *GateIO) marketlist() string {
	var method string = "GET"
	url := "/marketlist"
	param := ""
	var ret string = g.httpDo(method, url, param)
	return ret
}

// tickers

func (g *GateIO) tickers() string {
	var method string = "GET"
	url := "/tickers"
	param := ""
	var ret string = g.httpDo(method, url, param)
	return ret
}

ticker

func (*GateIO) TradeHistory

func (g *GateIO) TradeHistory(params string) (string, error)

Trade History

func (*GateIO) UnsubBalance

func (g *GateIO) UnsubBalance(currencies []string)

func (*GateIO) UnsubCandlestick

func (g *GateIO) UnsubCandlestick(symbol, clientId string)

func (*GateIO) UnsubOrder

func (g *GateIO) UnsubOrder(symbol, clientId string)

func (*GateIO) UnsubTicker

func (g *GateIO) UnsubTicker(id int64, symbol string)

func (*GateIO) UnsubscribeCandlestick

func (g *GateIO) UnsubscribeCandlestick(symbol, clientId string, period time.Duration)

func (*GateIO) UnsubscribeCandlestickWithReq

func (g *GateIO) UnsubscribeCandlestickWithReq(symbol, clientId string, period time.Duration)

func (*GateIO) UnsubscribeOrder

func (g *GateIO) UnsubscribeOrder(symbol, clientId string)

type MyTradeHistoryResult

type MyTradeHistoryResult struct {
	Result  string     `json:"result"`
	Message string     `json:"message"`
	Code    int        `json:"code"`
	Trades  []RawTrade `json:"trades"`
}

type PrivateWebsocketClient

type PrivateWebsocketClient struct {
	base.WebsocketBase
	// contains filtered or unexported fields
}

func (*PrivateWebsocketClient) Init

func (c *PrivateWebsocketClient) Init(host, path string, apiKey, secretKey string, logger *zap.SugaredLogger) *PrivateWebsocketClient

Initializer

func (*PrivateWebsocketClient) ReqBalance

func (c *PrivateWebsocketClient) ReqBalance(id int64, assets []string)

func (*PrivateWebsocketClient) ReqBalanceHandler

func (c *PrivateWebsocketClient) ReqBalanceHandler(handler base.ResponseHandler) base.ResponseHandler

ReqBalanceHandler cast the raw result to gate order object list

func (*PrivateWebsocketClient) ReqOrder

func (c *PrivateWebsocketClient) ReqOrder(id int64, symbol string, offset, limit uint64)

func (*PrivateWebsocketClient) ReqOrderHandler

func (c *PrivateWebsocketClient) ReqOrderHandler(handler base.ResponseHandler) base.ResponseHandler

ReqOrderHandler cast the raw result to gate order object list

func (*PrivateWebsocketClient) SetHandler

func (c *PrivateWebsocketClient) SetHandler(
	connectedHandler base.ConnectedHandler,
	responseHandler base.ResponseHandler)

Set callback handler

func (*PrivateWebsocketClient) SubBalance

func (c *PrivateWebsocketClient) SubBalance(id int64, assets []string)

func (*PrivateWebsocketClient) SubBalanceHandler

func (c *PrivateWebsocketClient) SubBalanceHandler(handler exchange.ResponseHandler) base.ResponseHandler

func (*PrivateWebsocketClient) SubOrder

func (c *PrivateWebsocketClient) SubOrder(id int64, symbols []string)

func (*PrivateWebsocketClient) SubOrderHandler

client handler got a exchange.Order as response if everything's ok

func (*PrivateWebsocketClient) UnsubBalance

func (c *PrivateWebsocketClient) UnsubBalance(id int64, assets []string)

func (*PrivateWebsocketClient) UnsubOrder

func (c *PrivateWebsocketClient) UnsubOrder(id int64, symbols []string)

type Quote

type Quote = exchange.Quote

price, amount

type RawCandle

type RawCandle [6]float64

type RawOrderInGetOrder

type RawOrderInGetOrder struct {
	OrderNumber  string
	Text         string
	Status       string // 订单状态 open已挂单 cancelled已取消 closed已完成
	CurrencyPair string `json:"currencyPair"`
	Type         string // sell, buy

	Rate          string // 价格
	Amount        string // 买卖数量
	InitialRate   string // 下单价格
	InitialAmount string // 下单数量
	//FilledRate    interface{} // string when open, float64 when closed
	FilledAmount string

	FeePercentage float64
	FeeValue      string
	FeeCurrency   string
	Fee           string

	Timestamp int64
}

type RawOrderInOpenOrders

type RawOrderInOpenOrders struct {
	OrderNumber   uint64
	Status        string // 记录状态 DONE:完成; CANCEL:取消; REQUEST:请求中
	CurrencyPair  string
	Type          string
	Rate          string // 价格
	Amount        string // 买卖数量
	Total         string
	InitialRate   string // 下单价格
	InitialAmount string // 下单数量
	FilledRate    string // 成交价格
	FilledAmount  string // 成交数量
	Timestamp     int64
}

type RawSymbol

type RawSymbol struct {
	PricePrecision  int32   `json:"decimal_places"`
	AmountPrecision int32   `json:"amount_decimal_places"`
	MinAmount       float64 `json:"min_amount"`
	MinAmountA      float64 `json:"min_amount_a"`
	MinAmountB      float64 `json:"min_amount_b"`
	Fee             float64 `json:"fee"`
	TradeDisabled   int     `json:"trade_disabled"`
	BuyDisabled     int     `json:"buy_disabled"`
	SellDisabled    int     `json:"sell_disabled"`
}

type RawTrade

type RawTrade struct {
	TradeId     uint64  `json:"tradeID"`
	OrderNumber uint64  `json:"orderNumber"`
	Pair        string  `json:"pair"`
	Type        string  `json:"type"`
	Rate        string  `json:"rate"`
	Amount      string  `json:"amount"`
	Total       float64 `json:"total"`
	Date        string  `json:"date"`
	TimeUnix    int64   `json:"time_unix"`
	Role        string  `json:"role"`
	Fee         string  `json:"fee"`
	FeeCoin     string  `json:"fee_coin"`
	GtFee       string  `json:"gt_fee"`
	PointFee    string  `json:"point_fee"`
}

from api result

type ResponseBalances

type ResponseBalances struct {
	Result    string `json:"result"`
	Available map[string]string
	Locked    map[string]string
}

type ResponseBuy

type ResponseBuy struct {
	Result  string
	Message string
	Code    int

	OrderNumber uint64
	Market      string // 交易对

	CTime   float64 `json:"ctime"` // 时间戳: 1585793595.5014, 秒.毫秒
	Side    int
	Iceberg string

	Rate         string // 下单价格
	FilledRate   string // 成交价格
	LeftAmount   string // 剩余数量
	FilledAmount string // 成交数量

	FeePercentage float64
	FeeValue      string
	FeeCurrency   string
	Fee           string
}

type ResponseCancel

type ResponseCancel struct {
	Result  bool
	Code    int
	Message string
}

type ResponseCandles

type ResponseCandles struct {
	Result  string // true
	Elapsed string
	Data    []RawCandle
}

type ResponseGetOrder

type ResponseGetOrder struct {
	Result  string
	Message string
	Code    int
	Elapsed string
	Order   RawOrderInGetOrder
}

type ResponseMarketInfo

type ResponseMarketInfo struct {
	Result string
	Pairs  []map[string]RawSymbol
}

type ResponseOpenOrders

type ResponseOpenOrders struct {
	Result  string
	Message string
	Code    int64
	Elapsed string
	Orders  []RawOrderInOpenOrders
}

type ResponseOrder

type ResponseOrder struct {
	Result       string
	OrderNumber  uint64
	Rate         string
	LeftAmount   string // 剩余数量
	FilledAmount string // 成交数量
	FilledRate   string // 成交价格
	Text         string // 用户自定义订单标识,必须以固定前缀 "t-"开头,不计算前缀的情况下,长度限制为 16 字节,范围 [0-9a-zA-Z-_.]。
	Message      string
}

type ResponseOrderBook

type ResponseOrderBook struct {
	Result string
	Asks   []Quote // sell
	Bids   []Quote // buy
}

type ResponseReqOrder

type ResponseReqOrder struct {
	Offset int64 `json:"offset"`
	Limit  int64 `json:"limit"`
	// Total 是全部的订单个数,而不是当前批次取到多少
	Total   int64           `json:"total"`
	Records []WsOrderRecord `json:"records"`
}

ResponseReqOrder 是order.query请求返回的主结构

type ResponseSell

type ResponseSell ResponseOrder

type ResponseTicker

type ResponseTicker struct {
	Result        string // true
	Elapsed       string
	Last          string // 最新成交价
	LowestAsk     string // 卖1,卖方最低价
	HighestBid    string // 买1,买方最高价
	PercentChange string //涨跌百分比
	BaseVolume    string //交易量
	QuoteVolume   string // 兑换货币交易量
	High24hr      string // 24小时最高价
	Low24hr       string // 24小时最低价
}

type ResponseWsBase

type ResponseWsBase struct {
	Id     int64       `json:"id"`
	Error  interface{} `json:"error"`
	Result interface{} `json:"result"`
}

type ResponseWsKline

type ResponseWsKline struct {
	Time   int64  `json:"time"`
	Open   string `json:"open"`
	High   string `json:"highest"`
	Low    string `json:"lowest"`
	Close  string `json:"close"`
	Volume string `json:"volume"`
	Amount string `json:"amount"`
	Symbol string `json:"market_name"`
}

type ResponseWsTicker

type ResponseWsTicker struct {
	Period      int64  `json:"period"`
	Open        string `json:"open"`
	High        string `json:"high"`
	Low         string `json:"low"`
	Close       string `json:"close"`
	Last        string `json:"last"`
	Change      string `json:"change"`
	QuoteVolume string `json:"quoteVolume"`
	BaseVolume  string `json:"baseVolume"`
}

type SpotV4

type SpotV4 struct {
	Key    string
	Secret string

	Logger *zap.SugaredLogger
	// contains filtered or unexported fields
}

SpotV4 is gate.io API v4 wrapper GetXxx/Xxx: RESTful GET ReqXxx: websocket query SubXxx/UnsubXxx: websocket subscribe or unsubscribe

func NewSpotV4

func NewSpotV4(key, secret, host string, logger *zap.SugaredLogger) *SpotV4

func (*SpotV4) AllSymbols

func (g *SpotV4) AllSymbols(ctx context.Context) (symbols []exchange.Symbol, err error)

func (*SpotV4) AvailableBalance

func (g *SpotV4) AvailableBalance(ctx context.Context) (map[string]decimal.Decimal, error)

AvailableBalance returns account available balances

func (*SpotV4) Balance

func (g *SpotV4) Balance(ctx context.Context) ([]exchange.Balance, error)

Balance returns account balances

func (*SpotV4) BuyLimit

func (g *SpotV4) BuyLimit(ctx context.Context, symbol, clientOrderId string, price, amount decimal.Decimal) (exchange.Order, error)

订单类型("gtc":普通订单(默认);“ioc”:立即执行否则取消订单(Immediate-Or-Cancel,IOC);"poc":被动委托(只挂单,不吃单)(Pending-Or-Cancelled,POC))

func (*SpotV4) BuyMarket

func (g *SpotV4) BuyMarket(ctx context.Context, symbol exchange.Symbol, clientOrderId string, total decimal.Decimal) (exchange.Order, error)

BuyMarket use Ticker's last price to place order. may can't fill when big bull

func (*SpotV4) BuyStopLimit

func (g *SpotV4) BuyStopLimit(symbol, clientOrderId string, price, amount, stopPrice decimal.Decimal) (orderId uint64, err error)

func (*SpotV4) CancelAllOrders

func (g *SpotV4) CancelAllOrders(ctx context.Context, symbol string) ([]exchange.Order, error)

cancel all orders

func (*SpotV4) CancelOrder

func (g *SpotV4) CancelOrder(ctx context.Context, symbol string, orderId uint64) (exchange.Order, error)

Cancel order

func (*SpotV4) CandleBySize

func (g *SpotV4) CandleBySize(symbol string, period time.Duration, size int) (fym.Candle, error)

获取一定数量的k线 可以用于策略启动时的查询

func (*SpotV4) CandleBySizeContext

func (g *SpotV4) CandleBySizeContext(ctx context.Context, symbol string, period time.Duration, size int) (fym.Candle, error)

func (*SpotV4) Currencies

func (g *SpotV4) Currencies(ctx context.Context) ([]gateapi.Currency, error)

list all currencies

func (*SpotV4) GetOrder

func (g *SpotV4) GetOrder(ctx context.Context, symbol string, orderId uint64) (exchange.Order, error)

func (*SpotV4) GetSymbol

func (g *SpotV4) GetSymbol(ctx context.Context, symbol string) (s exchange.Symbol, err error)

func (*SpotV4) IsFullFilled

func (g *SpotV4) IsFullFilled(ctx context.Context, symbol string, orderId uint64) (order exchange.Order, filled bool, err error)

func (*SpotV4) Last24hVolume

func (g *SpotV4) Last24hVolume(ctx context.Context, symbol string) (decimal.Decimal, error)

func (*SpotV4) LastPrice

func (g *SpotV4) LastPrice(ctx context.Context, symbol string) (decimal.Decimal, error)

func (*SpotV4) ListOpenOrders

func (g *SpotV4) ListOpenOrders(ctx context.Context, symbol string) ([]exchange.Order, error)

list open orders by symbol

func (*SpotV4) ListOrders

func (g *SpotV4) ListOrders(ctx context.Context, symbol, status string) ([]exchange.Order, error)

list all orders by status (open, finished)

func (*SpotV4) MyTrades

func (g *SpotV4) MyTrades(ctx context.Context, symbol, orderId string) ([]exchange.Trade, error)

my trades history

func (*SpotV4) Name

func (g *SpotV4) Name() string

func (*SpotV4) ReqBalance

func (g *SpotV4) ReqBalance(ctx context.Context, currencies []string)

func (*SpotV4) ReqCandlestick

func (g *SpotV4) ReqCandlestick(ctx context.Context, symbol, clientId string, period time.Duration, from, to time.Time) (fym.Candle, error)

func (*SpotV4) ReqOrder

func (g *SpotV4) ReqOrder(ctx context.Context, symbol, clientId string) (orders []exchange.Order, err error)

func (*SpotV4) ReqPing

func (g *SpotV4) ReqPing(ctx context.Context, id int64) (string, error)

always call ReqPing use context context with a timeout

func (*SpotV4) ReqTicker

func (g *SpotV4) ReqTicker(ctx context.Context, id int64, symbol string, period time.Duration) (fym.Ticker, error)

func (*SpotV4) ReqTime

func (g *SpotV4) ReqTime(ctx context.Context, id int64) (int64, error)

func (*SpotV4) SellLimit

func (g *SpotV4) SellLimit(ctx context.Context, symbol, text string, price, amount decimal.Decimal) (exchange.Order, error)

Place order sell

func (*SpotV4) SellMarket

func (g *SpotV4) SellMarket(ctx context.Context, symbol exchange.Symbol, clientOrderId string, amount decimal.Decimal) (exchange.Order, error)

SellMarket use Ticker's last price to place order. may can't fill when big bear

func (*SpotV4) SellStopLimit

func (g *SpotV4) SellStopLimit(symbol, clientOrderId string, price, amount, stopPrice decimal.Decimal) (orderId uint64, err error)

func (*SpotV4) SubBalance

func (g *SpotV4) SubBalance(currencies []string)

func (*SpotV4) SubCandlestick

func (g *SpotV4) SubCandlestick(symbol, clientId string, period time.Duration,
	responseHandler exchange.ResponseHandler)

func (*SpotV4) SubOrder

func (g *SpotV4) SubOrder(ctx context.Context, symbol, clientId string, responseHandler exchange.ResponseHandler)

TODO: 应该改造为使用context,当context取消时,自动退出订阅

func (*SpotV4) SubTicker

func (g *SpotV4) SubTicker(id int64, symbol string, responseHandler exchange.ResponseHandler)

func (*SpotV4) SubscribeCandlestick

func (g *SpotV4) SubscribeCandlestick(symbol, clientId string, period time.Duration, responseHandler exchange.ResponseHandler)

func (*SpotV4) SubscribeCandlestickWithReq

func (g *SpotV4) SubscribeCandlestickWithReq(symbol, clientId string, period time.Duration, responseHandler exchange.ResponseHandler)

func (*SpotV4) SubscribeOrder

func (g *SpotV4) SubscribeOrder(ctx context.Context, symbol, clientId string, responseHandler exchange.ResponseHandler)

func (*SpotV4) Ticker

func (g *SpotV4) Ticker(ctx context.Context, symbol string) (exchange.Ticker, error)

ticker

func (*SpotV4) Tickers

func (g *SpotV4) Tickers(ctx context.Context) ([]exchange.Ticker, error)

tickers

func (*SpotV4) UnsubBalance

func (g *SpotV4) UnsubBalance(currencies []string)

func (*SpotV4) UnsubCandlestick

func (g *SpotV4) UnsubCandlestick(symbol, clientId string)

func (*SpotV4) UnsubTicker

func (g *SpotV4) UnsubTicker(id int64, symbol string)

func (*SpotV4) UnsubscribeCandlestick

func (g *SpotV4) UnsubscribeCandlestick(symbol, clientId string, period time.Duration)

func (*SpotV4) UnsubscribeCandlestickWithReq

func (g *SpotV4) UnsubscribeCandlestickWithReq(symbol, clientId string, period time.Duration)

type UpdateWsBase

type UpdateWsBase struct {
	Id     int64       `json:"id"`
	Method string      `json:"method"`
	Params interface{} `json:"params"`
}

type V2

type V2 struct {
	Key    string
	Secret string

	Logger *zap.SugaredLogger
	// contains filtered or unexported fields
}

func NewV2

func NewV2(key, secret, host string, logger *zap.SugaredLogger) *V2

func (*V2) AllSymbols

func (g *V2) AllSymbols(ctx context.Context) (symbols []exchange.Symbol, err error)

func (*V2) BuyLimit

func (g *V2) BuyLimit(symbol, text string, price, amount decimal.Decimal) (orderId uint64, err error)

订单类型("gtc":普通订单(默认);“ioc”:立即执行否则取消订单(Immediate-Or-Cancel,IOC);"poc":被动委托(只挂单,不吃单)(Pending-Or-Cancelled,POC)) Place order buy

func (*V2) BuyMarket

func (g *V2) BuyMarket(symbol exchange.Symbol, clientOrderId string, total decimal.Decimal) (orderId uint64, err error)

func (*V2) BuyOrder

func (g *V2) BuyOrder(symbol string, price, amount decimal.Decimal, orderType, text string) (resp ResponseOrder, err error)

func (*V2) BuyStopLimit

func (g *V2) BuyStopLimit(symbol, clientOrderId string, price, amount, stopPrice decimal.Decimal) (orderId uint64, err error)

func (*V2) CancelAllOrders

func (g *V2) CancelAllOrders(types string, currencyPair string) (res ResponseCancel, err error)

Cancel all orders

func (*V2) CancelOrder

func (g *V2) CancelOrder(symbol string, orderNumber uint64) error

Cancel order

func (*V2) CandleBySize

func (g *V2) CandleBySize(symbol string, period time.Duration, size int) (candle fym.Candle, err error)

获取Candle

func (*V2) CandleFrom

func (g *V2) CandleFrom(symbol, clientId string, period time.Duration, from, to time.Time) (fym.Candle, error)

func (*V2) GetCandle

func (g *V2) GetCandle(symbol string, groupSec, rangeHour int) (candles fym.Candle, err error)

获取Candle

func (*V2) GetFee

func (g *V2) GetFee(symbol string) (fee exchange.Fee, err error)

func (*V2) GetOrder

func (g *V2) GetOrder(orderId uint64, symbol string) (order exchange.Order, err error)

Get order status

func (*V2) GetOrderById

func (g *V2) GetOrderById(orderId uint64, symbol string) (order exchange.Order, err error)

func (*V2) GetOrderString

func (g *V2) GetOrderString(orderId uint64, symbol string) (string, error)

Get order as string, just for test gate's getOrder interface, only use in gateio_test.go

func (*V2) GetPairs

func (g *V2) GetPairs() (pairs []string, err error)

all support pairs

func (*V2) GetSymbol

func (g *V2) GetSymbol(ctx context.Context, symbol string) (s exchange.Symbol, err error)

func (*V2) IsFullFilled

func (g *V2) IsFullFilled(symbol string, orderId uint64) (order exchange.Order, filled bool, err error)

func (*V2) Last24hVolume

func (g *V2) Last24hVolume(symbol string) (decimal.Decimal, error)

func (*V2) LastPrice

func (g *V2) LastPrice(symbol string) (decimal.Decimal, error)

func (*V2) MarketInfo

func (g *V2) MarketInfo() (res ResponseMarketInfo, err error)

Market Info

func (*V2) MyTradeHistory

func (g *V2) MyTradeHistory(symbol string, orderId uint64) ([]exchange.Trade, error)

获取我的24小时内成交记录

func (*V2) OpenOrders

func (g *V2) OpenOrders() ([]exchange.Order, error)

Get my open order list

func (*V2) OrderBook

func (g *V2) OrderBook(symbol string) (ResponseOrderBook, error)

Depth of pair

func (*V2) ReqBalance

func (g *V2) ReqBalance(ctx context.Context, currencies []string)

func (*V2) ReqCandlestick

func (g *V2) ReqCandlestick(ctx context.Context, symbol, clientId string, period time.Duration, from, to time.Time) (fym.Candle, error)

func (*V2) ReqOrder

func (g *V2) ReqOrder(ctx context.Context, symbol, clientId string) (orders []exchange.Order, err error)

func (*V2) ReqPing

func (g *V2) ReqPing(ctx context.Context, id int64) (string, error)

always call ReqPing use context context with a timeout

func (*V2) ReqTicker

func (g *V2) ReqTicker(ctx context.Context, id int64, symbol string, period time.Duration) (fym.Ticker, error)

func (*V2) ReqTime

func (g *V2) ReqTime(ctx context.Context, id int64) (int64, error)

func (*V2) SellLimit

func (g *V2) SellLimit(symbol, text string, price, amount decimal.Decimal) (orderId uint64, err error)

Place order sell

func (*V2) SellMarket

func (g *V2) SellMarket(symbol exchange.Symbol, clientOrderId string, amount decimal.Decimal) (orderId uint64, err error)

func (*V2) SellStopLimit

func (g *V2) SellStopLimit(symbol, clientOrderId string, price, amount, stopPrice decimal.Decimal) (orderId uint64, err error)

func (*V2) SpotAvailableBalance

func (g *V2) SpotAvailableBalance() (map[string]decimal.Decimal, error)

Get account fund balances

func (*V2) SpotBalance

func (g *V2) SpotBalance() (map[string]decimal.Decimal, error)

Get account fund balances

func (*V2) SpotBalanceDetail

func (g *V2) SpotBalanceDetail() (map[string]exchange.Balance, error)

Get spot balances in details

func (*V2) SubBalance

func (g *V2) SubBalance(currencies []string)

func (*V2) SubCandlestick

func (g *V2) SubCandlestick(symbol, clientId string, period time.Duration,
	responseHandler exchange.ResponseHandler)

func (*V2) SubOrder

func (g *V2) SubOrder(symbol, clientId string, responseHandler exchange.ResponseHandler)

func (*V2) SubTicker

func (g *V2) SubTicker(id int64, symbol string, responseHandler exchange.ResponseHandler)

func (*V2) Ticker

func (g *V2) Ticker(currencyPair string) (*exchange.Ticker, error)

// Market Details

func (g *V2) marketlist() string {
	var method string = "GET"
	url := "/marketlist"
	param := ""
	var ret string = g.httpDo(method, url, param)
	return ret
}

// tickers

func (g *V2) tickers() string {
	var method string = "GET"
	url := "/tickers"
	param := ""
	var ret string = g.httpDo(method, url, param)
	return ret
}

ticker

func (*V2) TradeHistory

func (g *V2) TradeHistory(params string) (string, error)

Trade History

func (*V2) UnsubBalance

func (g *V2) UnsubBalance(currencies []string)

func (*V2) UnsubCandlestick

func (g *V2) UnsubCandlestick(symbol, clientId string)

func (*V2) UnsubOrder

func (g *V2) UnsubOrder(symbol, clientId string)

func (*V2) UnsubTicker

func (g *V2) UnsubTicker(id int64, symbol string)

type WebsocketClient

type WebsocketClient struct {
	base.WebsocketBase
	// contains filtered or unexported fields
}

func (*WebsocketClient) Auth

func (c *WebsocketClient) Auth(api, secret string)

func (*WebsocketClient) AuthHandler

func (c *WebsocketClient) AuthHandler(handler base.ResponseHandler) base.ResponseHandler

func (*WebsocketClient) Init

func (c *WebsocketClient) Init(host, path string, logger *zap.SugaredLogger) *WebsocketClient

Initializer

func (*WebsocketClient) Ping

func (c *WebsocketClient) Ping(id int64)

func (*WebsocketClient) PingHandler

func (c *WebsocketClient) PingHandler(handler base.ResponseHandler) base.ResponseHandler

func (*WebsocketClient) ReqCandle

func (c *WebsocketClient) ReqCandle(id int64, symbol string, start, end, interval int64)

start, end, interval unit is second

func (*WebsocketClient) ReqCandleHandler

func (c *WebsocketClient) ReqCandleHandler(handler base.ResponseHandler) base.ResponseHandler

func (*WebsocketClient) ReqTicker

func (c *WebsocketClient) ReqTicker(id int64, symbol string, period int64)

func (*WebsocketClient) ReqTickerHandler

func (c *WebsocketClient) ReqTickerHandler(handler base.ResponseHandler) base.ResponseHandler

func (*WebsocketClient) SetHandler

func (c *WebsocketClient) SetHandler(
	connectedHandler base.ConnectedHandler,
	responseHandler base.ResponseHandler)

Set callback handler

func (*WebsocketClient) SubCandle

func (c *WebsocketClient) SubCandle(id int64, symbol string, interval int64)

func (*WebsocketClient) SubCandleHandler

func (c *WebsocketClient) SubCandleHandler(handler exchange.ResponseHandler) base.ResponseHandler

func (*WebsocketClient) SubTicker

func (c *WebsocketClient) SubTicker(id int64, symbol string)

func (*WebsocketClient) SubTickerHandler

func (c *WebsocketClient) SubTickerHandler(handler exchange.ResponseHandler) base.ResponseHandler

func (*WebsocketClient) Time

func (c *WebsocketClient) Time(id int64)

func (*WebsocketClient) TimeHandler

func (c *WebsocketClient) TimeHandler(handler base.ResponseHandler) base.ResponseHandler

func (*WebsocketClient) UnsubCandle

func (c *WebsocketClient) UnsubCandle(id int64)

func (*WebsocketClient) UnsubTicker

func (c *WebsocketClient) UnsubTicker(id int64)

type WebsocketRequest

type WebsocketRequest struct {
	Id     int64         `json:"id"`
	Method string        `json:"method"`
	Params []interface{} `json:"params"`
}

func (WebsocketRequest) String

func (r WebsocketRequest) String() string

type WsOrderRecord

type WsOrderRecord struct {
	Id           uint64  `json:"id"`
	Market       string  `json:"market"`
	User         int64   `json:"user"`
	CTime        float64 `json:"ctime"`
	FTime        float64 `json:"ftime"`
	Price        string  `json:"price"`
	Amount       string  `json:"amount"`
	Left         string  `json:"left"`
	DealFee      string  `json:"dealFee"`
	OrderType    int     `json:"orderType"`
	Type         int     `json:"type"`
	FilledAmount string  `json:"filledAmount"`
	FilledTotal  string  `json:"filledTotal"`
	// 文档中有,但实际上却没有该字段
	Text string `json:"text"`

	// 以下字段不在文档中,是调试时看到的字段
	Tif           int64   `json:"tif"`
	MTime         float64 `json:"mtime"`
	Iceberg       string  `json:"iceberg"` // 冰山
	DealFeeRebate string  `json:"deal_fee_rebate"`
	DealPointFee  string  `json:"deal_point_fee"`
	GtDiscount    string  `json:"gt_discount"`
	GtMakerFee    string  `json:"gt_maker_fee"`
	GtTakerFee    string  `json:"gt_taker_fee"`
	DealGtFee     string  `json:"deal_gt_fee"`
}

WsOrderRecord 在order.query和order.update都相同,可以通用 差别是order.update里不含text

Jump to

Keyboard shortcuts

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