mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
implement QueryMarkets on binance
This commit is contained in:
parent
f454136449
commit
64c2170cd5
|
@ -37,6 +37,48 @@ func (e *Exchange) Name() types.ExchangeName {
|
|||
return types.ExchangeBinance
|
||||
}
|
||||
|
||||
func (e *Exchange) QueryMarkets(ctx context.Context) (types.MarketMap, error) {
|
||||
exchangeInfo, err := e.Client.NewExchangeInfoService().Do(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
markets := types.MarketMap{}
|
||||
for _, symbol := range exchangeInfo.Symbols {
|
||||
market := types.Market{
|
||||
Symbol: symbol.Symbol,
|
||||
PricePrecision: symbol.QuotePrecision,
|
||||
VolumePrecision: symbol.BaseAssetPrecision,
|
||||
QuoteCurrency: symbol.QuoteAsset,
|
||||
BaseCurrency: symbol.BaseAsset,
|
||||
MinAmount: 0,
|
||||
MinNotional: 0,
|
||||
MinLot: 0,
|
||||
}
|
||||
|
||||
if f := symbol.MinNotionalFilter() ; f != nil {
|
||||
market.MinNotional = util.MustParseFloat(f.MinNotional)
|
||||
}
|
||||
|
||||
if f := symbol.LotSizeFilter() ; f != nil {
|
||||
market.MinLot = util.MustParseFloat(f.MinQuantity)
|
||||
market.MinQuantity = util.MustParseFloat(f.MinQuantity)
|
||||
market.MaxQuantity = util.MustParseFloat(f.MaxQuantity)
|
||||
// market.StepSize = util.MustParseFloat(f.StepSize)
|
||||
}
|
||||
|
||||
if f := symbol.PriceFilter() ; f != nil {
|
||||
_ = f.MaxPrice
|
||||
_ = f.MinPrice
|
||||
_ = f.TickSize
|
||||
}
|
||||
|
||||
markets[symbol.Symbol] = market
|
||||
}
|
||||
|
||||
return markets, nil
|
||||
}
|
||||
|
||||
func (e *Exchange) QueryAveragePrice(ctx context.Context, symbol string) (float64, error) {
|
||||
resp, err := e.Client.NewAveragePriceService().Symbol(symbol).Do(ctx)
|
||||
if err != nil {
|
||||
|
|
|
@ -3,6 +3,8 @@ package types
|
|||
import (
|
||||
"math"
|
||||
"strconv"
|
||||
|
||||
"github.com/c9s/bbgo/types"
|
||||
)
|
||||
|
||||
type Market struct {
|
||||
|
@ -11,7 +13,10 @@ type Market struct {
|
|||
VolumePrecision int
|
||||
QuoteCurrency string
|
||||
BaseCurrency string
|
||||
|
||||
MinQuantity float64
|
||||
MaxQuantity float64
|
||||
|
||||
MinAmount float64
|
||||
MinNotional float64
|
||||
MinLot float64
|
||||
|
@ -80,6 +85,8 @@ var MarketBNBUSDT = Market{
|
|||
MinNotional: 10.0,
|
||||
}
|
||||
|
||||
type MarketMap map[string]Market
|
||||
|
||||
var Markets = map[string]Market{
|
||||
"ETHUSDT": MarketETHUSDT,
|
||||
"BNBUSDT": MarketBNBUSDT,
|
||||
|
|
Loading…
Reference in New Issue
Block a user