all: change trade id to uint64

This commit is contained in:
c9s 2021-12-23 13:15:27 +08:00
parent 74b09551b5
commit cfd68fdd1d
14 changed files with 30 additions and 28 deletions

View File

@ -226,7 +226,7 @@ func (m *SimplePriceMatching) newTradeFromOrder(order types.Order, isMaker bool)
var id = incTradeID()
return types.Trade{
ID: int64(id),
ID: id,
OrderID: order.OrderID,
Exchange: "backtest",
Price: order.Price,

View File

@ -10,7 +10,7 @@ type TradeStore struct {
// any created trades for tracking trades
sync.Mutex
trades map[int64]types.Trade
trades map[uint64]types.Trade
Symbol string
RemoveCancelled bool
@ -21,7 +21,7 @@ type TradeStore struct {
func NewTradeStore(symbol string) *TradeStore {
return &TradeStore{
Symbol: symbol,
trades: make(map[int64]types.Trade),
trades: make(map[uint64]types.Trade),
}
}
@ -43,7 +43,7 @@ func (s *TradeStore) Trades() (trades []types.Trade) {
return trades
}
func (s *TradeStore) Exists(oID int64) (ok bool) {
func (s *TradeStore) Exists(oID uint64) (ok bool) {
s.Lock()
defer s.Unlock()
@ -53,7 +53,7 @@ func (s *TradeStore) Exists(oID int64) (ok bool) {
func (s *TradeStore) Clear() {
s.Lock()
s.trades = make(map[int64]types.Trade)
s.trades = make(map[uint64]types.Trade)
s.Unlock()
}
@ -61,7 +61,7 @@ type TradeFilter func(trade types.Trade) bool
func (s *TradeStore) Filter(filter TradeFilter) {
s.Lock()
var trades = make(map[int64]types.Trade)
var trades = make(map[uint64]types.Trade)
for _, trade := range s.trades {
if !filter(trade) {
trades[trade.ID] = trade
@ -76,7 +76,7 @@ func (s *TradeStore) GetAndClear() (trades []types.Trade) {
for _, o := range s.trades {
trades = append(trades, o)
}
s.trades = make(map[int64]types.Trade)
s.trades = make(map[uint64]types.Trade)
s.Unlock()
return trades

View File

@ -294,7 +294,7 @@ func toGlobalTrade(t binance.TradeV3, isMargin bool) (*types.Trade, error) {
}
return &types.Trade{
ID: t.ID,
ID: uint64(t.ID),
OrderID: uint64(t.OrderID),
Price: price,
Symbol: t.Symbol,
@ -347,7 +347,7 @@ func toGlobalFuturesTrade(t futures.AccountTrade) (*types.Trade, error) {
}
return &types.Trade{
ID: t.ID,
ID: uint64(t.ID),
OrderID: uint64(t.OrderID),
Price: price,
Symbol: t.Symbol,

View File

@ -3,13 +3,14 @@ package binance
import (
"context"
"fmt"
"github.com/adshao/go-binance/v2/futures"
"net/http"
"os"
"strconv"
"strings"
"time"
"github.com/adshao/go-binance/v2/futures"
"go.uber.org/multierr"
"golang.org/x/time/rate"
@ -961,7 +962,7 @@ func (e *Exchange) QueryTrades(ctx context.Context, symbol string, options *type
// BINANCE uses inclusive last trade ID
if options.LastTradeID > 0 {
req.FromID(options.LastTradeID)
req.FromID(int64(options.LastTradeID))
}
remoteTrades, err = req.Do(ctx)
@ -992,7 +993,7 @@ func (e *Exchange) QueryTrades(ctx context.Context, symbol string, options *type
// BINANCE uses inclusive last trade ID
if options.LastTradeID > 0 {
req.FromID(options.LastTradeID)
req.FromID(int64(options.LastTradeID))
}
remoteTrades, err = req.Do(ctx)
@ -1030,7 +1031,7 @@ func (e *Exchange) QueryTrades(ctx context.Context, symbol string, options *type
// BINANCE uses inclusive last trade ID
if options.LastTradeID > 0 {
req.FromID(options.LastTradeID)
req.FromID(int64(options.LastTradeID))
}
remoteTrades, err = req.Do(ctx)

View File

@ -4,9 +4,10 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/adshao/go-binance/v2/futures"
"time"
"github.com/adshao/go-binance/v2/futures"
"github.com/adshao/go-binance/v2"
"github.com/valyala/fastjson"
@ -137,7 +138,7 @@ func (e *ExecutionReportEvent) Trade() (*types.Trade, error) {
tt := time.Unix(0, e.TransactionTime*int64(time.Millisecond))
return &types.Trade{
ID: e.TradeID,
ID: uint64(e.TradeID),
Exchange: types.ExchangeBinance,
Symbol: e.Symbol,
OrderID: uint64(e.OrderID),

View File

@ -363,7 +363,7 @@ func (e *Exchange) QueryTrades(ctx context.Context, symbol string, options *type
limit = 200
}
tradeIDs := make(map[int64]struct{})
tradeIDs := make(map[uint64]struct{})
lastTradeID := options.LastTradeID
var trades []types.Trade

View File

@ -8,7 +8,7 @@ import (
"github.com/c9s/bbgo/pkg/types"
)
//ex: 2019-03-05T09:56:55.728933+00:00
// ex: 2019-03-05T09:56:55.728933+00:00
const timeLayout = "2006-01-02T15:04:05.999999Z07:00"
type datetime struct {
@ -364,7 +364,7 @@ type fill struct {
Size float64 `json:"size"`
OrderId uint64 `json:"orderId"`
Time datetime `json:"time"`
TradeId int64 `json:"tradeId"`
TradeId uint64 `json:"tradeId"`
FeeRate float64 `json:"feeRate"`
Fee float64 `json:"fee"`
FeeCurrency string `json:"feeCurrency"`

View File

@ -233,7 +233,7 @@ func toGlobalTrade(t max.Trade) (*types.Trade, error) {
}
return &types.Trade{
ID: int64(t.ID),
ID: t.ID,
OrderID: t.OrderID,
Price: price,
Symbol: toGlobalSymbol(t.Market),

View File

@ -744,7 +744,7 @@ func (e *Exchange) QueryTrades(ctx context.Context, symbol string, options *type
// MAX uses exclusive last trade ID
if options.LastTradeID > 0 {
req.From(options.LastTradeID)
req.From(int64(options.LastTradeID))
}
// make it compatible with binance, we need the last trade id for the next page.

View File

@ -213,7 +213,7 @@ func convertWebSocketTrade(t max.TradeUpdate) (*types.Trade, error) {
}
return &types.Trade{
ID: int64(t.ID),
ID: t.ID,
OrderID: t.OrderID,
Symbol: toGlobalSymbol(t.Market),
Exchange: types.ExchangeMax,

View File

@ -136,7 +136,7 @@ func toGlobalTrades(orderDetails []okexapi.OrderDetails) ([]types.Trade, error)
side := types.SideType(strings.ToUpper(string(orderDetail.Side)))
trades = append(trades, types.Trade{
ID: tradeID,
ID: uint64(tradeID),
OrderID: uint64(orderID),
Exchange: types.ExchangeOKEx,
Price: orderDetail.LastFilledPrice.Float64(),

View File

@ -81,7 +81,7 @@ func (s *TradeService) Sync(ctx context.Context, exchange types.Exchange, symbol
}
var tradeKeys = map[types.TradeKey]struct{}{}
var lastTradeID int64 = 1
var lastTradeID uint64 = 1
if len(records) > 0 {
for _, record := range records {
tradeKeys[record.Key()] = struct{}{}

View File

@ -126,5 +126,5 @@ type TradeQueryOptions struct {
StartTime *time.Time
EndTime *time.Time
Limit int64
LastTradeID int64
LastTradeID uint64
}

View File

@ -50,7 +50,7 @@ type Trade struct {
GID int64 `json:"gid" db:"gid"`
// ID is the source trade ID
ID int64 `json:"id" db:"id"`
ID uint64 `json:"id" db:"id"`
OrderID uint64 `json:"orderID" db:"order_id"`
Exchange ExchangeName `json:"exchange" db:"exchange"`
Price float64 `json:"price" db:"price"`
@ -143,6 +143,6 @@ func (trade Trade) Key() TradeKey {
}
type TradeKey struct {
ID int64
ID uint64
Side SideType
}