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

@@ -1,6 +1,9 @@
package yobit
import "github.com/thrasher-corp/gocryptotrader/currency"
import (
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/types"
)
// Response is a generic struct used for exchange API request result
type Response struct {
@@ -11,7 +14,7 @@ type Response struct {
// Info holds server time and pair information
type Info struct {
ServerTime int64 `json:"server_time"`
ServerTime types.Time `json:"server_time"`
Pairs map[string]Pair `json:"pairs"`
}
@@ -36,21 +39,21 @@ type Orderbook struct {
// Trade stores trade information
type Trade struct {
Type string `json:"type"`
Price float64 `json:"price"`
Amount float64 `json:"amount"`
TID int64 `json:"tid"`
Timestamp int64 `json:"timestamp"`
Type string `json:"type"`
Price float64 `json:"price"`
Amount float64 `json:"amount"`
TID int64 `json:"tid"`
Timestamp types.Time `json:"timestamp"`
}
// ActiveOrders stores active order information
type ActiveOrders struct {
Pair string `json:"pair"`
Type string `json:"type"`
Amount float64 `json:"amount"`
Rate float64 `json:"rate"`
TimestampCreated float64 `json:"timestamp_created"`
Status int `json:"status"`
Pair string `json:"pair"`
Type string `json:"type"`
Amount float64 `json:"amount"`
Rate float64 `json:"rate"`
TimestampCreated types.Time `json:"timestamp_created"`
Status int `json:"status"`
}
// Pair holds pair information
@@ -72,21 +75,21 @@ type AccountInfo struct {
Trade int `json:"trade"`
Withdraw int `json:"withdraw"`
} `json:"rights"`
TransactionCount int `json:"transaction_count"`
OpenOrders int `json:"open_orders"`
ServerTime float64 `json:"server_time"`
Error string `json:"error"`
TransactionCount int `json:"transaction_count"`
OpenOrders int `json:"open_orders"`
ServerTime types.Time `json:"server_time"`
Error string `json:"error"`
}
// OrderInfo stores order information
type OrderInfo struct {
Pair string `json:"pair"`
Type string `json:"type"`
StartAmount float64 `json:"start_amount"`
Amount float64 `json:"amount"`
Rate float64 `json:"rate"`
TimestampCreated float64 `json:"timestamp_created"`
Status int `json:"status"`
Pair string `json:"pair"`
Type string `json:"type"`
StartAmount float64 `json:"start_amount"`
Amount float64 `json:"amount"`
Rate float64 `json:"rate"`
TimestampCreated types.Time `json:"timestamp_created"`
Status int `json:"status"`
}
// CancelOrder is used for the CancelOrder API request response
@@ -114,30 +117,30 @@ type TradeHistoryResponse struct {
// TradeHistory stores trade history
type TradeHistory struct {
Pair string `json:"pair"`
Type string `json:"type"`
Amount float64 `json:"amount"`
Rate float64 `json:"rate"`
OrderID float64 `json:"order_id"`
MyOrder int `json:"is_your_order"`
Timestamp float64 `json:"timestamp"`
Pair string `json:"pair"`
Type string `json:"type"`
Amount float64 `json:"amount"`
Rate float64 `json:"rate"`
OrderID float64 `json:"order_id"`
MyOrder int `json:"is_your_order"`
Timestamp types.Time `json:"timestamp"`
}
// DepositAddress stores a currency deposit address
type DepositAddress struct {
Success int `json:"success"`
Return struct {
Address string `json:"address"`
ProcessedAmount float64 `json:"processed_amount"`
ServerTime int64 `json:"server_time"`
Address string `json:"address"`
ProcessedAmount float64 `json:"processed_amount"`
ServerTime types.Time `json:"server_time"`
} `json:"return"`
Error string `json:"error"`
}
// WithdrawCoinsToAddress stores information for a withdrawcoins request
type WithdrawCoinsToAddress struct {
ServerTime int64 `json:"server_time"`
Error string `json:"error"`
ServerTime types.Time `json:"server_time"`
Error string `json:"error"`
}
// CreateCoupon stores information coupon information

View File

@@ -305,7 +305,6 @@ func (y *Yobit) GetRecentTrades(ctx context.Context, p currency.Pair, assetType
resp := make([]trade.Data, len(tradeData))
for i := range tradeData {
tradeTS := time.Unix(tradeData[i].Timestamp, 0)
side := order.Buy
if tradeData[i].Type == "ask" {
side = order.Sell
@@ -318,7 +317,7 @@ func (y *Yobit) GetRecentTrades(ctx context.Context, p currency.Pair, assetType
Side: side,
Price: tradeData[i].Price,
Amount: tradeData[i].Amount,
Timestamp: tradeTS,
Timestamp: tradeData[i].Timestamp.Time(),
}
}
@@ -465,7 +464,7 @@ func (y *Yobit) GetOrderInfo(ctx context.Context, orderID string, _ currency.Pai
Amount: orderInfo.Amount,
Price: orderInfo.Rate,
Side: side,
Date: time.Unix(int64(orderInfo.TimestampCreated), 0),
Date: orderInfo.TimestampCreated.Time(),
Pair: symbol,
Exchange: y.Name,
}, nil
@@ -572,7 +571,7 @@ func (y *Yobit) GetActiveOrders(ctx context.Context, req *order.MultiOrderReques
Amount: resp[id].Amount,
Price: resp[id].Rate,
Side: side,
Date: time.Unix(int64(resp[id].TimestampCreated), 0),
Date: resp[id].TimestampCreated.Time(),
Pair: symbol,
Exchange: y.Name,
})
@@ -626,7 +625,6 @@ func (y *Yobit) GetOrderHistory(ctx context.Context, req *order.MultiOrderReques
if err != nil {
return nil, err
}
orderDate := time.Unix(int64(allOrders[i].Timestamp), 0)
var side order.Side
side, err = order.StringToOrderSide(allOrders[i].Type)
if err != nil {
@@ -640,7 +638,7 @@ func (y *Yobit) GetOrderHistory(ctx context.Context, req *order.MultiOrderReques
AverageExecutedPrice: allOrders[i].Rate,
Side: side,
Status: order.Filled,
Date: orderDate,
Date: allOrders[i].Timestamp.Time(),
Pair: pair,
Exchange: y.Name,
}
@@ -673,7 +671,7 @@ func (y *Yobit) GetServerTime(ctx context.Context, _ asset.Item) (time.Time, err
if err != nil {
return time.Time{}, err
}
return time.Unix(info.ServerTime, 0), nil
return info.ServerTime.Time(), nil
}
// GetFuturesContractDetails returns all contracts from the exchange by asset type