mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-23 07:26:47 +00:00
bybit/buf: Fix test issues (#1073)
* bybit/buf: Fix issues * Update exchanges/bybit/futures_type.go Co-authored-by: Scott <gloriousCode@users.noreply.github.com> * Address nitters Co-authored-by: Scott <gloriousCode@users.noreply.github.com>
This commit is contained in:
@@ -299,24 +299,12 @@ func (by *Bybit) GetKlines(ctx context.Context, symbol, period string, limit int
|
||||
}
|
||||
kline.TradesCount = int64(tradesCount)
|
||||
|
||||
takerBaseVolume, ok := resp.Data[x][9].(string)
|
||||
if !ok {
|
||||
if kline.TakerBaseVolume, ok = resp.Data[x][9].(float64); !ok {
|
||||
return klines, fmt.Errorf("%v GetKlines: %w for TakerBaseVolume", by.Name, errTypeAssert)
|
||||
}
|
||||
kline.TakerBaseVolume, err = strconv.ParseFloat(takerBaseVolume, 64)
|
||||
if err != nil {
|
||||
return klines, fmt.Errorf("%v GetKlines: %w for TakerBaseVolume", by.Name, errStrParsing)
|
||||
}
|
||||
|
||||
takerQuoteVolume, ok := resp.Data[x][10].(string)
|
||||
if !ok {
|
||||
if kline.TakerQuoteVolume, ok = resp.Data[x][10].(float64); !ok {
|
||||
return klines, fmt.Errorf("%v GetKlines: %w for TakerQuoteVolume", by.Name, errTypeAssert)
|
||||
}
|
||||
kline.TakerQuoteVolume, err = strconv.ParseFloat(takerQuoteVolume, 64)
|
||||
if err != nil {
|
||||
return klines, fmt.Errorf("%v GetKlines: %w for TakerQuoteVolume", by.Name, errStrParsing)
|
||||
}
|
||||
|
||||
klines[x] = kline
|
||||
}
|
||||
return klines, nil
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/kline"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
@@ -48,6 +49,7 @@ func TestMain(m *testing.M) {
|
||||
exchCfg.API.Credentials.Key = apiKey
|
||||
exchCfg.API.Credentials.Secret = apiSecret
|
||||
b.Websocket = sharedtestvalues.NewTestWebsocket()
|
||||
request.MaxRequestJobs = 100
|
||||
err = b.Setup(exchCfg)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
||||
@@ -149,6 +149,34 @@ func (b bybitTimeNanoSec) Time() time.Time {
|
||||
return time.Time(b)
|
||||
}
|
||||
|
||||
// bybitNumericalValue is a type used for when the API returns an empty or
|
||||
// numerical string
|
||||
type bybitNumericalValue float64
|
||||
|
||||
// UnmarshalJSON is custom type json unmarshaller for bybitNumericalValue
|
||||
func (b *bybitNumericalValue) UnmarshalJSON(data []byte) error {
|
||||
var num string
|
||||
err := json.Unmarshal(data, &num)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if num == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
v, err := strconv.ParseFloat(num, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*b = bybitNumericalValue(v)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Float64 returns a float64 value for bybitNumericalValue
|
||||
func (b *bybitNumericalValue) Float64() float64 { return float64(*b) }
|
||||
|
||||
// UnmarshalTo acts as interface to exchange API response
|
||||
type UnmarshalTo interface {
|
||||
GetError() error
|
||||
|
||||
@@ -464,7 +464,7 @@ func (by *Bybit) UpdateTickers(ctx context.Context, assetType asset.Item) error
|
||||
Bid: tick[y].BidPrice,
|
||||
Ask: tick[y].AskPrice,
|
||||
Volume: tick[y].Volume24h,
|
||||
Open: tick[y].OpenValue,
|
||||
Open: tick[y].OpenValue.Float64(),
|
||||
Pair: cp,
|
||||
ExchangeName: by.Name,
|
||||
AssetType: assetType})
|
||||
@@ -567,7 +567,7 @@ func (by *Bybit) UpdateTicker(ctx context.Context, p currency.Pair, assetType as
|
||||
Bid: tick[y].BidPrice,
|
||||
Ask: tick[y].AskPrice,
|
||||
Volume: tick[y].Volume24h,
|
||||
Open: tick[y].OpenValue,
|
||||
Open: tick[y].OpenValue.Float64(),
|
||||
Pair: cp,
|
||||
ExchangeName: by.Name,
|
||||
AssetType: assetType})
|
||||
|
||||
@@ -51,32 +51,32 @@ type FuturesCandleStickWithStringParam struct {
|
||||
|
||||
// SymbolPriceTicker stores ticker price stats
|
||||
type SymbolPriceTicker struct {
|
||||
Symbol string `json:"symbol"`
|
||||
BidPrice float64 `json:"bid_price,string"`
|
||||
AskPrice float64 `json:"ask_price,string"`
|
||||
LastPrice float64 `json:"last_price,string"`
|
||||
LastTickDirection string `json:"last_tick_direction"`
|
||||
Price24hAgo float64 `json:"prev_price_24h,string"`
|
||||
PricePcntChange24h float64 `json:"price_24h_pcnt,string"`
|
||||
HighPrice24h float64 `json:"high_price_24h,string"`
|
||||
LowPrice24h float64 `json:"low_price_24h,string"`
|
||||
Price1hAgo float64 `json:"prev_price_1h,string"`
|
||||
PricePcntChange1h float64 `json:"price_1h_pcnt,string"`
|
||||
MarkPrice float64 `json:"mark_price,string"`
|
||||
IndexPrice float64 `json:"index_price,string"`
|
||||
OpenInterest float64 `json:"open_interest"`
|
||||
OpenValue float64 `json:"open_value,string"`
|
||||
TotalTurnover float64 `json:"total_turnover,string"`
|
||||
Turnover24h float64 `json:"turnover_24h,string"`
|
||||
TotalVolume float64 `json:"total_volume"`
|
||||
Volume24h float64 `json:"volume_24h"`
|
||||
FundingRate float64 `json:"funding_rate,string"`
|
||||
PredictedFundingRate float64 `json:"predicted_funding_rate,string"`
|
||||
NextFundingTime string `json:"next_funding_time"`
|
||||
CountdownHour int64 `json:"countdown_hour"`
|
||||
DeliveryFeeRate string `json:"delivery_fee_rate"` // type is string because it comes as empty string in API response sometime
|
||||
PredictedDeliveryPrice string `json:"predicted_delivery_price"` // type is string because it comes as empty string in API response sometime
|
||||
DeliveryTime string `json:"delivery_time"`
|
||||
Symbol string `json:"symbol"`
|
||||
BidPrice float64 `json:"bid_price,string"`
|
||||
AskPrice float64 `json:"ask_price,string"`
|
||||
LastPrice float64 `json:"last_price,string"`
|
||||
LastTickDirection string `json:"last_tick_direction"`
|
||||
Price24hAgo float64 `json:"prev_price_24h,string"`
|
||||
PricePcntChange24h float64 `json:"price_24h_pcnt,string"`
|
||||
HighPrice24h float64 `json:"high_price_24h,string"`
|
||||
LowPrice24h float64 `json:"low_price_24h,string"`
|
||||
Price1hAgo float64 `json:"prev_price_1h,string"`
|
||||
PricePcntChange1h bybitNumericalValue `json:"price_1h_pcnt"`
|
||||
MarkPrice float64 `json:"mark_price,string"`
|
||||
IndexPrice float64 `json:"index_price,string"`
|
||||
OpenInterest float64 `json:"open_interest"`
|
||||
OpenValue bybitNumericalValue `json:"open_value"`
|
||||
TotalTurnover bybitNumericalValue `json:"total_turnover"`
|
||||
Turnover24h float64 `json:"turnover_24h,string"`
|
||||
TotalVolume float64 `json:"total_volume"`
|
||||
Volume24h float64 `json:"volume_24h"`
|
||||
FundingRate float64 `json:"funding_rate,string"`
|
||||
PredictedFundingRate bybitNumericalValue `json:"predicted_funding_rate"`
|
||||
NextFundingTime string `json:"next_funding_time"`
|
||||
CountdownHour int64 `json:"countdown_hour"`
|
||||
DeliveryFeeRate bybitNumericalValue `json:"delivery_fee_rate"`
|
||||
PredictedDeliveryPrice bybitNumericalValue `json:"predicted_delivery_price"`
|
||||
DeliveryTime string `json:"delivery_time"`
|
||||
}
|
||||
|
||||
// FuturesPublicTradesData stores recent public trades for futures
|
||||
@@ -149,10 +149,11 @@ type OpenInterestData struct {
|
||||
|
||||
// BigDealData stores big deal data
|
||||
type BigDealData struct {
|
||||
Symbol string `json:"symbol"`
|
||||
Side string `json:"side"`
|
||||
Time int64 `json:"timestamp"`
|
||||
Value int64 `json:"value"`
|
||||
ID int64 `json:"id"`
|
||||
Symbol string `json:"symbol"`
|
||||
Side string `json:"side"`
|
||||
Time int64 `json:"timestamp"`
|
||||
Value float64 `json:"value"`
|
||||
}
|
||||
|
||||
// AccountRatioData stores user accounts long short ratio
|
||||
|
||||
Reference in New Issue
Block a user