mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
all: change trade id to uint64
This commit is contained in:
parent
74b09551b5
commit
cfd68fdd1d
|
@ -226,7 +226,7 @@ func (m *SimplePriceMatching) newTradeFromOrder(order types.Order, isMaker bool)
|
||||||
|
|
||||||
var id = incTradeID()
|
var id = incTradeID()
|
||||||
return types.Trade{
|
return types.Trade{
|
||||||
ID: int64(id),
|
ID: id,
|
||||||
OrderID: order.OrderID,
|
OrderID: order.OrderID,
|
||||||
Exchange: "backtest",
|
Exchange: "backtest",
|
||||||
Price: order.Price,
|
Price: order.Price,
|
||||||
|
|
|
@ -10,7 +10,7 @@ type TradeStore struct {
|
||||||
// any created trades for tracking trades
|
// any created trades for tracking trades
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
|
|
||||||
trades map[int64]types.Trade
|
trades map[uint64]types.Trade
|
||||||
|
|
||||||
Symbol string
|
Symbol string
|
||||||
RemoveCancelled bool
|
RemoveCancelled bool
|
||||||
|
@ -21,7 +21,7 @@ type TradeStore struct {
|
||||||
func NewTradeStore(symbol string) *TradeStore {
|
func NewTradeStore(symbol string) *TradeStore {
|
||||||
return &TradeStore{
|
return &TradeStore{
|
||||||
Symbol: symbol,
|
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
|
return trades
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *TradeStore) Exists(oID int64) (ok bool) {
|
func (s *TradeStore) Exists(oID uint64) (ok bool) {
|
||||||
s.Lock()
|
s.Lock()
|
||||||
defer s.Unlock()
|
defer s.Unlock()
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ func (s *TradeStore) Exists(oID int64) (ok bool) {
|
||||||
|
|
||||||
func (s *TradeStore) Clear() {
|
func (s *TradeStore) Clear() {
|
||||||
s.Lock()
|
s.Lock()
|
||||||
s.trades = make(map[int64]types.Trade)
|
s.trades = make(map[uint64]types.Trade)
|
||||||
s.Unlock()
|
s.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ type TradeFilter func(trade types.Trade) bool
|
||||||
|
|
||||||
func (s *TradeStore) Filter(filter TradeFilter) {
|
func (s *TradeStore) Filter(filter TradeFilter) {
|
||||||
s.Lock()
|
s.Lock()
|
||||||
var trades = make(map[int64]types.Trade)
|
var trades = make(map[uint64]types.Trade)
|
||||||
for _, trade := range s.trades {
|
for _, trade := range s.trades {
|
||||||
if !filter(trade) {
|
if !filter(trade) {
|
||||||
trades[trade.ID] = trade
|
trades[trade.ID] = trade
|
||||||
|
@ -76,7 +76,7 @@ func (s *TradeStore) GetAndClear() (trades []types.Trade) {
|
||||||
for _, o := range s.trades {
|
for _, o := range s.trades {
|
||||||
trades = append(trades, o)
|
trades = append(trades, o)
|
||||||
}
|
}
|
||||||
s.trades = make(map[int64]types.Trade)
|
s.trades = make(map[uint64]types.Trade)
|
||||||
s.Unlock()
|
s.Unlock()
|
||||||
|
|
||||||
return trades
|
return trades
|
||||||
|
|
|
@ -294,7 +294,7 @@ func toGlobalTrade(t binance.TradeV3, isMargin bool) (*types.Trade, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return &types.Trade{
|
return &types.Trade{
|
||||||
ID: t.ID,
|
ID: uint64(t.ID),
|
||||||
OrderID: uint64(t.OrderID),
|
OrderID: uint64(t.OrderID),
|
||||||
Price: price,
|
Price: price,
|
||||||
Symbol: t.Symbol,
|
Symbol: t.Symbol,
|
||||||
|
@ -347,7 +347,7 @@ func toGlobalFuturesTrade(t futures.AccountTrade) (*types.Trade, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return &types.Trade{
|
return &types.Trade{
|
||||||
ID: t.ID,
|
ID: uint64(t.ID),
|
||||||
OrderID: uint64(t.OrderID),
|
OrderID: uint64(t.OrderID),
|
||||||
Price: price,
|
Price: price,
|
||||||
Symbol: t.Symbol,
|
Symbol: t.Symbol,
|
||||||
|
|
|
@ -3,13 +3,14 @@ package binance
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/adshao/go-binance/v2/futures"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/adshao/go-binance/v2/futures"
|
||||||
|
|
||||||
"go.uber.org/multierr"
|
"go.uber.org/multierr"
|
||||||
|
|
||||||
"golang.org/x/time/rate"
|
"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
|
// BINANCE uses inclusive last trade ID
|
||||||
if options.LastTradeID > 0 {
|
if options.LastTradeID > 0 {
|
||||||
req.FromID(options.LastTradeID)
|
req.FromID(int64(options.LastTradeID))
|
||||||
}
|
}
|
||||||
|
|
||||||
remoteTrades, err = req.Do(ctx)
|
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
|
// BINANCE uses inclusive last trade ID
|
||||||
if options.LastTradeID > 0 {
|
if options.LastTradeID > 0 {
|
||||||
req.FromID(options.LastTradeID)
|
req.FromID(int64(options.LastTradeID))
|
||||||
}
|
}
|
||||||
|
|
||||||
remoteTrades, err = req.Do(ctx)
|
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
|
// BINANCE uses inclusive last trade ID
|
||||||
if options.LastTradeID > 0 {
|
if options.LastTradeID > 0 {
|
||||||
req.FromID(options.LastTradeID)
|
req.FromID(int64(options.LastTradeID))
|
||||||
}
|
}
|
||||||
|
|
||||||
remoteTrades, err = req.Do(ctx)
|
remoteTrades, err = req.Do(ctx)
|
||||||
|
|
|
@ -4,9 +4,10 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/adshao/go-binance/v2/futures"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/adshao/go-binance/v2/futures"
|
||||||
|
|
||||||
"github.com/adshao/go-binance/v2"
|
"github.com/adshao/go-binance/v2"
|
||||||
"github.com/valyala/fastjson"
|
"github.com/valyala/fastjson"
|
||||||
|
|
||||||
|
@ -87,10 +88,10 @@ type ExecutionReportEvent struct {
|
||||||
CurrentOrderStatus string `json:"X"`
|
CurrentOrderStatus string `json:"X"`
|
||||||
|
|
||||||
OrderID int64 `json:"i"`
|
OrderID int64 `json:"i"`
|
||||||
Ignored int64 `json:"I"`
|
Ignored int64 `json:"I"`
|
||||||
|
|
||||||
TradeID int64 `json:"t"`
|
TradeID int64 `json:"t"`
|
||||||
TransactionTime int64 `json:"T"`
|
TransactionTime int64 `json:"T"`
|
||||||
|
|
||||||
LastExecutedQuantity string `json:"l"`
|
LastExecutedQuantity string `json:"l"`
|
||||||
LastExecutedPrice string `json:"L"`
|
LastExecutedPrice string `json:"L"`
|
||||||
|
@ -137,7 +138,7 @@ func (e *ExecutionReportEvent) Trade() (*types.Trade, error) {
|
||||||
|
|
||||||
tt := time.Unix(0, e.TransactionTime*int64(time.Millisecond))
|
tt := time.Unix(0, e.TransactionTime*int64(time.Millisecond))
|
||||||
return &types.Trade{
|
return &types.Trade{
|
||||||
ID: e.TradeID,
|
ID: uint64(e.TradeID),
|
||||||
Exchange: types.ExchangeBinance,
|
Exchange: types.ExchangeBinance,
|
||||||
Symbol: e.Symbol,
|
Symbol: e.Symbol,
|
||||||
OrderID: uint64(e.OrderID),
|
OrderID: uint64(e.OrderID),
|
||||||
|
|
|
@ -363,7 +363,7 @@ func (e *Exchange) QueryTrades(ctx context.Context, symbol string, options *type
|
||||||
limit = 200
|
limit = 200
|
||||||
}
|
}
|
||||||
|
|
||||||
tradeIDs := make(map[int64]struct{})
|
tradeIDs := make(map[uint64]struct{})
|
||||||
|
|
||||||
lastTradeID := options.LastTradeID
|
lastTradeID := options.LastTradeID
|
||||||
var trades []types.Trade
|
var trades []types.Trade
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"github.com/c9s/bbgo/pkg/types"
|
"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"
|
const timeLayout = "2006-01-02T15:04:05.999999Z07:00"
|
||||||
|
|
||||||
type datetime struct {
|
type datetime struct {
|
||||||
|
@ -364,7 +364,7 @@ type fill struct {
|
||||||
Size float64 `json:"size"`
|
Size float64 `json:"size"`
|
||||||
OrderId uint64 `json:"orderId"`
|
OrderId uint64 `json:"orderId"`
|
||||||
Time datetime `json:"time"`
|
Time datetime `json:"time"`
|
||||||
TradeId int64 `json:"tradeId"`
|
TradeId uint64 `json:"tradeId"`
|
||||||
FeeRate float64 `json:"feeRate"`
|
FeeRate float64 `json:"feeRate"`
|
||||||
Fee float64 `json:"fee"`
|
Fee float64 `json:"fee"`
|
||||||
FeeCurrency string `json:"feeCurrency"`
|
FeeCurrency string `json:"feeCurrency"`
|
||||||
|
|
|
@ -233,7 +233,7 @@ func toGlobalTrade(t max.Trade) (*types.Trade, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return &types.Trade{
|
return &types.Trade{
|
||||||
ID: int64(t.ID),
|
ID: t.ID,
|
||||||
OrderID: t.OrderID,
|
OrderID: t.OrderID,
|
||||||
Price: price,
|
Price: price,
|
||||||
Symbol: toGlobalSymbol(t.Market),
|
Symbol: toGlobalSymbol(t.Market),
|
||||||
|
|
|
@ -744,7 +744,7 @@ func (e *Exchange) QueryTrades(ctx context.Context, symbol string, options *type
|
||||||
|
|
||||||
// MAX uses exclusive last trade ID
|
// MAX uses exclusive last trade ID
|
||||||
if options.LastTradeID > 0 {
|
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.
|
// make it compatible with binance, we need the last trade id for the next page.
|
||||||
|
|
|
@ -213,7 +213,7 @@ func convertWebSocketTrade(t max.TradeUpdate) (*types.Trade, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return &types.Trade{
|
return &types.Trade{
|
||||||
ID: int64(t.ID),
|
ID: t.ID,
|
||||||
OrderID: t.OrderID,
|
OrderID: t.OrderID,
|
||||||
Symbol: toGlobalSymbol(t.Market),
|
Symbol: toGlobalSymbol(t.Market),
|
||||||
Exchange: types.ExchangeMax,
|
Exchange: types.ExchangeMax,
|
||||||
|
|
|
@ -136,7 +136,7 @@ func toGlobalTrades(orderDetails []okexapi.OrderDetails) ([]types.Trade, error)
|
||||||
side := types.SideType(strings.ToUpper(string(orderDetail.Side)))
|
side := types.SideType(strings.ToUpper(string(orderDetail.Side)))
|
||||||
|
|
||||||
trades = append(trades, types.Trade{
|
trades = append(trades, types.Trade{
|
||||||
ID: tradeID,
|
ID: uint64(tradeID),
|
||||||
OrderID: uint64(orderID),
|
OrderID: uint64(orderID),
|
||||||
Exchange: types.ExchangeOKEx,
|
Exchange: types.ExchangeOKEx,
|
||||||
Price: orderDetail.LastFilledPrice.Float64(),
|
Price: orderDetail.LastFilledPrice.Float64(),
|
||||||
|
|
|
@ -81,7 +81,7 @@ func (s *TradeService) Sync(ctx context.Context, exchange types.Exchange, symbol
|
||||||
}
|
}
|
||||||
|
|
||||||
var tradeKeys = map[types.TradeKey]struct{}{}
|
var tradeKeys = map[types.TradeKey]struct{}{}
|
||||||
var lastTradeID int64 = 1
|
var lastTradeID uint64 = 1
|
||||||
if len(records) > 0 {
|
if len(records) > 0 {
|
||||||
for _, record := range records {
|
for _, record := range records {
|
||||||
tradeKeys[record.Key()] = struct{}{}
|
tradeKeys[record.Key()] = struct{}{}
|
||||||
|
|
|
@ -126,5 +126,5 @@ type TradeQueryOptions struct {
|
||||||
StartTime *time.Time
|
StartTime *time.Time
|
||||||
EndTime *time.Time
|
EndTime *time.Time
|
||||||
Limit int64
|
Limit int64
|
||||||
LastTradeID int64
|
LastTradeID uint64
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ type Trade struct {
|
||||||
GID int64 `json:"gid" db:"gid"`
|
GID int64 `json:"gid" db:"gid"`
|
||||||
|
|
||||||
// ID is the source trade ID
|
// 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"`
|
OrderID uint64 `json:"orderID" db:"order_id"`
|
||||||
Exchange ExchangeName `json:"exchange" db:"exchange"`
|
Exchange ExchangeName `json:"exchange" db:"exchange"`
|
||||||
Price float64 `json:"price" db:"price"`
|
Price float64 `json:"price" db:"price"`
|
||||||
|
@ -143,6 +143,6 @@ func (trade Trade) Key() TradeKey {
|
||||||
}
|
}
|
||||||
|
|
||||||
type TradeKey struct {
|
type TradeKey struct {
|
||||||
ID int64
|
ID uint64
|
||||||
Side SideType
|
Side SideType
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user