From 4aca676b4df5bcf3788a213906fb3e5b48f6c5d9 Mon Sep 17 00:00:00 2001 From: c9s Date: Fri, 23 Feb 2024 17:04:03 +0800 Subject: [PATCH] all: add exchange field to types.Market --- pkg/exchange/binance/convert.go | 2 ++ pkg/exchange/bitget/convert.go | 1 + pkg/exchange/bitget/convert_test.go | 1 + pkg/exchange/max/exchange.go | 5 ++++- pkg/exchange/okex/exchange.go | 9 +++++++-- pkg/types/market.go | 2 ++ 6 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pkg/exchange/binance/convert.go b/pkg/exchange/binance/convert.go index 8aae013f6..ebc64c9a4 100644 --- a/pkg/exchange/binance/convert.go +++ b/pkg/exchange/binance/convert.go @@ -15,6 +15,7 @@ import ( func toGlobalMarket(symbol binance.Symbol) types.Market { market := types.Market{ + Exchange: types.ExchangeBinance, Symbol: symbol.Symbol, LocalSymbol: symbol.Symbol, PricePrecision: symbol.QuotePrecision, @@ -59,6 +60,7 @@ func toGlobalMarket(symbol binance.Symbol) types.Market { // TODO: Cuz it returns types.Market as well, merge following to the above function func toGlobalFuturesMarket(symbol futures.Symbol) types.Market { market := types.Market{ + Exchange: types.ExchangeBinance, Symbol: symbol.Symbol, LocalSymbol: symbol.Symbol, PricePrecision: symbol.QuotePrecision, diff --git a/pkg/exchange/bitget/convert.go b/pkg/exchange/bitget/convert.go index 54ca48498..6e5a7593b 100644 --- a/pkg/exchange/bitget/convert.go +++ b/pkg/exchange/bitget/convert.go @@ -30,6 +30,7 @@ func toGlobalMarket(s v2.Symbol) types.Market { } return types.Market{ + Exchange: types.ExchangeBitget, Symbol: s.Symbol, LocalSymbol: s.Symbol, PricePrecision: s.PricePrecision.Int(), diff --git a/pkg/exchange/bitget/convert_test.go b/pkg/exchange/bitget/convert_test.go index 6f34b5021..59e9a4ca8 100644 --- a/pkg/exchange/bitget/convert_test.go +++ b/pkg/exchange/bitget/convert_test.go @@ -78,6 +78,7 @@ func Test_toGlobalMarket(t *testing.T) { } exp := types.Market{ + Exchange: types.ExchangeBitget, Symbol: inst.Symbol, LocalSymbol: inst.Symbol, PricePrecision: 2, diff --git a/pkg/exchange/max/exchange.go b/pkg/exchange/max/exchange.go index 98a6bbbda..27c995cd0 100644 --- a/pkg/exchange/max/exchange.go +++ b/pkg/exchange/max/exchange.go @@ -146,6 +146,7 @@ func (e *Exchange) QueryMarkets(ctx context.Context) (types.MarketMap, error) { symbol := toGlobalSymbol(m.ID) market := types.Market{ + Exchange: types.ExchangeMax, Symbol: symbol, LocalSymbol: m.ID, PricePrecision: m.QuoteUnitPrecision, @@ -372,7 +373,9 @@ func (e *Exchange) queryClosedOrdersByLastOrderID( return types.SortOrdersAscending(orders), nil } -func (e *Exchange) queryClosedOrdersByTime(ctx context.Context, symbol string, since, until time.Time, orderByType maxapi.OrderByType) (orders []types.Order, err error) { +func (e *Exchange) queryClosedOrdersByTime( + ctx context.Context, symbol string, since, until time.Time, orderByType maxapi.OrderByType, +) (orders []types.Order, err error) { if err := e.closedOrderQueryLimiter.Wait(ctx); err != nil { return orders, err } diff --git a/pkg/exchange/okex/exchange.go b/pkg/exchange/okex/exchange.go index 1b866fb87..e7226ed49 100644 --- a/pkg/exchange/okex/exchange.go +++ b/pkg/exchange/okex/exchange.go @@ -95,6 +95,7 @@ func (e *Exchange) QueryMarkets(ctx context.Context) (types.MarketMap, error) { for _, instrument := range instruments { symbol := toGlobalSymbol(instrument.InstrumentID) market := types.Market{ + Exchange: types.ExchangeOKEx, Symbol: symbol, LocalSymbol: instrument.InstrumentID, @@ -383,7 +384,9 @@ func (e *Exchange) NewStream() types.Stream { return NewStream(e.client, e) } -func (e *Exchange) QueryKLines(ctx context.Context, symbol string, interval types.Interval, options types.KLineQueryOptions) ([]types.KLine, error) { +func (e *Exchange) QueryKLines( + ctx context.Context, symbol string, interval types.Interval, options types.KLineQueryOptions, +) ([]types.KLine, error) { if err := queryKLineLimiter.Wait(ctx); err != nil { return nil, fmt.Errorf("query k line rate limiter wait error: %w", err) } @@ -477,7 +480,9 @@ If you want to query all orders within a large time range (e.g. total orders > 1 ** since and until are inclusive, you can include the lastTradeId as well. ** */ -func (e *Exchange) QueryClosedOrders(ctx context.Context, symbol string, since, until time.Time, lastOrderID uint64) (orders []types.Order, err error) { +func (e *Exchange) QueryClosedOrders( + ctx context.Context, symbol string, since, until time.Time, lastOrderID uint64, +) (orders []types.Order, err error) { if symbol == "" { return nil, ErrSymbolRequired } diff --git a/pkg/types/market.go b/pkg/types/market.go index 5ea42d6d7..4b2934222 100644 --- a/pkg/types/market.go +++ b/pkg/types/market.go @@ -10,6 +10,8 @@ import ( ) type Market struct { + Exchange ExchangeName `json:"exchange,omitempty"` + Symbol string `json:"symbol"` // LocalSymbol is used for exchange's API (exchange package internal)