Merge pull request #1487 from c9s/c9s/bitget-ignore-offline-symbols

FIX: [bitget] ignore offline symbols
This commit is contained in:
c9s 2024-01-08 18:19:01 +08:00 committed by GitHub
commit 11309ac8c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 18 deletions

View File

@ -12,12 +12,14 @@ import (
type SymbolStatus string type SymbolStatus string
const ( const (
// SymbolOffline represent market is suspended, users cannot trade. // SymbolStatusOffline represent market is suspended, users cannot trade.
SymbolOffline SymbolStatus = "offline" SymbolStatusOffline SymbolStatus = "offline"
// SymbolGray represents market is online, but user trading is not available.
SymbolGray SymbolStatus = "gray" // SymbolStatusGray represents market is online, but user trading is not available.
// SymbolOnline trading begins, users can trade. SymbolStatusGray SymbolStatus = "gray"
SymbolOnline SymbolStatus = "online"
// SymbolStatusOnline trading begins, users can trade.
SymbolStatusOnline SymbolStatus = "online"
) )
type Symbol struct { type Symbol struct {

View File

@ -137,15 +137,29 @@ func (g *GetSymbolsRequest) Do(ctx context.Context) ([]Symbol, error) {
} }
var apiResponse bitgetapi.APIResponse var apiResponse bitgetapi.APIResponse
if err := response.DecodeJSON(&apiResponse); err != nil {
return nil, err type responseUnmarshaler interface {
Unmarshal(data []byte) error
}
if unmarshaler, ok := interface{}(&apiResponse).(responseUnmarshaler); ok {
if err := unmarshaler.Unmarshal(response.Body); err != nil {
return nil, err
}
} else {
// The line below checks the content type, however, some API server might not send the correct content type header,
// Hence, this is commented for backward compatibility
// response.IsJSON()
if err := response.DecodeJSON(&apiResponse); err != nil {
return nil, err
}
} }
type responseValidator interface { type responseValidator interface {
Validate() error Validate() error
} }
validator, ok := interface{}(apiResponse).(responseValidator)
if ok { if validator, ok := interface{}(&apiResponse).(responseValidator); ok {
if err := validator.Validate(); err != nil { if err := validator.Validate(); err != nil {
return nil, err return nil, err
} }

View File

@ -25,9 +25,10 @@ func toGlobalBalance(asset v2.AccountAsset) types.Balance {
} }
func toGlobalMarket(s v2.Symbol) types.Market { func toGlobalMarket(s v2.Symbol) types.Market {
if s.Status != v2.SymbolOnline { if s.Status != v2.SymbolStatusOnline {
log.Warnf("The symbol %s is not online", s.Symbol) log.Warnf("The market symbol status %s is not online: %s", s.Symbol, s.Status)
} }
return types.Market{ return types.Market{
Symbol: s.Symbol, Symbol: s.Symbol,
LocalSymbol: s.Symbol, LocalSymbol: s.Symbol,

View File

@ -44,7 +44,7 @@ func Test_toGlobalBalance(t *testing.T) {
func Test_toGlobalMarket(t *testing.T) { func Test_toGlobalMarket(t *testing.T) {
// sample: // sample:
//{ // {
// "symbol":"BTCUSDT", // "symbol":"BTCUSDT",
// "baseCoin":"BTC", // "baseCoin":"BTC",
// "quoteCoin":"USDT", // "quoteCoin":"USDT",
@ -59,7 +59,7 @@ func Test_toGlobalMarket(t *testing.T) {
// "minTradeUSDT":"5", // "minTradeUSDT":"5",
// "buyLimitPriceRatio":"0.05", // "buyLimitPriceRatio":"0.05",
// "sellLimitPriceRatio":"0.05" // "sellLimitPriceRatio":"0.05"
//} // }
inst := v2.Symbol{ inst := v2.Symbol{
Symbol: "BTCUSDT", Symbol: "BTCUSDT",
BaseCoin: "BTC", BaseCoin: "BTC",
@ -72,7 +72,7 @@ func Test_toGlobalMarket(t *testing.T) {
QuantityPrecision: fixedpoint.NewFromFloat(4), QuantityPrecision: fixedpoint.NewFromFloat(4),
QuotePrecision: fixedpoint.NewFromFloat(6), QuotePrecision: fixedpoint.NewFromFloat(6),
MinTradeUSDT: fixedpoint.NewFromFloat(5), MinTradeUSDT: fixedpoint.NewFromFloat(5),
Status: v2.SymbolOnline, Status: v2.SymbolStatusOnline,
BuyLimitPriceRatio: fixedpoint.NewFromFloat(0.05), BuyLimitPriceRatio: fixedpoint.NewFromFloat(0.05),
SellLimitPriceRatio: fixedpoint.NewFromFloat(0.05), SellLimitPriceRatio: fixedpoint.NewFromFloat(0.05),
} }
@ -99,7 +99,7 @@ func Test_toGlobalMarket(t *testing.T) {
func Test_toGlobalTicker(t *testing.T) { func Test_toGlobalTicker(t *testing.T) {
// sample: // sample:
//{ // {
// "open":"36465.96", // "open":"36465.96",
// "symbol":"BTCUSDT", // "symbol":"BTCUSDT",
// "high24h":"37040.25", // "high24h":"37040.25",
@ -116,7 +116,7 @@ func Test_toGlobalTicker(t *testing.T) {
// "openUtc":"36465.96", // "openUtc":"36465.96",
// "changeUtc24h":"0.00599", // "changeUtc24h":"0.00599",
// "change24h":"-0.00426" // "change24h":"-0.00426"
//} // }
ticker := v2.Ticker{ ticker := v2.Ticker{
Symbol: "BTCUSDT", Symbol: "BTCUSDT",
High24H: fixedpoint.NewFromFloat(24175.65), High24H: fixedpoint.NewFromFloat(24175.65),
@ -540,7 +540,7 @@ func Test_toGlobalTrade(t *testing.T) {
// "tradeScope":"taker", // "tradeScope":"taker",
// "cTime":"1699020564676", // "cTime":"1699020564676",
// "uTime":"1699020564687" // "uTime":"1699020564687"
//} // }
trade := v2.Trade{ trade := v2.Trade{
UserId: types.StrInt64(8672173294), UserId: types.StrInt64(8672173294),
Symbol: "APEUSDT", Symbol: "APEUSDT",

View File

@ -111,6 +111,11 @@ func (e *Exchange) QueryMarkets(ctx context.Context) (types.MarketMap, error) {
markets := types.MarketMap{} markets := types.MarketMap{}
for _, s := range symbols { for _, s := range symbols {
if s.Status == v2.SymbolStatusOffline {
// ignore offline symbols
continue
}
markets[s.Symbol] = toGlobalMarket(s) markets[s.Symbol] = toGlobalMarket(s)
} }