From 0aa5c89b4ea98f52d09c64f0efe6823a9bf8c1fa Mon Sep 17 00:00:00 2001 From: dwd Date: Wed, 18 Sep 2024 20:56:27 +0800 Subject: [PATCH] add func: bnc.QuerySpotTrades bnc.QuerySpotAggTrades --- bnc/config_pub.go | 60 +++++++++++++++++++++++++++++++++++++++++++++++ bnc/public.go | 16 +++++++++++++ 2 files changed, 76 insertions(+) diff --git a/bnc/config_pub.go b/bnc/config_pub.go index ff51545..ad58206 100644 --- a/bnc/config_pub.go +++ b/bnc/config_pub.go @@ -396,3 +396,63 @@ var CMPremiumIndexConfig = cex.ReqConfig[CMPremiumIndexParams, []CMPremiumIndex] HTTPStatusCodeChecker: HTTPStatusCodeChecker, RespBodyUnmarshaler: fuBodyUnmshWrapper(cex.StdBodyUnmarshaler[[]CMPremiumIndex]), } + +type SpotTrade struct { + Id int64 `json:"id"` + Price float64 `json:"price,string"` + Qty float64 `json:"qty,string"` + QuoteQty float64 `json:"quoteQty,string"` + Time int64 `json:"time,string"` + IsBuyerMaker bool `json:"isBuyerMaker"` + IsBestMatch bool `json:"isBestMatch"` +} + +type SpotTradesParams struct { + Symbol string `s2m:"symbol,omitempty"` + Limit int `s2m:"limit,omitempty"` // default 500; max 1000 +} + +var SpotTradesConfig = cex.ReqConfig[SpotTradesParams, []SpotTrade]{ + ReqBaseConfig: cex.ReqBaseConfig{ + BaseUrl: ApiBaseUrl, + Path: ApiV3 + "/trades", + Method: http.MethodGet, + IsUserData: false, + UserTimeInterval: 0, + IpTimeInterval: 0, + }, + HTTPStatusCodeChecker: HTTPStatusCodeChecker, + RespBodyUnmarshaler: spotBodyUnmshWrapper(cex.StdBodyUnmarshaler[[]SpotTrade]), +} + +type SpotAggTrades struct { + Id int64 `json:"a"` + Price float64 `json:"p,string"` + Qty float64 `json:"q,string"` + FirstTradeId int64 `json:"f,string"` + LastTradeId int64 `json:"l,string"` + Time int64 `json:"T"` + IsBuyerMaker bool `json:"m"` + IsBestMatch bool `json:"M"` +} + +type SpotAggTradesParams struct { + Symbol string `s2m:"symbol,omitempty"` + FromId int64 `s2m:"fromId,omitempty"` + StartTime int64 `s2m:"startTime,omitempty"` + EndTime int64 `s2m:"endTime,omitempty"` + Limit int `s2m:"limit,omitempty"` // default 500; max 1000 +} + +var SpotAggTradesConfig = cex.ReqConfig[SpotAggTradesParams, []SpotAggTrades]{ + ReqBaseConfig: cex.ReqBaseConfig{ + BaseUrl: ApiBaseUrl, + Path: ApiV3 + "/aggTrades", + Method: http.MethodGet, + IsUserData: false, + UserTimeInterval: 0, + IpTimeInterval: 0, + }, + HTTPStatusCodeChecker: HTTPStatusCodeChecker, + RespBodyUnmarshaler: spotBodyUnmshWrapper(cex.StdBodyUnmarshaler[[]SpotAggTrades]), +} diff --git a/bnc/public.go b/bnc/public.go index 4baf984..d8868eb 100644 --- a/bnc/public.go +++ b/bnc/public.go @@ -200,3 +200,19 @@ func QueryCMPremiumIndex(symbol, pair string) ([]CMPremiumIndex, error) { } return data, nil } + +func QuerySpotTrades(symbol string) ([]SpotTrade, error) { + _, data, reqErr := cex.Request(emptyUser, SpotTradesConfig, SpotTradesParams{Symbol: symbol, Limit: 1000}) + if reqErr.IsNotNil() { + return nil, reqErr.Err + } + return data, nil +} + +func QuerySpotAggTrades(symbol string) ([]SpotAggTrades, error) { + _, data, reqErr := cex.Request(emptyUser, SpotAggTradesConfig, SpotAggTradesParams{Symbol: symbol, Limit: 1000}) + if reqErr.IsNotNil() { + return nil, reqErr.Err + } + return data, nil +}