gate.io: Enforce the use of 'convert.StringToFloat64' and permit its use in outbound requests (#1308)

Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
This commit is contained in:
Ryan O'Hara-Reid
2023-09-18 17:15:27 +10:00
committed by GitHub
parent 78fe6d5e79
commit 8b8d96c612
9 changed files with 1140 additions and 1100 deletions

View File

@@ -222,6 +222,15 @@ func (f *StringToFloat64) UnmarshalJSON(data []byte) error {
return nil
}
// MarshalJSON implements the json.Marshaler interface.
func (f StringToFloat64) MarshalJSON() ([]byte, error) {
if f == 0 {
return []byte(jsonStringIdent + jsonStringIdent), nil
}
val := strconv.FormatFloat(float64(f), 'f', -1, 64)
return []byte(jsonStringIdent + val + jsonStringIdent), nil
}
// Float64 returns the float64 value of the FloatString.
func (f *StringToFloat64) Float64() float64 {
return float64(*f)

View File

@@ -353,6 +353,24 @@ func TestStringToFloat64(t *testing.T) {
if err == nil {
t.Fatal("error cannot be nil")
}
data, err := json.Marshal(StringToFloat64(0))
if err != nil {
t.Fatal(err)
}
if string(data) != `""` {
t.Fatalf("expected empty string, got %v", string(data))
}
data, err = json.Marshal(StringToFloat64(1337.1337))
if err != nil {
t.Fatal(err)
}
if string(data) != `"1337.1337"` {
t.Fatalf("expected \"1337.1337\" string, got %v", string(data))
}
}
func TestStringToFloat64Decimal(t *testing.T) {

View File

@@ -3796,11 +3796,11 @@ func (g *Gateio) GetFee(ctx context.Context, feeBuilder *exchange.FeeBuilder) (f
return 0, err
}
if feeBuilder.IsMaker {
fee = calculateTradingFee(feePairs.MakerFee,
fee = calculateTradingFee(feePairs.MakerFee.Float64(),
feeBuilder.PurchasePrice,
feeBuilder.Amount)
} else {
fee = calculateTradingFee(feePairs.TakerFee,
fee = calculateTradingFee(feePairs.TakerFee.Float64(),
feeBuilder.PurchasePrice,
feeBuilder.Amount)
}

View File

@@ -3386,3 +3386,14 @@ func TestUpdateOrderExecutionLimits(t *testing.T) {
}
}
}
func TestForceFileStandard(t *testing.T) {
t.Parallel()
err := sharedtestvalues.ForceFileStandard(t, sharedtestvalues.EmptyStringPotentialPattern)
if err != nil {
t.Error(err)
}
if t.Failed() {
t.Fatal("Please use convert.StringToFloat64 type instead of `float64` and remove `,string` as strings can be empty in unmarshal process. Then call the Float64() method.")
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -167,13 +167,13 @@ func (g *Gateio) processTicker(incoming []byte, pushTime int64) error {
}
tickerPrice := ticker.Price{
ExchangeName: g.Name,
Volume: data.BaseVolume,
QuoteVolume: data.QuoteVolume,
High: data.High24H,
Low: data.Low24H,
Last: data.Last,
Bid: data.HighestBid,
Ask: data.LowestAsk,
Volume: data.BaseVolume.Float64(),
QuoteVolume: data.QuoteVolume.Float64(),
High: data.High24H.Float64(),
Low: data.Low24H.Float64(),
Last: data.Last.Float64(),
Bid: data.HighestBid.Float64(),
Ask: data.LowestAsk.Float64(),
AssetType: asset.Spot,
Pair: data.CurrencyPair,
LastUpdated: time.Unix(pushTime, 0),
@@ -216,8 +216,8 @@ func (g *Gateio) processTrades(incoming []byte) error {
CurrencyPair: data.CurrencyPair,
AssetType: asset.Spot,
Exchange: g.Name,
Price: data.Price,
Amount: data.Amount,
Price: data.Price.Float64(),
Amount: data.Amount.Float64(),
Side: side,
TID: strconv.FormatInt(data.ID, 10),
}
@@ -254,11 +254,11 @@ func (g *Gateio) processCandlestick(incoming []byte) error {
Exchange: g.Name,
StartTime: time.Unix(data.Timestamp, 0),
Interval: icp[0],
OpenPrice: data.OpenPrice,
ClosePrice: data.ClosePrice,
HighPrice: data.HighestPrice,
LowPrice: data.LowestPrice,
Volume: data.TotalVolume,
OpenPrice: data.OpenPrice.Float64(),
ClosePrice: data.ClosePrice.Float64(),
HighPrice: data.HighestPrice.Float64(),
LowPrice: data.LowestPrice.Float64(),
Volume: data.TotalVolume.Float64(),
}
assetPairEnabled := g.listOfAssetsCurrencyPairEnabledFor(currencyPair)
if assetPairEnabled[asset.Spot] {
@@ -289,8 +289,8 @@ func (g *Gateio) processOrderbookTicker(incoming []byte) error {
Pair: data.CurrencyPair,
Asset: asset.Spot,
LastUpdated: time.UnixMilli(data.UpdateTimeMS),
Bids: []orderbook.Item{{Price: data.BestBidPrice, Amount: data.BestBidAmount}},
Asks: []orderbook.Item{{Price: data.BestAskPrice, Amount: data.BestAskAmount}},
Bids: []orderbook.Item{{Price: data.BestBidPrice.Float64(), Amount: data.BestBidAmount.Float64()}},
Asks: []orderbook.Item{{Price: data.BestAskPrice.Float64(), Amount: data.BestAskAmount.Float64()}},
})
}
@@ -464,16 +464,16 @@ func (g *Gateio) processSpotOrders(data []byte) error {
return err
}
details[x] = order.Detail{
Amount: resp.Result[x].Amount,
Amount: resp.Result[x].Amount.Float64(),
Exchange: g.Name,
OrderID: resp.Result[x].ID,
Side: side,
Type: orderType,
Pair: resp.Result[x].CurrencyPair,
Cost: resp.Result[x].Fee,
Cost: resp.Result[x].Fee.Float64(),
AssetType: a,
Price: resp.Result[x].Price,
ExecutedAmount: resp.Result[x].Amount - resp.Result[x].Left.Float64(),
Price: resp.Result[x].Price.Float64(),
ExecutedAmount: resp.Result[x].Amount.Float64() - resp.Result[x].Left.Float64(),
Date: resp.Result[x].CreateTimeMs.Time(),
LastUpdated: resp.Result[x].UpdateTimeMs.Time(),
}
@@ -510,8 +510,8 @@ func (g *Gateio) processUserPersonalTrades(data []byte) error {
Side: side,
OrderID: resp.Result[x].OrderID,
TradeID: strconv.FormatInt(resp.Result[x].ID, 10),
Price: resp.Result[x].Price,
Amount: resp.Result[x].Amount,
Price: resp.Result[x].Price.Float64(),
Amount: resp.Result[x].Amount.Float64(),
}
}
return g.Websocket.Fills.Update(fills...)
@@ -535,7 +535,7 @@ func (g *Gateio) processSpotBalances(data []byte) error {
Exchange: g.Name,
Currency: code,
Asset: asset.Spot,
Amount: resp.Result[x].Available,
Amount: resp.Result[x].Available.Float64(),
}
}
g.Websocket.DataHandler <- accountChanges
@@ -560,7 +560,7 @@ func (g *Gateio) processMarginBalances(data []byte) error {
Exchange: g.Name,
Currency: code,
Asset: asset.Margin,
Amount: resp.Result[x].Available,
Amount: resp.Result[x].Available.Float64(),
}
}
g.Websocket.DataHandler <- accountChange
@@ -600,7 +600,7 @@ func (g *Gateio) processCrossMarginBalance(data []byte) error {
Exchange: g.Name,
Currency: code,
Asset: asset.Margin,
Amount: resp.Result[x].Available,
Amount: resp.Result[x].Available.Float64(),
Account: resp.Result[x].User,
}
}

View File

@@ -12,6 +12,7 @@ import (
"time"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/convert"
"github.com/thrasher-corp/gocryptotrader/config"
"github.com/thrasher-corp/gocryptotrader/currency"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
@@ -312,11 +313,11 @@ func (g *Gateio) UpdateTicker(ctx context.Context, p currency.Pair, a asset.Item
}
tickerData = &ticker.Price{
Pair: fPair,
Low: tick.Low24H,
High: tick.High24H,
Last: tick.Last,
Volume: tick.Volume24HBase,
QuoteVolume: tick.Volume24HQuote,
Low: tick.Low24H.Float64(),
High: tick.High24H.Float64(),
Last: tick.Last.Float64(),
Volume: tick.Volume24HBase.Float64(),
QuoteVolume: tick.Volume24HQuote.Float64(),
ExchangeName: g.Name,
AssetType: a,
}
@@ -343,8 +344,8 @@ func (g *Gateio) UpdateTicker(ctx context.Context, p currency.Pair, a asset.Item
tickerData = &ticker.Price{
Pair: tickers[x].Name,
Last: tickers[x].LastPrice.Float64(),
Bid: tickers[x].Bid1Price,
Ask: tickers[x].Ask1Price,
Bid: tickers[x].Bid1Price.Float64(),
Ask: tickers[x].Ask1Price.Float64(),
AskSize: tickers[x].Ask1Size,
BidSize: tickers[x].Bid1Size,
ExchangeName: g.Name,
@@ -371,11 +372,11 @@ func (g *Gateio) UpdateTicker(ctx context.Context, p currency.Pair, a asset.Item
if tickers[x].Contract == fPair.Upper().String() {
tickerData = &ticker.Price{
Pair: fPair,
Last: tickers[x].Last,
High: tickers[x].High24H,
Low: tickers[x].Low24H,
Volume: tickers[x].Volume24H,
QuoteVolume: tickers[x].Volume24HQuote,
Last: tickers[x].Last.Float64(),
High: tickers[x].High24H.Float64(),
Low: tickers[x].Low24H.Float64(),
Volume: tickers[x].Volume24H.Float64(),
QuoteVolume: tickers[x].Volume24HQuote.Float64(),
ExchangeName: g.Name,
AssetType: a,
}
@@ -613,11 +614,11 @@ func (g *Gateio) UpdateTickers(ctx context.Context, a asset.Item) error {
return err
}
err = ticker.ProcessTicker(&ticker.Price{
Last: tickers[x].Last,
High: tickers[x].High24H,
Low: tickers[x].Low24H,
Volume: tickers[x].Volume24H,
QuoteVolume: tickers[x].Volume24HQuote,
Last: tickers[x].Last.Float64(),
High: tickers[x].High24H.Float64(),
Low: tickers[x].Low24H.Float64(),
Volume: tickers[x].Volume24H.Float64(),
QuoteVolume: tickers[x].Volume24HQuote.Float64(),
ExchangeName: g.Name,
Pair: currencyPair,
AssetType: a,
@@ -643,9 +644,9 @@ func (g *Gateio) UpdateTickers(ctx context.Context, a asset.Item) error {
for x := range tickers {
err = ticker.ProcessTicker(&ticker.Price{
Last: tickers[x].LastPrice.Float64(),
Ask: tickers[x].Ask1Price,
Ask: tickers[x].Ask1Price.Float64(),
AskSize: tickers[x].Ask1Size,
Bid: tickers[x].Bid1Price,
Bid: tickers[x].Bid1Price.Float64(),
BidSize: tickers[x].Bid1Size,
Pair: tickers[x].Name,
ExchangeName: g.Name,
@@ -756,9 +757,9 @@ func (g *Gateio) UpdateAccountInfo(ctx context.Context, a asset.Item) (account.H
for x := range balances {
currencies[x] = account.Balance{
Currency: currency.NewCode(balances[x].Currency),
Total: balances[x].Available - balances[x].Locked,
Hold: balances[x].Locked,
Free: balances[x].Available,
Total: balances[x].Available.Float64() - balances[x].Locked.Float64(),
Hold: balances[x].Locked.Float64(),
Free: balances[x].Available.Float64(),
}
}
info.Accounts = append(info.Accounts, account.SubAccount{
@@ -775,14 +776,14 @@ func (g *Gateio) UpdateAccountInfo(ctx context.Context, a asset.Item) (account.H
for x := range balances {
currencies = append(currencies, account.Balance{
Currency: currency.NewCode(balances[x].Base.Currency),
Total: balances[x].Base.Available + balances[x].Base.LockedAmount,
Hold: balances[x].Base.LockedAmount,
Free: balances[x].Base.Available,
Total: balances[x].Base.Available.Float64() + balances[x].Base.LockedAmount.Float64(),
Hold: balances[x].Base.LockedAmount.Float64(),
Free: balances[x].Base.Available.Float64(),
}, account.Balance{
Currency: currency.NewCode(balances[x].Quote.Currency),
Total: balances[x].Quote.Available + balances[x].Quote.LockedAmount,
Hold: balances[x].Quote.LockedAmount,
Free: balances[x].Quote.Available,
Total: balances[x].Quote.Available.Float64() + balances[x].Quote.LockedAmount.Float64(),
Hold: balances[x].Quote.LockedAmount.Float64(),
Free: balances[x].Quote.Available.Float64(),
})
}
info.Accounts = append(info.Accounts, account.SubAccount{
@@ -807,9 +808,9 @@ func (g *Gateio) UpdateAccountInfo(ctx context.Context, a asset.Item) (account.H
}
currencies[x] = account.Balance{
Currency: currency.NewCode(balance.Currency),
Total: balance.Total,
Hold: balance.Total - balance.Available,
Free: balance.Available,
Total: balance.Total.Float64(),
Hold: balance.Total.Float64() - balance.Available.Float64(),
Free: balance.Available.Float64(),
}
}
info.Accounts = append(info.Accounts, account.SubAccount{
@@ -827,9 +828,9 @@ func (g *Gateio) UpdateAccountInfo(ctx context.Context, a asset.Item) (account.H
Currencies: []account.Balance{
{
Currency: currency.NewCode(balance.Currency),
Total: balance.Total,
Hold: balance.Total - balance.Available,
Free: balance.Available,
Total: balance.Total.Float64(),
Hold: balance.Total.Float64() - balance.Available.Float64(),
Free: balance.Available.Float64(),
},
},
})
@@ -878,7 +879,7 @@ func (g *Gateio) GetWithdrawalsHistory(ctx context.Context, c currency.Code, _ a
Status: records[x].Status,
TransferID: records[x].ID,
Currency: records[x].Currency,
Amount: records[x].Amount,
Amount: records[x].Amount.Float64(),
CryptoTxID: records[x].TransactionID,
CryptoToAddress: records[x].WithdrawalAddress,
Timestamp: records[x].Timestamp.Time(),
@@ -917,8 +918,8 @@ func (g *Gateio) GetRecentTrades(ctx context.Context, p currency.Pair, a asset.I
CurrencyPair: p,
AssetType: a,
Side: side,
Price: tradeData[i].Price,
Amount: tradeData[i].Amount,
Price: tradeData[i].Price.Float64(),
Amount: tradeData[i].Amount.Float64(),
Timestamp: tradeData[i].CreateTimeMs.Time(),
}
}
@@ -940,7 +941,7 @@ func (g *Gateio) GetRecentTrades(ctx context.Context, p currency.Pair, a asset.I
Exchange: g.Name,
CurrencyPair: p,
AssetType: a,
Price: futuresTrades[i].Price,
Price: futuresTrades[i].Price.Float64(),
Amount: futuresTrades[i].Size,
Timestamp: futuresTrades[i].CreateTime.Time(),
}
@@ -963,7 +964,7 @@ func (g *Gateio) GetRecentTrades(ctx context.Context, p currency.Pair, a asset.I
Exchange: g.Name,
CurrencyPair: p,
AssetType: a,
Price: deliveryTrades[i].Price,
Price: deliveryTrades[i].Price.Float64(),
Amount: deliveryTrades[i].Size,
Timestamp: deliveryTrades[i].CreateTime.Time(),
}
@@ -981,7 +982,7 @@ func (g *Gateio) GetRecentTrades(ctx context.Context, p currency.Pair, a asset.I
Exchange: g.Name,
CurrencyPair: p,
AssetType: a,
Price: trades[i].Price,
Price: trades[i].Price.Float64(),
Amount: trades[i].Size,
Timestamp: trades[i].CreateTime.Time(),
}
@@ -1032,8 +1033,8 @@ func (g *Gateio) SubmitOrder(ctx context.Context, s *order.Submit) (*order.Submi
Side: orderTypeFormat,
Type: s.Type.Lower(),
Account: g.assetTypeToString(s.AssetType),
Amount: s.Amount,
Price: s.Price,
Amount: convert.StringToFloat64(s.Amount),
Price: convert.StringToFloat64(s.Price),
CurrencyPair: s.Pair,
Text: s.ClientOrderID,
})
@@ -1054,7 +1055,7 @@ func (g *Gateio) SubmitOrder(ctx context.Context, s *order.Submit) (*order.Submi
return nil, err
}
response.Status = status
response.Fee = sOrder.FeeDeducted
response.Fee = sOrder.FeeDeducted.Float64()
response.FeeAsset = currency.NewCode(sOrder.FeeCurrency)
response.Pair = s.Pair
response.Date = sOrder.CreateTime.Time()
@@ -1075,7 +1076,7 @@ func (g *Gateio) SubmitOrder(ctx context.Context, s *order.Submit) (*order.Submi
fOrder, err := g.PlaceFuturesOrder(ctx, &OrderCreateParams{
Contract: s.Pair,
Size: s.Amount,
Price: s.Price,
Price: convert.StringToFloat64(s.Price),
Settle: settle,
ReduceOnly: s.ReduceOnly,
TimeInForce: "gtc",
@@ -1112,7 +1113,7 @@ func (g *Gateio) SubmitOrder(ctx context.Context, s *order.Submit) (*order.Submi
newOrder, err := g.PlaceDeliveryOrder(ctx, &OrderCreateParams{
Contract: s.Pair,
Size: s.Amount,
Price: s.Price,
Price: convert.StringToFloat64(s.Price),
Settle: settle,
ReduceOnly: s.ReduceOnly,
TimeInForce: "gtc",
@@ -1134,13 +1135,13 @@ func (g *Gateio) SubmitOrder(ctx context.Context, s *order.Submit) (*order.Submi
response.Date = newOrder.CreateTime.Time()
response.ClientOrderID = newOrder.Text
response.Amount = newOrder.Size
response.Price = newOrder.OrderPrice
response.Price = newOrder.OrderPrice.Float64()
return response, nil
case asset.Options:
optionOrder, err := g.PlaceOptionOrder(ctx, OptionOrderParam{
Contract: s.Pair.String(),
OrderSize: s.Amount,
Price: s.Price,
Price: convert.StringToFloat64(s.Price),
ReduceOnly: s.ReduceOnly,
Text: s.ClientOrderID,
})
@@ -1409,17 +1410,17 @@ func (g *Gateio) GetOrderInfo(ctx context.Context, orderID string, pair currency
return nil, err
}
return &order.Detail{
Amount: spotOrder.Amount,
Amount: spotOrder.Amount.Float64(),
Exchange: g.Name,
OrderID: spotOrder.OrderID,
Side: side,
Type: orderType,
Pair: pair,
Cost: spotOrder.FeeDeducted,
Cost: spotOrder.FeeDeducted.Float64(),
AssetType: a,
Status: orderStatus,
Price: spotOrder.Price,
ExecutedAmount: spotOrder.Amount - spotOrder.Left.Float64(),
Price: spotOrder.Price.Float64(),
ExecutedAmount: spotOrder.Amount.Float64() - spotOrder.Left.Float64(),
Date: spotOrder.CreateTimeMs.Time(),
LastUpdated: spotOrder.UpdateTimeMs.Time(),
}, nil
@@ -1457,7 +1458,7 @@ func (g *Gateio) GetOrderInfo(ctx context.Context, orderID string, pair currency
Exchange: g.Name,
OrderID: orderID,
Status: orderStatus,
Price: fOrder.OrderPrice,
Price: fOrder.OrderPrice.Float64(),
Date: fOrder.CreateTime.Time(),
LastUpdated: fOrder.FinishTime.Time(),
Pair: pair,
@@ -1482,7 +1483,7 @@ func (g *Gateio) GetOrderInfo(ctx context.Context, orderID string, pair currency
Exchange: g.Name,
OrderID: orderID,
Status: orderStatus,
Price: optionOrder.Price,
Price: optionOrder.Price.Float64(),
Date: optionOrder.CreateTime.Time(),
LastUpdated: optionOrder.FinishTime.Time(),
Pair: pair,
@@ -1528,7 +1529,7 @@ func (g *Gateio) WithdrawCryptocurrencyFunds(ctx context.Context, withdrawReques
}
response, err := g.WithdrawCurrency(ctx,
WithdrawalRequestParam{
Amount: withdrawRequest.Amount,
Amount: convert.StringToFloat64(withdrawRequest.Amount),
Currency: withdrawRequest.Currency,
Address: withdrawRequest.Crypto.Address,
Chain: withdrawRequest.Crypto.Chain,
@@ -1614,11 +1615,11 @@ func (g *Gateio) GetActiveOrders(ctx context.Context, req *order.MultiOrderReque
Status: status,
Pair: symbol,
OrderID: spotOrders[x].Orders[y].OrderID,
Amount: spotOrders[x].Orders[y].Amount,
ExecutedAmount: spotOrders[x].Orders[y].Amount - spotOrders[x].Orders[y].Left.Float64(),
Amount: spotOrders[x].Orders[y].Amount.Float64(),
ExecutedAmount: spotOrders[x].Orders[y].Amount.Float64() - spotOrders[x].Orders[y].Left.Float64(),
RemainingAmount: spotOrders[x].Orders[y].Left.Float64(),
Price: spotOrders[x].Orders[y].Price,
AverageExecutedPrice: spotOrders[x].Orders[y].AverageFillPrice,
Price: spotOrders[x].Orders[y].Price.Float64(),
AverageExecutedPrice: spotOrders[x].Orders[y].AverageFillPrice.Float64(),
Date: spotOrders[x].Orders[y].CreateTimeMs.Time(),
LastUpdated: spotOrders[x].Orders[y].UpdateTimeMs.Time(),
Exchange: g.Name,
@@ -1665,7 +1666,7 @@ func (g *Gateio) GetActiveOrders(ctx context.Context, req *order.MultiOrderReque
Amount: futuresOrders[x].Size,
Pair: req.Pairs[x],
OrderID: strconv.FormatInt(futuresOrders[x].ID, 10),
Price: futuresOrders[x].OrderPrice,
Price: futuresOrders[x].OrderPrice.Float64(),
ExecutedAmount: futuresOrders[x].Size - futuresOrders[x].RemainingAmount,
RemainingAmount: futuresOrders[x].RemainingAmount,
LastUpdated: futuresOrders[x].FinishTime.Time(),
@@ -1698,7 +1699,7 @@ func (g *Gateio) GetActiveOrders(ctx context.Context, req *order.MultiOrderReque
Amount: optionsOrders[x].Size,
Pair: currencyPair,
OrderID: strconv.FormatInt(optionsOrders[x].OptionOrderID, 10),
Price: optionsOrders[x].Price,
Price: optionsOrders[x].Price.Float64(),
ExecutedAmount: optionsOrders[x].Size - optionsOrders[x].Left,
RemainingAmount: optionsOrders[x].Left,
LastUpdated: optionsOrders[x].FinishTime.Time(),
@@ -1743,15 +1744,15 @@ func (g *Gateio) GetOrderHistory(ctx context.Context, req *order.MultiOrderReque
}
detail := order.Detail{
OrderID: spotOrders[o].OrderID,
Amount: spotOrders[o].Amount,
ExecutedAmount: spotOrders[o].Amount,
Price: spotOrders[o].Price,
Amount: spotOrders[o].Amount.Float64(),
ExecutedAmount: spotOrders[o].Amount.Float64(),
Price: spotOrders[o].Price.Float64(),
Date: spotOrders[o].CreateTime.Time(),
Side: side,
Exchange: g.Name,
Pair: fPair,
AssetType: req.AssetType,
Fee: spotOrders[o].Fee,
Fee: spotOrders[o].Fee.Float64(),
FeeAsset: currency.NewCode(spotOrders[o].FeeCurrency),
}
detail.InferCostsAndTimes()
@@ -1786,7 +1787,7 @@ func (g *Gateio) GetOrderHistory(ctx context.Context, req *order.MultiOrderReque
detail := order.Detail{
OrderID: strconv.FormatInt(futuresOrder[o].ID, 10),
Amount: futuresOrder[o].Size,
Price: futuresOrder[o].Price,
Price: futuresOrder[o].Price.Float64(),
Date: futuresOrder[o].CreateTime.Time(),
Exchange: g.Name,
Pair: fPair,
@@ -1808,7 +1809,7 @@ func (g *Gateio) GetOrderHistory(ctx context.Context, req *order.MultiOrderReque
detail := order.Detail{
OrderID: strconv.FormatInt(optionOrders[o].OrderID, 10),
Amount: optionOrders[o].Size,
Price: optionOrders[o].Price,
Price: optionOrders[o].Price.Float64(),
Date: optionOrders[o].CreateTime.Time(),
Exchange: g.Name,
Pair: fPair,
@@ -1875,10 +1876,10 @@ func (g *Gateio) GetHistoricCandles(ctx context.Context, pair currency.Pair, a a
for x := range candles {
listCandlesticks[x] = kline.Candle{
Time: candles[x].Timestamp.Time(),
Open: candles[x].OpenPrice,
High: candles[x].HighestPrice,
Low: candles[x].LowestPrice,
Close: candles[x].ClosePrice,
Open: candles[x].OpenPrice.Float64(),
High: candles[x].HighestPrice.Float64(),
Low: candles[x].LowestPrice.Float64(),
Close: candles[x].ClosePrice.Float64(),
Volume: candles[x].Volume,
}
}
@@ -1938,10 +1939,10 @@ func (g *Gateio) GetHistoricCandlesExtended(ctx context.Context, pair currency.P
for x := range candles {
candlestickItems = append(candlestickItems, kline.Candle{
Time: candles[x].Timestamp.Time(),
Open: candles[x].OpenPrice,
High: candles[x].HighestPrice,
Low: candles[x].LowestPrice,
Close: candles[x].ClosePrice,
Open: candles[x].OpenPrice.Float64(),
High: candles[x].HighestPrice.Float64(),
Low: candles[x].LowestPrice.Float64(),
Close: candles[x].ClosePrice.Float64(),
Volume: candles[x].Volume,
})
}

View File

@@ -425,11 +425,11 @@ func (g *Gateio) processFuturesTickers(data []byte, assetType asset.Item) error
for x := range resp.Result {
tickerPriceDatas[x] = ticker.Price{
ExchangeName: g.Name,
Volume: resp.Result[x].Volume24HBase,
QuoteVolume: resp.Result[x].Volume24HQuote,
High: resp.Result[x].High24H,
Low: resp.Result[x].Low24H,
Last: resp.Result[x].Last,
Volume: resp.Result[x].Volume24HBase.Float64(),
QuoteVolume: resp.Result[x].Volume24HQuote.Float64(),
High: resp.Result[x].High24H.Float64(),
Low: resp.Result[x].Low24H.Float64(),
Last: resp.Result[x].Last.Float64(),
AssetType: assetType,
Pair: resp.Result[x].Contract,
LastUpdated: time.Unix(resp.Time, 0),
@@ -463,7 +463,7 @@ func (g *Gateio) processFuturesTrades(data []byte, assetType asset.Item) error {
CurrencyPair: resp.Result[x].Contract,
AssetType: assetType,
Exchange: g.Name,
Price: resp.Result[x].Price,
Price: resp.Result[x].Price.Float64(),
Amount: resp.Result[x].Size,
TID: strconv.FormatInt(resp.Result[x].ID, 10),
}
@@ -498,10 +498,10 @@ func (g *Gateio) processFuturesCandlesticks(data []byte, assetType asset.Item) e
Exchange: g.Name,
StartTime: resp.Result[x].Timestamp.Time(),
Interval: icp[0],
OpenPrice: resp.Result[x].OpenPrice,
ClosePrice: resp.Result[x].ClosePrice,
HighPrice: resp.Result[x].HighestPrice,
LowPrice: resp.Result[x].LowestPrice,
OpenPrice: resp.Result[x].OpenPrice.Float64(),
ClosePrice: resp.Result[x].ClosePrice.Float64(),
HighPrice: resp.Result[x].HighestPrice.Float64(),
LowPrice: resp.Result[x].LowestPrice.Float64(),
Volume: resp.Result[x].Volume,
}
}
@@ -552,12 +552,12 @@ func (g *Gateio) processFuturesAndOptionsOrderbookUpdate(incoming []byte, assetT
updates.Asks = make([]orderbook.Item, len(data.Asks))
for x := range data.Asks {
updates.Asks[x].Amount = data.Asks[x].Size
updates.Asks[x].Price = data.Asks[x].Price
updates.Asks[x].Price = data.Asks[x].Price.Float64()
}
updates.Bids = make([]orderbook.Item, len(data.Bids))
for x := range data.Bids {
updates.Bids[x].Amount = data.Bids[x].Size
updates.Bids[x].Price = data.Bids[x].Price
updates.Bids[x].Price = data.Bids[x].Price.Float64()
}
if len(updates.Asks) == 0 && len(updates.Bids) == 0 {
return errors.New("malformed orderbook data")
@@ -582,12 +582,12 @@ func (g *Gateio) processFuturesOrderbookSnapshot(event string, incoming []byte,
base.Asks = make([]orderbook.Item, len(data.Asks))
for x := range data.Asks {
base.Asks[x].Amount = data.Asks[x].Size
base.Asks[x].Price = data.Asks[x].Price
base.Asks[x].Price = data.Asks[x].Price.Float64()
}
base.Bids = make([]orderbook.Item, len(data.Bids))
for x := range data.Bids {
base.Bids[x].Amount = data.Bids[x].Size
base.Bids[x].Price = data.Bids[x].Price
base.Bids[x].Price = data.Bids[x].Price.Float64()
}
return g.Websocket.Orderbook.LoadSnapshot(&base)
}
@@ -604,12 +604,12 @@ func (g *Gateio) processFuturesOrderbookSnapshot(event string, incoming []byte,
}
if data[x].Amount > 0 {
ab[1] = append(ab[1], orderbook.Item{
Price: data[x].Price,
Price: data[x].Price.Float64(),
Amount: data[x].Amount,
})
} else {
ab[0] = append(ab[0], orderbook.Item{
Price: data[x].Price,
Price: data[x].Price.Float64(),
Amount: -data[x].Amount,
})
}
@@ -705,7 +705,7 @@ func (g *Gateio) procesFuturesUserTrades(data []byte, assetType asset.Item) erro
CurrencyPair: resp.Result[x].Contract,
OrderID: resp.Result[x].OrderID,
TradeID: resp.Result[x].ID,
Price: resp.Result[x].Price,
Price: resp.Result[x].Price.Float64(),
Amount: resp.Result[x].Size,
AssetType: assetType,
}

View File

@@ -408,8 +408,8 @@ func (g *Gateio) processOptionsContractTickers(incoming []byte) error {
g.Websocket.DataHandler <- &ticker.Price{
Pair: data.Name,
Last: data.LastPrice.Float64(),
Bid: data.Bid1Price,
Ask: data.Ask1Price,
Bid: data.Bid1Price.Float64(),
Ask: data.Ask1Price.Float64(),
AskSize: data.Ask1Size,
BidSize: data.Bid1Size,
ExchangeName: g.Name,
@@ -526,11 +526,11 @@ func (g *Gateio) processOptionsCandlestickPushData(data []byte) error {
Exchange: g.Name,
StartTime: time.Unix(resp.Result[x].Timestamp, 0),
Interval: icp[0],
OpenPrice: resp.Result[x].OpenPrice,
ClosePrice: resp.Result[x].ClosePrice,
HighPrice: resp.Result[x].HighestPrice,
LowPrice: resp.Result[x].LowestPrice,
Volume: resp.Result[x].Amount,
OpenPrice: resp.Result[x].OpenPrice.Float64(),
ClosePrice: resp.Result[x].ClosePrice.Float64(),
HighPrice: resp.Result[x].HighestPrice.Float64(),
LowPrice: resp.Result[x].LowestPrice.Float64(),
Volume: resp.Result[x].Amount.Float64(),
}
}
g.Websocket.DataHandler <- klineDatas
@@ -564,12 +564,12 @@ func (g *Gateio) processOptionsOrderbookSnapshotPushData(event string, incoming
base.Asks = make([]orderbook.Item, len(data.Asks))
for x := range data.Asks {
base.Asks[x].Amount = data.Asks[x].Size
base.Asks[x].Price = data.Asks[x].Price
base.Asks[x].Price = data.Asks[x].Price.Float64()
}
base.Bids = make([]orderbook.Item, len(data.Bids))
for x := range data.Bids {
base.Bids[x].Amount = data.Bids[x].Size
base.Bids[x].Price = data.Bids[x].Price
base.Bids[x].Price = data.Bids[x].Price.Float64()
}
return g.Websocket.Orderbook.LoadSnapshot(&base)
}
@@ -586,11 +586,11 @@ func (g *Gateio) processOptionsOrderbookSnapshotPushData(event string, incoming
}
if data[x].Amount > 0 {
ab[1] = append(ab[1], orderbook.Item{
Price: data[x].Price, Amount: data[x].Amount,
Price: data[x].Price.Float64(), Amount: data[x].Amount,
})
} else {
ab[0] = append(ab[0], orderbook.Item{
Price: data[x].Price, Amount: -data[x].Amount,
Price: data[x].Price.Float64(), Amount: -data[x].Amount,
})
}
if !ok {
@@ -682,7 +682,7 @@ func (g *Gateio) processOptionsUserTradesPushData(data []byte) error {
CurrencyPair: resp.Result[x].Contract,
OrderID: resp.Result[x].OrderID,
TradeID: resp.Result[x].ID,
Price: resp.Result[x].Price,
Price: resp.Result[x].Price.Float64(),
Amount: resp.Result[x].Size,
}
}