mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
fix: replace json.Number with MillisecondTimestamp in types
This commit is contained in:
parent
2e4336a604
commit
08dad1c497
|
@ -4,7 +4,6 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/adshao/go-binance/v2/futures"
|
||||
|
@ -18,8 +17,8 @@ import (
|
|||
)
|
||||
|
||||
type EventBase struct {
|
||||
Event string `json:"e"` // event name
|
||||
Time json.Number `json:"E"` // event time
|
||||
Event string `json:"e"` // event name
|
||||
Time types.MillisecondTimestamp `json:"E"` // event time
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -462,11 +461,7 @@ func (e *DepthEvent) String() (o string) {
|
|||
|
||||
func (e *DepthEvent) OrderBook() (book types.SliceOrderBook, err error) {
|
||||
book.Symbol = e.Symbol
|
||||
t, err := e.EventBase.Time.Int64()
|
||||
if err != nil {
|
||||
return book, err
|
||||
}
|
||||
book.Time = types.NewMillisecondTimestampFromInt(t).Time()
|
||||
book.Time = e.EventBase.Time.Time()
|
||||
|
||||
// already in descending order
|
||||
book.Bids = e.Bids
|
||||
|
@ -505,7 +500,7 @@ func parseDepthEvent(val *fastjson.Value) (*DepthEvent, error) {
|
|||
var depth = &DepthEvent{
|
||||
EventBase: EventBase{
|
||||
Event: string(val.GetStringBytes("e")),
|
||||
Time: json.Number(strconv.FormatInt(val.GetInt64("E"), 10)),
|
||||
Time: types.NewMillisecondTimestampFromInt(val.GetInt64("E")),
|
||||
},
|
||||
Symbol: string(val.GetStringBytes("s")),
|
||||
FirstUpdateID: val.GetInt64("U"),
|
||||
|
|
|
@ -397,7 +397,7 @@ func TestParseOrderFuturesUpdate(t *testing.T) {
|
|||
assert.Equal(t, "SELL", orderTradeEvent.OrderTrade.Side)
|
||||
assert.Equal(t, "x-NSUYEBKMe60cf610-f5c7-49a4-9c1", orderTradeEvent.OrderTrade.ClientOrderID)
|
||||
assert.Equal(t, "MARKET", orderTradeEvent.OrderTrade.OrderType)
|
||||
assert.Equal(t, int64(1639933384763), orderTradeEvent.Time)
|
||||
assert.Equal(t, types.NewMillisecondTimestampFromInt(1639933384763), orderTradeEvent.Time)
|
||||
assert.Equal(t, types.MillisecondTimestamp(time.UnixMilli(1639933384755)), orderTradeEvent.OrderTrade.OrderTradeTime)
|
||||
assert.Equal(t, fixedpoint.MustNewFromString("0.001"), orderTradeEvent.OrderTrade.OriginalQuantity)
|
||||
assert.Equal(t, fixedpoint.MustNewFromString("0.001"), orderTradeEvent.OrderTrade.OrderLastFilledQuantity)
|
||||
|
|
|
@ -86,13 +86,9 @@ func NewStream(ex *Exchange, client *binance.Client, futuresClient *futures.Clie
|
|||
stream.OnDepthEvent(func(e *DepthEvent) {
|
||||
f, ok := stream.depthBuffers[e.Symbol]
|
||||
if ok {
|
||||
t, err := e.EventBase.Time.Int64()
|
||||
if err != nil {
|
||||
log.WithError(err).Errorf("Time parsing failed: %v", e.EventBase.Time)
|
||||
}
|
||||
err = f.AddUpdate(types.SliceOrderBook{
|
||||
err := f.AddUpdate(types.SliceOrderBook{
|
||||
Symbol: e.Symbol,
|
||||
Time: types.NewMillisecondTimestampFromInt(t).Time(),
|
||||
Time: e.EventBase.Time.Time(),
|
||||
Bids: e.Bids,
|
||||
Asks: e.Asks,
|
||||
}, e.FirstUpdateID, e.FinalUpdateID)
|
||||
|
|
|
@ -527,19 +527,14 @@ func (s *Strategy) handleAccountUpdate(ctx context.Context, e *binance.AccountUp
|
|||
if b.Asset != s.ProfitStats.FundingFeeCurrency {
|
||||
continue
|
||||
}
|
||||
t, err := e.EventBase.Time.Int64()
|
||||
if err != nil {
|
||||
log.WithError(err).Error("unable to parse event timestamp")
|
||||
continue
|
||||
}
|
||||
txnTime := time.UnixMilli(t)
|
||||
txnTime := e.EventBase.Time.Time()
|
||||
fee := FundingFee{
|
||||
Asset: b.Asset,
|
||||
Amount: b.BalanceChange,
|
||||
Txn: e.Transaction,
|
||||
Time: txnTime,
|
||||
}
|
||||
err = s.ProfitStats.AddFundingFee(fee)
|
||||
err := s.ProfitStats.AddFundingFee(fee)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("unable to add funding fee to profitStats")
|
||||
continue
|
||||
|
|
Loading…
Reference in New Issue
Block a user