mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-31 23:16:54 +00:00
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:
@@ -362,7 +362,7 @@ func (b *Bithumb) GetWithdrawalsHistory(ctx context.Context, c currency.Code, _
|
||||
resp := make([]exchange.WithdrawalHistory, len(transactions.Data))
|
||||
for i := range transactions.Data {
|
||||
resp[i] = exchange.WithdrawalHistory{
|
||||
Timestamp: time.UnixMilli(transactions.Data[i].TransferDate),
|
||||
Timestamp: transactions.Data[i].TransferDate.Time(),
|
||||
Currency: transactions.Data[i].OrderCurrency.String(),
|
||||
Amount: transactions.Data[i].Amount,
|
||||
Fee: transactions.Data[i].Fee,
|
||||
@@ -389,11 +389,6 @@ func (b *Bithumb) GetRecentTrades(ctx context.Context, p currency.Pair, assetTyp
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var t time.Time
|
||||
t, err = time.Parse(time.DateTime, tradeData.Data[i].TransactionDate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp[i] = trade.Data{
|
||||
Exchange: b.Name,
|
||||
CurrencyPair: p,
|
||||
@@ -401,7 +396,7 @@ func (b *Bithumb) GetRecentTrades(ctx context.Context, p currency.Pair, assetTyp
|
||||
Side: side,
|
||||
Price: tradeData.Data[i].Price,
|
||||
Amount: tradeData.Data[i].UnitsTraded,
|
||||
Timestamp: t,
|
||||
Timestamp: tradeData.Data[i].TransactionDate.Time(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -756,41 +751,27 @@ func (b *Bithumb) GetHistoricCandles(ctx context.Context, pair currency.Pair, a
|
||||
return nil, err
|
||||
}
|
||||
|
||||
candle, err := b.GetCandleStick(ctx,
|
||||
req.RequestFormatted.String(),
|
||||
b.FormatExchangeKlineInterval(req.ExchangeInterval))
|
||||
candles, err := b.GetCandleStick(ctx, req.RequestFormatted.String(), b.FormatExchangeKlineInterval(req.ExchangeInterval))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
timeSeries := make([]kline.Candle, 0, len(candle.Data))
|
||||
for x := range candle.Data {
|
||||
var tempCandle kline.Candle
|
||||
if tempCandle.Time, err = convert.TimeFromUnixTimestampFloat(candle.Data[x][0]); err != nil {
|
||||
return nil, fmt.Errorf("unable to convert timestamp: %w", err)
|
||||
}
|
||||
if tempCandle.Time.Before(req.Start) {
|
||||
timeSeries := make([]kline.Candle, 0, len(candles.Data))
|
||||
for x := range candles.Data {
|
||||
if candles.Data[x].Timestamp.Time().Before(req.Start) {
|
||||
continue
|
||||
}
|
||||
if tempCandle.Time.After(req.End) {
|
||||
if candles.Data[x].Timestamp.Time().After(req.End) {
|
||||
break
|
||||
}
|
||||
if tempCandle.Open, err = convert.FloatFromString(candle.Data[x][1]); err != nil {
|
||||
return nil, fmt.Errorf("kline open conversion failed: %w", err)
|
||||
}
|
||||
if tempCandle.High, err = convert.FloatFromString(candle.Data[x][2]); err != nil {
|
||||
return nil, fmt.Errorf("kline high conversion failed: %w", err)
|
||||
}
|
||||
if tempCandle.Low, err = convert.FloatFromString(candle.Data[x][3]); err != nil {
|
||||
return nil, fmt.Errorf("kline low conversion failed: %w", err)
|
||||
}
|
||||
if tempCandle.Close, err = convert.FloatFromString(candle.Data[x][4]); err != nil {
|
||||
return nil, fmt.Errorf("kline close conversion failed: %w", err)
|
||||
}
|
||||
if tempCandle.Volume, err = convert.FloatFromString(candle.Data[x][5]); err != nil {
|
||||
return nil, fmt.Errorf("kline volume conversion failed: %w", err)
|
||||
}
|
||||
timeSeries = append(timeSeries, tempCandle)
|
||||
timeSeries = append(timeSeries, kline.Candle{
|
||||
Time: candles.Data[x].Timestamp.Time(),
|
||||
Open: candles.Data[x].Open.Float64(),
|
||||
High: candles.Data[x].High.Float64(),
|
||||
Low: candles.Data[x].Low.Float64(),
|
||||
Close: candles.Data[x].Close.Float64(),
|
||||
Volume: candles.Data[x].Volume.Float64(),
|
||||
})
|
||||
}
|
||||
return req.ProcessResponse(timeSeries)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user