1 Star 0 Fork 0

hacker61/go-binance

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
depth_service.go 1.74 KB
一键复制 编辑 原始数据 按行查看 历史
luyao 提交于 2021-07-18 00:06 +08:00 . 地址修改为gitee.com/hacker61
package futures
import (
"context"
"gitee.com/hacker61/go-binance/v2/common"
)
// DepthService show depth info
type DepthService struct {
c *Client
symbol string
limit *int
}
// Symbol set symbol
func (s *DepthService) Symbol(symbol string) *DepthService {
s.symbol = symbol
return s
}
// Limit set limit
func (s *DepthService) Limit(limit int) *DepthService {
s.limit = &limit
return s
}
// Do send request
func (s *DepthService) Do(ctx context.Context, opts ...RequestOption) (res *DepthResponse, err error) {
r := &request{
method: "GET",
endpoint: "/fapi/v1/depth",
}
r.setParam("symbol", s.symbol)
if s.limit != nil {
r.setParam("limit", *s.limit)
}
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
j, err := newJSON(data)
if err != nil {
return nil, err
}
res = new(DepthResponse)
res.LastUpdateID = j.Get("lastUpdateId").MustInt64()
bidsLen := len(j.Get("bids").MustArray())
res.Bids = make([]Bid, bidsLen)
for i := 0; i < bidsLen; i++ {
item := j.Get("bids").GetIndex(i)
res.Bids[i] = Bid{
Price: item.GetIndex(0).MustString(),
Quantity: item.GetIndex(1).MustString(),
}
}
asksLen := len(j.Get("asks").MustArray())
res.Asks = make([]Ask, asksLen)
for i := 0; i < asksLen; i++ {
item := j.Get("asks").GetIndex(i)
res.Asks[i] = Ask{
Price: item.GetIndex(0).MustString(),
Quantity: item.GetIndex(1).MustString(),
}
}
return res, nil
}
// DepthResponse define depth info with bids and asks
type DepthResponse struct {
LastUpdateID int64 `json:"lastUpdateId"`
Bids []Bid `json:"bids"`
Asks []Ask `json:"asks"`
}
// Ask is a type alias for PriceLevel.
type Ask = common.PriceLevel
// Bid is a type alias for PriceLevel.
type Bid = common.PriceLevel
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/hacker61/go-binance.git
git@gitee.com:hacker61/go-binance.git
hacker61
go-binance
go-binance
v2.2.10

搜索帮助