exchanges: Types and unmarshalling methods update (#1899)

* Added TimeInForce type and updated related files

* Linter issue fix and minor coinbasepro type update

* Bitrex consts update

* added unit test and minor changes in bittrex

* Unit tests update

* Fix minor linter issues

* Update TestStringToTimeInForce unit test

* fix conflict with gateio timeInForce

* Update order tests

* Complete updating the order unit tests

* update kucoin and deribit wrapper to match the time in force change

* fix time-in-force related test errors

* linter issue fix

* time in force constants, functions and unit tests update

* shift tif policies to TimeInForce

* Update time-in-force, related functions, and unit tests

* fix linter issue and time-in-force processing

* added a good till crossing tif value

* order type fix and fix related tim-in-force entries

* update time-in-force unmarshaling and unit test

* fix time-in-force error in gateio

* linter issue fix

* update based on review comments

* add unit test and fix missing issues

* minor fix and added benchmark unit test

* change GTT to GTC for limit

* fix linter issue

* added time-in-force value to place order param

* fix minor issues based on review comment and move tif code to separate files

* update on exchanges linked to time-in-force

* resolve missing review comments

* minor linter issues fix

* added time-in-force handler and update timeInForce parametered endpoint

* minor fixes based on review

* nits fix

* update based on review

* linter fix

* rm getTimeInForce func and minor change to time-in-force

* minor change

* update based on review comments

* wrappers and time-in-force calling approach

* update slice data processing

* fix linter issues

* remove unnecessary Unmarshal methods and replace type delatration and added unit tests

* minor change

* minor changes to types

* update gateio string to timeInForce conversion and unit test

* removed unused timeInForceString func from kraken

* removed redundant parentheses in slice unmarshaling

* array to slice conversion and other updates

* reverted slice target to array

* Binanceus unit test NotNil check to Len check

* change NotNil to Len check

* rename unmarshal unit test funcs name

* wrap json strings with []byte
This commit is contained in:
Samuael A.
2025-06-02 06:54:49 +03:00
committed by GitHub
parent 8fa6179f65
commit 0e9adcd1e1
28 changed files with 483 additions and 1095 deletions

View File

@@ -471,55 +471,8 @@ func (g *Gateio) GetCandlesticks(ctx context.Context, currencyPair currency.Pair
if !to.IsZero() {
params.Set("to", strconv.FormatInt(to.Unix(), 10))
}
var candles [][7]string
err = g.SendHTTPRequest(ctx, exchange.RestSpot, publicCandleStickSpotEPL, common.EncodeURLValues(gateioSpotCandlesticks, params), &candles)
if err != nil {
return nil, err
}
if len(candles) == 0 {
return nil, fmt.Errorf("no candlesticks available for instrument %v", currencyPair)
}
candlesticks := make([]Candlestick, len(candles))
for x := range candles {
timestamp, err := strconv.ParseInt(candles[x][0], 10, 64)
if err != nil {
return nil, err
}
quoteTradingVolume, err := strconv.ParseFloat(candles[x][1], 64)
if err != nil {
return nil, err
}
closePrice, err := strconv.ParseFloat(candles[x][2], 64)
if err != nil {
return nil, err
}
highestPrice, err := strconv.ParseFloat(candles[x][3], 64)
if err != nil {
return nil, err
}
lowestPrice, err := strconv.ParseFloat(candles[x][4], 64)
if err != nil {
return nil, err
}
openPrice, err := strconv.ParseFloat(candles[x][5], 64)
if err != nil {
return nil, err
}
baseCurrencyAmount, err := strconv.ParseFloat(candles[x][6], 64)
if err != nil {
return nil, err
}
candlesticks[x] = Candlestick{
Timestamp: time.Unix(timestamp, 0),
QuoteCcyVolume: quoteTradingVolume,
ClosePrice: closePrice,
HighestPrice: highestPrice,
LowestPrice: lowestPrice,
OpenPrice: openPrice,
BaseCcyAmount: baseCurrencyAmount,
}
}
return candlesticks, nil
var candles []Candlestick
return candles, g.SendHTTPRequest(ctx, exchange.RestSpot, publicCandleStickSpotEPL, common.EncodeURLValues(gateioSpotCandlesticks, params), &candles)
}
// GetTradingFeeRatio retrieves user trading fee rates

View File

@@ -191,6 +191,25 @@ func TestGetMarketTrades(t *testing.T) {
}
}
func TestCandlestickUnmarshalJSON(t *testing.T) {
t.Parallel()
data := []byte(`[["1738108800","229534412.73508700","103734.3","104779.9","101336.6","101343.8","2232.94510000","true"],["1738195200","178316032.62306100","104718.6","106467.1","103286.4","103734.4","1695.00787000","true"],["1738281600","231315376.16747100","102431","106042.7","101555.9","104718.6","2228.03609000","true"]]`)
var targets []Candlestick
err := json.Unmarshal(data, &targets)
require.NoError(t, err)
require.Len(t, targets, 3)
assert.Equal(t, Candlestick{
Timestamp: types.Time(time.Unix(1738108800, 0)),
QuoteCcyVolume: 229534412.73508700,
ClosePrice: 103734.3,
HighestPrice: 104779.9,
LowestPrice: 101336.6,
OpenPrice: 101343.8,
BaseCcyAmount: 2232.94510000,
WindowClosed: true,
}, targets[0])
}
func TestGetCandlesticks(t *testing.T) {
t.Parallel()
if _, err := g.GetCandlesticks(t.Context(), getPair(t, asset.Spot), 0, time.Time{}, time.Time{}, kline.OneDay); err != nil {

View File

@@ -598,13 +598,25 @@ type Trade struct {
// Candlestick represents candlestick data point detail.
type Candlestick struct {
Timestamp time.Time
QuoteCcyVolume float64
ClosePrice float64
HighestPrice float64
LowestPrice float64
OpenPrice float64
BaseCcyAmount float64
Timestamp types.Time
QuoteCcyVolume types.Number
ClosePrice types.Number
HighestPrice types.Number
LowestPrice types.Number
OpenPrice types.Number
BaseCcyAmount types.Number
WindowClosed bool
}
// UnmarshalJSON parses kline data from a JSON array into Candlestick fields.
func (c *Candlestick) UnmarshalJSON(data []byte) error {
var windowClosed string
err := json.Unmarshal(data, &[8]any{&c.Timestamp, &c.QuoteCcyVolume, &c.ClosePrice, &c.HighestPrice, &c.LowestPrice, &c.OpenPrice, &c.BaseCcyAmount, &windowClosed})
if err != nil {
return err
}
c.WindowClosed, err = strconv.ParseBool(windowClosed)
return err
}
// CurrencyChain currency chain detail.

View File

@@ -1691,12 +1691,12 @@ func (g *Gateio) GetHistoricCandles(ctx context.Context, pair currency.Pair, a a
listCandlesticks = make([]kline.Candle, len(candles))
for i := range candles {
listCandlesticks[i] = kline.Candle{
Time: candles[i].Timestamp,
Open: candles[i].OpenPrice,
High: candles[i].HighestPrice,
Low: candles[i].LowestPrice,
Close: candles[i].ClosePrice,
Volume: candles[i].QuoteCcyVolume,
Time: candles[i].Timestamp.Time(),
Open: candles[i].OpenPrice.Float64(),
High: candles[i].HighestPrice.Float64(),
Low: candles[i].LowestPrice.Float64(),
Close: candles[i].ClosePrice.Float64(),
Volume: candles[i].BaseCcyAmount.Float64(),
}
}
case asset.CoinMarginedFutures, asset.USDTMarginedFutures, asset.DeliveryFutures:
@@ -1746,12 +1746,12 @@ func (g *Gateio) GetHistoricCandlesExtended(ctx context.Context, pair currency.P
}
for j := range candles {
candlestickItems = append(candlestickItems, kline.Candle{
Time: candles[j].Timestamp,
Open: candles[j].OpenPrice,
High: candles[j].HighestPrice,
Low: candles[j].LowestPrice,
Close: candles[j].ClosePrice,
Volume: candles[j].QuoteCcyVolume,
Time: candles[j].Timestamp.Time(),
Open: candles[j].OpenPrice.Float64(),
High: candles[j].HighestPrice.Float64(),
Low: candles[j].LowestPrice.Float64(),
Close: candles[j].ClosePrice.Float64(),
Volume: candles[j].QuoteCcyVolume.Float64(),
})
}
case asset.CoinMarginedFutures, asset.USDTMarginedFutures, asset.DeliveryFutures: