bitget: implement QueryMarkets

This commit is contained in:
c9s 2023-08-09 15:20:33 +08:00
parent d43c358b61
commit 2fda4477bd
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
5 changed files with 100 additions and 5 deletions

View File

@ -38,6 +38,13 @@ func TestClient(t *testing.T) {
t.Logf("tickers: %+v", tickers)
})
t.Run("GetSymbolsRequest", func(t *testing.T) {
req := client.NewGetSymbolsRequest()
symbols, err := req.Do(ctx)
assert.NoError(t, err)
t.Logf("symbols: %+v", symbols)
})
t.Run("GetTickerRequest", func(t *testing.T) {
req := client.NewGetTickerRequest()
req.Symbol("BTCUSDT_SPBL")

View File

@ -18,8 +18,8 @@ type Symbol struct {
MaxTradeAmount fixedpoint.Value `json:"maxTradeAmount"`
TakerFeeRate fixedpoint.Value `json:"takerFeeRate"`
MakerFeeRate fixedpoint.Value `json:"makerFeeRate"`
PriceScale fixedpoint.Value `json:"priceScale"`
QuantityScale fixedpoint.Value `json:"quantityScale"`
PriceScale int `json:"priceScale"`
QuantityScale int `json:"quantityScale"`
MinTradeUSDT fixedpoint.Value `json:"minTradeUSDT"`
Status string `json:"status"`
BuyLimitPriceRatio fixedpoint.Value `json:"buyLimitPriceRatio"`

View File

@ -0,0 +1,7 @@
package bitget
import "strings"
func toGlobalSymbol(s string) string {
return strings.ToUpper(s)
}

View File

@ -1,9 +1,13 @@
package bitget
import (
"context"
"math"
"github.com/sirupsen/logrus"
"github.com/c9s/bbgo/pkg/exchange/bitget/bitgetapi"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
)
@ -43,3 +47,80 @@ func (e *Exchange) Name() types.ExchangeName {
func (e *Exchange) PlatformFeeCurrency() string {
return PlatformToken
}
func (e *Exchange) NewStream() types.Stream {
// TODO implement me
panic("implement me")
}
func (e *Exchange) QueryMarkets(ctx context.Context) (types.MarketMap, error) {
// TODO implement me
req := e.client.NewGetSymbolsRequest()
symbols, err := req.Do(ctx)
if err != nil {
return nil, err
}
markets := types.MarketMap{}
for _, s := range symbols {
symbol := toGlobalSymbol(s.Symbol)
markets[symbol] = types.Market{
Symbol: symbol,
LocalSymbol: s.Symbol,
PricePrecision: s.PriceScale,
VolumePrecision: s.QuantityScale,
QuoteCurrency: s.QuoteCoin,
BaseCurrency: s.BaseCoin,
MinNotional: s.MinTradeUSDT,
MinAmount: s.MinTradeUSDT,
MinQuantity: s.MinTradeAmount,
MaxQuantity: s.MaxTradeAmount,
StepSize: fixedpoint.NewFromFloat(math.Pow10(-s.QuantityScale)),
TickSize: fixedpoint.NewFromFloat(math.Pow10(-s.PriceScale)),
MinPrice: 0,
MaxPrice: 0,
}
}
return markets, nil
}
func (e *Exchange) QueryTicker(ctx context.Context, symbol string) (*types.Ticker, error) {
// TODO implement me
panic("implement me")
}
func (e *Exchange) QueryTickers(ctx context.Context, symbol ...string) (map[string]types.Ticker, error) {
// TODO implement me
panic("implement me")
}
func (e *Exchange) QueryKLines(ctx context.Context, symbol string, interval types.Interval, options types.KLineQueryOptions) ([]types.KLine, error) {
// TODO implement me
panic("implement me")
}
func (e *Exchange) QueryAccount(ctx context.Context) (*types.Account, error) {
// TODO implement me
panic("implement me")
}
func (e *Exchange) QueryAccountBalances(ctx context.Context) (types.BalanceMap, error) {
// TODO implement me
panic("implement me")
}
func (e *Exchange) SubmitOrder(ctx context.Context, order types.SubmitOrder) (createdOrder *types.Order, err error) {
// TODO implement me
panic("implement me")
}
func (e *Exchange) QueryOpenOrders(ctx context.Context, symbol string) (orders []types.Order, err error) {
// TODO implement me
panic("implement me")
}
func (e *Exchange) CancelOrders(ctx context.Context, orders ...types.Order) error {
// TODO implement me
panic("implement me")
}

View File

@ -47,11 +47,11 @@ type Market struct {
// 1.0 / math.Pow10(m.BaseUnitPrecision)
StepSize fixedpoint.Value `json:"stepSize,omitempty"`
MinPrice fixedpoint.Value `json:"minPrice,omitempty"`
MaxPrice fixedpoint.Value `json:"maxPrice,omitempty"`
// TickSize is the step size of price
TickSize fixedpoint.Value `json:"tickSize,omitempty"`
MinPrice fixedpoint.Value `json:"minPrice,omitempty"`
MaxPrice fixedpoint.Value `json:"maxPrice,omitempty"`
}
func (m Market) IsDustQuantity(quantity, price fixedpoint.Value) bool {