Skip to content

Commit

Permalink
all: add exchange field to types.Market
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Feb 23, 2024
1 parent 945c442 commit 4aca676
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions pkg/exchange/binance/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions pkg/exchange/bitget/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions pkg/exchange/bitget/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func Test_toGlobalMarket(t *testing.T) {
}

exp := types.Market{
Exchange: types.ExchangeBitget,
Symbol: inst.Symbol,
LocalSymbol: inst.Symbol,
PricePrecision: 2,
Expand Down
5 changes: 4 additions & 1 deletion pkg/exchange/max/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
Expand Down
9 changes: 7 additions & 2 deletions pkg/exchange/okex/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/types/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4aca676

Please sign in to comment.