all: add exchange field to types.Market

This commit is contained in:
c9s 2024-02-23 17:04:03 +08:00
parent 945c442b92
commit 4aca676b4d
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
6 changed files with 17 additions and 3 deletions

View File

@ -15,6 +15,7 @@ import (
func toGlobalMarket(symbol binance.Symbol) types.Market { func toGlobalMarket(symbol binance.Symbol) types.Market {
market := types.Market{ market := types.Market{
Exchange: types.ExchangeBinance,
Symbol: symbol.Symbol, Symbol: symbol.Symbol,
LocalSymbol: symbol.Symbol, LocalSymbol: symbol.Symbol,
PricePrecision: symbol.QuotePrecision, 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 // TODO: Cuz it returns types.Market as well, merge following to the above function
func toGlobalFuturesMarket(symbol futures.Symbol) types.Market { func toGlobalFuturesMarket(symbol futures.Symbol) types.Market {
market := types.Market{ market := types.Market{
Exchange: types.ExchangeBinance,
Symbol: symbol.Symbol, Symbol: symbol.Symbol,
LocalSymbol: symbol.Symbol, LocalSymbol: symbol.Symbol,
PricePrecision: symbol.QuotePrecision, PricePrecision: symbol.QuotePrecision,

View File

@ -30,6 +30,7 @@ func toGlobalMarket(s v2.Symbol) types.Market {
} }
return types.Market{ return types.Market{
Exchange: types.ExchangeBitget,
Symbol: s.Symbol, Symbol: s.Symbol,
LocalSymbol: s.Symbol, LocalSymbol: s.Symbol,
PricePrecision: s.PricePrecision.Int(), PricePrecision: s.PricePrecision.Int(),

View File

@ -78,6 +78,7 @@ func Test_toGlobalMarket(t *testing.T) {
} }
exp := types.Market{ exp := types.Market{
Exchange: types.ExchangeBitget,
Symbol: inst.Symbol, Symbol: inst.Symbol,
LocalSymbol: inst.Symbol, LocalSymbol: inst.Symbol,
PricePrecision: 2, PricePrecision: 2,

View File

@ -146,6 +146,7 @@ func (e *Exchange) QueryMarkets(ctx context.Context) (types.MarketMap, error) {
symbol := toGlobalSymbol(m.ID) symbol := toGlobalSymbol(m.ID)
market := types.Market{ market := types.Market{
Exchange: types.ExchangeMax,
Symbol: symbol, Symbol: symbol,
LocalSymbol: m.ID, LocalSymbol: m.ID,
PricePrecision: m.QuoteUnitPrecision, PricePrecision: m.QuoteUnitPrecision,
@ -372,7 +373,9 @@ func (e *Exchange) queryClosedOrdersByLastOrderID(
return types.SortOrdersAscending(orders), nil 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 { if err := e.closedOrderQueryLimiter.Wait(ctx); err != nil {
return orders, err return orders, err
} }

View File

@ -95,6 +95,7 @@ func (e *Exchange) QueryMarkets(ctx context.Context) (types.MarketMap, error) {
for _, instrument := range instruments { for _, instrument := range instruments {
symbol := toGlobalSymbol(instrument.InstrumentID) symbol := toGlobalSymbol(instrument.InstrumentID)
market := types.Market{ market := types.Market{
Exchange: types.ExchangeOKEx,
Symbol: symbol, Symbol: symbol,
LocalSymbol: instrument.InstrumentID, LocalSymbol: instrument.InstrumentID,
@ -383,7 +384,9 @@ func (e *Exchange) NewStream() types.Stream {
return NewStream(e.client, e) 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 { if err := queryKLineLimiter.Wait(ctx); err != nil {
return nil, fmt.Errorf("query k line rate limiter wait error: %w", err) 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. ** ** 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 == "" { if symbol == "" {
return nil, ErrSymbolRequired return nil, ErrSymbolRequired
} }

View File

@ -10,6 +10,8 @@ import (
) )
type Market struct { type Market struct {
Exchange ExchangeName `json:"exchange,omitempty"`
Symbol string `json:"symbol"` Symbol string `json:"symbol"`
// LocalSymbol is used for exchange's API (exchange package internal) // LocalSymbol is used for exchange's API (exchange package internal)