mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-06 15:10:59 +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:
@@ -264,7 +264,7 @@ func (b *Bitstamp) UpdateTicker(ctx context.Context, p currency.Pair, a asset.It
|
||||
Volume: tick.Volume,
|
||||
Open: tick.Open,
|
||||
Pair: fPair,
|
||||
LastUpdated: time.Unix(tick.Timestamp, 0),
|
||||
LastUpdated: tick.Timestamp.Time(),
|
||||
ExchangeName: b.Name,
|
||||
AssetType: a,
|
||||
})
|
||||
@@ -386,15 +386,10 @@ func (b *Bitstamp) GetWithdrawalsHistory(ctx context.Context, c currency.Code, _
|
||||
}
|
||||
resp := make([]exchange.WithdrawalHistory, 0, len(withdrawals))
|
||||
for i := range withdrawals {
|
||||
var tm time.Time
|
||||
tm, err = parseTime(withdrawals[i].Date)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("getWithdrawalsHistory unable to parse Date field: %w", err)
|
||||
}
|
||||
if c.IsEmpty() || c.Equal(withdrawals[i].Currency) {
|
||||
resp = append(resp, exchange.WithdrawalHistory{
|
||||
Status: strconv.FormatInt(withdrawals[i].Status, 10),
|
||||
Timestamp: tm,
|
||||
Timestamp: withdrawals[i].Date.Time(),
|
||||
Currency: withdrawals[i].Currency.String(),
|
||||
Amount: withdrawals[i].Amount,
|
||||
TransferType: strconv.FormatInt(withdrawals[i].Type, 10),
|
||||
@@ -432,7 +427,7 @@ func (b *Bitstamp) GetRecentTrades(ctx context.Context, p currency.Pair, assetTy
|
||||
Side: s,
|
||||
Price: tradeData[i].Price,
|
||||
Amount: tradeData[i].Amount,
|
||||
Timestamp: time.Unix(tradeData[i].Date, 0),
|
||||
Timestamp: tradeData[i].Date.Time(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -531,10 +526,6 @@ func (b *Bitstamp) GetOrderInfo(ctx context.Context, orderID string, _ currency.
|
||||
Amount: o.Transactions[i].ToCurrency,
|
||||
}
|
||||
}
|
||||
orderDate, err := time.Parse(time.DateTime, o.DateTime)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
status, err := order.StringToOrderStatus(o.Status)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -542,7 +533,7 @@ func (b *Bitstamp) GetOrderInfo(ctx context.Context, orderID string, _ currency.
|
||||
return &order.Detail{
|
||||
RemainingAmount: o.AmountRemaining,
|
||||
OrderID: o.ID,
|
||||
Date: orderDate,
|
||||
Date: o.DateTime.Time(),
|
||||
Trades: th,
|
||||
Status: status,
|
||||
}, nil
|
||||
@@ -677,13 +668,6 @@ func (b *Bitstamp) GetActiveOrders(ctx context.Context, req *order.MultiOrderReq
|
||||
orderSide = order.Sell
|
||||
}
|
||||
|
||||
var tm time.Time
|
||||
tm, err = parseTime(resp[i].DateTime)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"%s GetActiveOrders unable to parse time: %s\n", b.Name, err)
|
||||
}
|
||||
|
||||
var p currency.Pair
|
||||
if currPair == "all" {
|
||||
// Currency pairs are returned as format "currency_pair": "BTC/USD"
|
||||
@@ -702,7 +686,7 @@ func (b *Bitstamp) GetActiveOrders(ctx context.Context, req *order.MultiOrderReq
|
||||
Price: resp[i].Price,
|
||||
Type: order.Limit,
|
||||
Side: orderSide,
|
||||
Date: tm,
|
||||
Date: resp[i].DateTime.Time(),
|
||||
Pair: p,
|
||||
Exchange: b.Name,
|
||||
}
|
||||
@@ -776,16 +760,9 @@ func (b *Bitstamp) GetOrderHistory(ctx context.Context, req *order.MultiOrderReq
|
||||
format.Delimiter)
|
||||
}
|
||||
|
||||
var tm time.Time
|
||||
tm, err = parseTime(resp[i].Date)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"%s GetOrderHistory unable to parse time: %s\n", b.Name, err)
|
||||
}
|
||||
|
||||
orders = append(orders, order.Detail{
|
||||
OrderID: strconv.FormatInt(resp[i].OrderID, 10),
|
||||
Date: tm,
|
||||
Date: resp[i].Date.Time(),
|
||||
Exchange: b.Name,
|
||||
Pair: currPair,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user