mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-01 23:16:51 +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:
@@ -21,6 +21,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/nonce"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-corp/gocryptotrader/types"
|
||||
)
|
||||
|
||||
// Deribit is the overarching type across this package
|
||||
@@ -2449,12 +2450,11 @@ func (d *Deribit) GetUserBlockTrade(ctx context.Context, id string) ([]BlockTrad
|
||||
|
||||
// GetTime retrieves the current time (in milliseconds). This API endpoint can be used to check the clock skew between your software and Deribit's systems.
|
||||
func (d *Deribit) GetTime(ctx context.Context) (time.Time, error) {
|
||||
var result int64
|
||||
err := d.SendHTTPRequest(ctx, exchange.RestSpot, nonMatchingEPL, "public/get_time", &result)
|
||||
if err != nil {
|
||||
var timestamp types.Time
|
||||
if err := d.SendHTTPRequest(ctx, exchange.RestSpot, nonMatchingEPL, "public/get_time", ×tamp); err != nil {
|
||||
return time.Time{}, err
|
||||
}
|
||||
return time.UnixMilli(result), nil
|
||||
return timestamp.Time(), nil
|
||||
}
|
||||
|
||||
// GetLastBlockTradesByCurrency returns list of last users block trades
|
||||
|
||||
@@ -620,10 +620,10 @@ type MarginsData struct {
|
||||
|
||||
// MMPConfigData gets the current configuration data for MMP
|
||||
type MMPConfigData struct {
|
||||
Currency string `json:"currency"`
|
||||
Interval int64 `json:"interval"`
|
||||
FrozenTime int64 `json:"frozen_time"`
|
||||
QuantityLimit float64 `json:"quantity_limit"`
|
||||
Currency string `json:"currency"`
|
||||
Interval int64 `json:"interval"`
|
||||
FrozenTime types.Time `json:"frozen_time"`
|
||||
QuantityLimit float64 `json:"quantity_limit"`
|
||||
}
|
||||
|
||||
// UserTradesData stores data of user trades
|
||||
@@ -1097,13 +1097,13 @@ type wsOrderbook struct {
|
||||
|
||||
// wsCandlestickData represents publicly available market data used to generate a TradingView candle chart.
|
||||
type wsCandlestickData struct {
|
||||
Volume float64 `json:"volume"`
|
||||
Tick int64 `json:"tick"`
|
||||
Open float64 `json:"open"`
|
||||
Low float64 `json:"low"`
|
||||
High float64 `json:"high"`
|
||||
Cost float64 `json:"cost"`
|
||||
Close float64 `json:"close"`
|
||||
Volume float64 `json:"volume"`
|
||||
Tick types.Time `json:"tick"`
|
||||
Open float64 `json:"open"`
|
||||
Low float64 `json:"low"`
|
||||
High float64 `json:"high"`
|
||||
Cost float64 `json:"cost"`
|
||||
Close float64 `json:"close"`
|
||||
}
|
||||
|
||||
// wsIndexPrice represents information about current value (price) for Deribit Index
|
||||
|
||||
@@ -627,7 +627,7 @@ func (d *Deribit) processCandleChart(respRaw []byte, channels []string) error {
|
||||
return err
|
||||
}
|
||||
d.Websocket.DataHandler <- websocket.KlineData{
|
||||
Timestamp: time.UnixMilli(candleData.Tick),
|
||||
Timestamp: candleData.Tick.Time(),
|
||||
Pair: cp,
|
||||
AssetType: a,
|
||||
Exchange: d.Name,
|
||||
|
||||
Reference in New Issue
Block a user