Skip to content

Commit

Permalink
preparse filters
Browse files Browse the repository at this point in the history
  • Loading branch information
buck54321 committed Nov 28, 2024
1 parent 47d2deb commit 810504c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
33 changes: 33 additions & 0 deletions client/mm/libxc/binance.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,40 @@ func (bnc *binance) getMarkets(ctx context.Context) (map[string]*bntypes.Market,
}

marketsMap := make(map[string]*bntypes.Market, len(exchangeInfo.Symbols))
tokenIDs := bnc.tokenIDs.Load().(map[string][]uint32)
for _, market := range exchangeInfo.Symbols {
dexMarkets := binanceMarketToDexMarkets(market.BaseAsset, market.QuoteAsset, tokenIDs, bnc.isUS)
if len(dexMarkets) == 0 {
continue
}
dexMkt := dexMarkets[0]

bui, _ := asset.UnitInfo(dexMkt.BaseID)
qui, _ := asset.UnitInfo(dexMkt.QuoteID)

var rateStepFound, lotSizeFound bool
for _, filter := range market.Filters {
if filter.Type == "PRICE_FILTER" {
rateStepFound = true
conv := float64(qui.Conventional.ConversionFactor) / float64(bui.Conventional.ConversionFactor) * calc.RateEncodingFactor
market.RateStep = uint64(math.Round(filter.TickSize * conv))
market.MinPrice = uint64(math.Round(filter.MinPrice * conv))
market.MaxPrice = uint64(math.Round(filter.MaxPrice) * conv)
} else if filter.Type == "LOT_SIZE" {
lotSizeFound = true
market.LotSize = uint64(math.Round(filter.StepSize * float64(bui.Conventional.ConversionFactor)))
market.MinQty = uint64(math.Round(filter.MinQty * float64(bui.Conventional.ConversionFactor)))
market.MaxQty = uint64(math.Round(filter.MaxQty * float64(bui.Conventional.ConversionFactor)))
}
if rateStepFound && lotSizeFound {
break
}
}

if !rateStepFound || !lotSizeFound {
return nil, fmt.Errorf("missing filter for market %s, rate step found = %t, lot size found = %t", dexMkt.MarketID, rateStepFound, lotSizeFound)
}

marketsMap[market.Symbol] = market
}

Expand Down
7 changes: 7 additions & 0 deletions client/mm/libxc/bntypes/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ type Market struct {
QuoteAssetPrecision int `json:"quoteAssetPrecision"`
OrderTypes []string `json:"orderTypes"`
Filters []*Filter `json:"filters"`
// Below fields are parsed from Filters.
LotSize uint64
MinQty uint64
MaxQty uint64
RateStep uint64
MinPrice uint64
MaxPrice uint64
}

type Balance struct {
Expand Down

0 comments on commit 810504c

Please sign in to comment.