exchanges: Refactor time handling and other minor improvements (#1948)

* exchanges: Refactor time handling and other minor improvements

- Updated Kraken wrapper to utilise new time handling methods.
- Simplified Kucoin types by removing unnecessary structures and using direct JSON unmarshalling.
- Improved websocket handling in Kucoin to directly parse candlestick data.
- Modified Lbank types to use the new time representation.
- Adjusted Poloniex wrapper and types to utilise the new time handling.
- Updated Yobit types and wrapper to reflect changes in time representation.
- Introduced DateTime type for better handling of specific time formats.
- Added tests for DateTime unmarshalling to ensure correctness.
- Rid UTC().Unix and UTC().UnixMilli as it's not needed
- Correct Huobi timestamp usage for some endpoints.
- Rid RFC3339 time parsing since Go does that automatically.

* exchanges: Refactor JSON unmarshalling for various types and improve test coverage

* linter: Update error message in TestGetKlines

* refactor: Simplify JSON unmarshalling in MovementHistory and improve test assertions in GetKlines

* refactor: Improve JSON unmarshalling for channel name and clarify comment in wsProcessOpenOrders

* refactor: Update time handling in Huobi types to use types.Time for createdAt fields and relax GetLiquidationOrders test

* refactor: Move wsTicker, wsSpread, wsTrades, and wsCandle types to kraken_types.go for better organistion

* refactor: Add validation for underlying parameter in GetExpirationTime and update tests
This commit is contained in:
Adrian Gallagher
2025-07-01 09:11:55 +10:00
committed by GitHub
parent 48a66c9faa
commit 3cc9a2b9e0
92 changed files with 2488 additions and 3276 deletions

View File

@@ -1653,12 +1653,12 @@ func (b *Binance) GetHistoricCandles(ctx context.Context, pair currency.Pair, a
}
for i := range candles {
timeSeries = append(timeSeries, kline.Candle{
Time: candles[i].OpenTime,
Open: candles[i].Open,
High: candles[i].High,
Low: candles[i].Low,
Close: candles[i].Close,
Volume: candles[i].Volume,
Time: candles[i].OpenTime.Time(),
Open: candles[i].Open.Float64(),
High: candles[i].High.Float64(),
Low: candles[i].Low.Float64(),
Close: candles[i].Close.Float64(),
Volume: candles[i].Volume.Float64(),
})
}
case asset.USDTMarginedFutures:
@@ -1734,12 +1734,12 @@ func (b *Binance) GetHistoricCandlesExtended(ctx context.Context, pair currency.
}
for i := range candles {
timeSeries = append(timeSeries, kline.Candle{
Time: candles[i].OpenTime,
Open: candles[i].Open,
High: candles[i].High,
Low: candles[i].Low,
Close: candles[i].Close,
Volume: candles[i].Volume,
Time: candles[i].OpenTime.Time(),
Open: candles[i].Open.Float64(),
High: candles[i].High.Float64(),
Low: candles[i].Low.Float64(),
Close: candles[i].Close.Float64(),
Volume: candles[i].Volume.Float64(),
})
}
case asset.USDTMarginedFutures:
@@ -1933,7 +1933,7 @@ func (b *Binance) GetServerTime(ctx context.Context, ai asset.Item) (time.Time,
if err != nil {
return time.Time{}, err
}
return time.UnixMilli(info.ServerTime), nil
return info.ServerTime.Time(), nil
}
return time.Time{}, fmt.Errorf("%s %w", ai, asset.ErrNotSupported)
}
@@ -2128,14 +2128,14 @@ func (b *Binance) GetHistoricalFundingRates(ctx context.Context, r *fundingrate.
}
for j := range frh {
pairRate.FundingRates = append(pairRate.FundingRates, fundingrate.Rate{
Time: time.UnixMilli(frh[j].FundingTime),
Time: frh[j].FundingTime.Time(),
Rate: decimal.NewFromFloat(frh[j].FundingRate),
})
}
if len(frh) < requestLimit {
break
}
sd = time.UnixMilli(frh[len(frh)-1].FundingTime)
sd = frh[len(frh)-1].FundingTime.Time()
}
var mp []UMarkPrice
mp, err = b.UGetMarkPrice(ctx, fPair)
@@ -2155,8 +2155,7 @@ func (b *Binance) GetHistoricalFundingRates(ctx context.Context, r *fundingrate.
}
for j := range income {
for x := range pairRate.FundingRates {
tt := time.UnixMilli(income[j].Time)
tt = tt.Truncate(time.Duration(fundingRateFrequency) * time.Hour)
tt := income[j].Time.Time().Truncate(time.Duration(fundingRateFrequency) * time.Hour)
if !tt.Equal(pairRate.FundingRates[x].Time) {
continue
}
@@ -2194,14 +2193,14 @@ func (b *Binance) GetHistoricalFundingRates(ctx context.Context, r *fundingrate.
}
for j := range frh {
pairRate.FundingRates = append(pairRate.FundingRates, fundingrate.Rate{
Time: time.UnixMilli(frh[j].FundingTime),
Time: frh[j].FundingTime.Time(),
Rate: decimal.NewFromFloat(frh[j].FundingRate),
})
}
if len(frh) < requestLimit {
break
}
sd = time.UnixMilli(frh[len(frh)-1].FundingTime)
sd = frh[len(frh)-1].FundingTime.Time()
}
var mp []IndexMarkPrice
mp, err = b.GetIndexAndMarkPrice(ctx, fPair.String(), "")
@@ -2221,8 +2220,7 @@ func (b *Binance) GetHistoricalFundingRates(ctx context.Context, r *fundingrate.
}
for j := range income {
for x := range pairRate.FundingRates {
tt := time.UnixMilli(income[j].Timestamp)
tt = tt.Truncate(8 * time.Hour)
tt := income[j].Timestamp.Time().Truncate(8 * time.Hour)
if !tt.Equal(pairRate.FundingRates[x].Time) {
continue
}