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:
@@ -10,7 +10,6 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/common/convert"
|
||||
"github.com/thrasher-corp/gocryptotrader/core"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/encoding/json"
|
||||
@@ -1004,20 +1003,6 @@ func TestStatusToStandardStatus(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseTime(t *testing.T) {
|
||||
// Rest examples use 2014-11-07T22:19:28.578544Z" and can be safely
|
||||
// unmarhsalled into time.Time
|
||||
|
||||
// All events except for activate use the above, in the below test
|
||||
// we'll use their API docs example
|
||||
r := convert.TimeFromUnixTimestampDecimal(1483736448.299000).UTC()
|
||||
if r.Year() != 2017 ||
|
||||
r.Month().String() != "January" ||
|
||||
r.Day() != 6 {
|
||||
t.Error("unexpected result")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetRecentTrades(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := c.GetRecentTrades(t.Context(), testPair, asset.Spot)
|
||||
|
||||
@@ -386,41 +386,41 @@ type WsChannel struct {
|
||||
|
||||
// wsOrderReceived holds websocket received values
|
||||
type wsOrderReceived struct {
|
||||
Type string `json:"type"`
|
||||
OrderID string `json:"order_id"`
|
||||
OrderType string `json:"order_type"`
|
||||
Size float64 `json:"size,string"`
|
||||
Price float64 `json:"price,omitempty,string"`
|
||||
Funds float64 `json:"funds,omitempty,string"`
|
||||
Side string `json:"side"`
|
||||
ClientOID string `json:"client_oid"`
|
||||
ProductID string `json:"product_id"`
|
||||
Sequence int64 `json:"sequence"`
|
||||
Time time.Time `json:"time"`
|
||||
RemainingSize float64 `json:"remaining_size,string"`
|
||||
NewSize float64 `json:"new_size,string"`
|
||||
OldSize float64 `json:"old_size,string"`
|
||||
Reason string `json:"reason"`
|
||||
Timestamp float64 `json:"timestamp,string"`
|
||||
UserID string `json:"user_id"`
|
||||
ProfileID string `json:"profile_id"`
|
||||
StopType string `json:"stop_type"`
|
||||
StopPrice float64 `json:"stop_price,string"`
|
||||
TakerFeeRate float64 `json:"taker_fee_rate,string"`
|
||||
Private bool `json:"private"`
|
||||
TradeID int64 `json:"trade_id"`
|
||||
MakerOrderID string `json:"maker_order_id"`
|
||||
TakerOrderID string `json:"taker_order_id"`
|
||||
TakerUserID string `json:"taker_user_id"`
|
||||
Type string `json:"type"`
|
||||
OrderID string `json:"order_id"`
|
||||
OrderType string `json:"order_type"`
|
||||
Size float64 `json:"size,string"`
|
||||
Price float64 `json:"price,omitempty,string"`
|
||||
Funds float64 `json:"funds,omitempty,string"`
|
||||
Side string `json:"side"`
|
||||
ClientOID string `json:"client_oid"`
|
||||
ProductID string `json:"product_id"`
|
||||
Sequence int64 `json:"sequence"`
|
||||
Time time.Time `json:"time"`
|
||||
RemainingSize float64 `json:"remaining_size,string"`
|
||||
NewSize float64 `json:"new_size,string"`
|
||||
OldSize float64 `json:"old_size,string"`
|
||||
Reason string `json:"reason"`
|
||||
Timestamp types.Time `json:"timestamp"`
|
||||
UserID string `json:"user_id"`
|
||||
ProfileID string `json:"profile_id"`
|
||||
StopType string `json:"stop_type"`
|
||||
StopPrice float64 `json:"stop_price,string"`
|
||||
TakerFeeRate float64 `json:"taker_fee_rate,string"`
|
||||
Private bool `json:"private"`
|
||||
TradeID int64 `json:"trade_id"`
|
||||
MakerOrderID string `json:"maker_order_id"`
|
||||
TakerOrderID string `json:"taker_order_id"`
|
||||
TakerUserID string `json:"taker_user_id"`
|
||||
}
|
||||
|
||||
// WebsocketHeartBeat defines JSON response for a heart beat message
|
||||
type WebsocketHeartBeat struct {
|
||||
Type string `json:"type"`
|
||||
Sequence int64 `json:"sequence"`
|
||||
LastTradeID int64 `json:"last_trade_id"`
|
||||
ProductID string `json:"product_id"`
|
||||
Time string `json:"time"`
|
||||
Type string `json:"type"`
|
||||
Sequence int64 `json:"sequence"`
|
||||
LastTradeID int64 `json:"last_trade_id"`
|
||||
ProductID string `json:"product_id"`
|
||||
Time time.Time `json:"time"`
|
||||
}
|
||||
|
||||
// WebsocketTicker defines ticker websocket response
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"time"
|
||||
|
||||
gws "github.com/gorilla/websocket"
|
||||
"github.com/thrasher-corp/gocryptotrader/common/convert"
|
||||
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/encoding/json"
|
||||
@@ -163,7 +162,7 @@ func (c *CoinbasePro) wsHandleData(ctx context.Context, respRaw []byte) error {
|
||||
}
|
||||
ts := wsOrder.Time
|
||||
if wsOrder.Type == "activate" {
|
||||
ts = convert.TimeFromUnixTimestampDecimal(wsOrder.Timestamp)
|
||||
ts = wsOrder.Timestamp.Time()
|
||||
}
|
||||
|
||||
creds, err := c.GetCredentials(ctx)
|
||||
|
||||
@@ -170,7 +170,6 @@ func (c *CoinbasePro) Setup(exch *config.Exchange) error {
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("COINBASE ISSUE")
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user