mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-30 23:16:52 +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:
@@ -1,35 +1,41 @@
|
||||
package bitflyer
|
||||
|
||||
import "errors"
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/encoding/json"
|
||||
"github.com/thrasher-corp/gocryptotrader/types"
|
||||
)
|
||||
|
||||
var errUnhandledCurrency = errors.New("unhandled currency")
|
||||
|
||||
// ChainAnalysisBlock holds block information from the bitcoin network
|
||||
type ChainAnalysisBlock struct {
|
||||
BlockHash string `json:"block_hash"`
|
||||
Height int64 `json:"height"`
|
||||
IsMain bool `json:"is_main"`
|
||||
Version float64 `json:"version"`
|
||||
PreviousBlock string `json:"prev_block"`
|
||||
MerkleRoot string `json:"merkle_root"`
|
||||
Timestamp string `json:"timestamp"`
|
||||
Bits int64 `json:"bits"`
|
||||
Nonce int64 `json:"nonce"`
|
||||
TxNum int64 `json:"txnum"`
|
||||
TotalFees float64 `json:"total_fees"`
|
||||
TxHashes []string `json:"tx_hashes"`
|
||||
BlockHash string `json:"block_hash"`
|
||||
Height int64 `json:"height"`
|
||||
IsMain bool `json:"is_main"`
|
||||
Version float64 `json:"version"`
|
||||
PreviousBlock string `json:"prev_block"`
|
||||
MerkleRoot string `json:"merkle_root"`
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
Bits int64 `json:"bits"`
|
||||
Nonce int64 `json:"nonce"`
|
||||
TxNum int64 `json:"txnum"`
|
||||
TotalFees float64 `json:"total_fees"`
|
||||
TxHashes []string `json:"tx_hashes"`
|
||||
}
|
||||
|
||||
// ChainAnalysisTransaction holds transaction data from the bitcoin network
|
||||
type ChainAnalysisTransaction struct {
|
||||
TxHash string `json:"tx_hash"`
|
||||
BlockHeight int64 `json:"block_height"`
|
||||
Confirmations int64 `json:"confirmed"`
|
||||
Fees float64 `json:"fees"`
|
||||
Size int64 `json:"size"`
|
||||
ReceivedDate string `json:"received_date"`
|
||||
Version float64 `json:"version"`
|
||||
LockTime int64 `json:"lock_time"`
|
||||
TxHash string `json:"tx_hash"`
|
||||
BlockHeight int64 `json:"block_height"`
|
||||
Confirmations int64 `json:"confirmed"`
|
||||
Fees float64 `json:"fees"`
|
||||
Size int64 `json:"size"`
|
||||
ReceivedDate string `json:"received_date"`
|
||||
Version float64 `json:"version"`
|
||||
LockTime types.Time `json:"lock_time"`
|
||||
Inputs []struct {
|
||||
PrevHash string `json:"prev_hash"`
|
||||
PrevIndex int `json:"prev_index"`
|
||||
@@ -75,7 +81,7 @@ type Orderbook struct {
|
||||
// Ticker holds ticker information
|
||||
type Ticker struct {
|
||||
ProductCode string `json:"product_code"`
|
||||
TimeStamp string `json:"timestamp"`
|
||||
TimeStamp Time `json:"timestamp"`
|
||||
TickID int64 `json:"tick_id"`
|
||||
BestBid float64 `json:"best_bid"`
|
||||
BestAsk float64 `json:"best_ask"`
|
||||
@@ -94,7 +100,7 @@ type ExecutedTrade struct {
|
||||
Side string `json:"side"`
|
||||
Price float64 `json:"price"`
|
||||
Size float64 `json:"size"`
|
||||
ExecDate string `json:"exec_date"`
|
||||
ExecDate Time `json:"exec_date"`
|
||||
BuyAcceptedID string `json:"buy_child_order_acceptance_id"`
|
||||
SellAcceptedID string `json:"sell_child_order_acceptance_id"`
|
||||
}
|
||||
@@ -294,3 +300,23 @@ type NewOrder struct {
|
||||
MinuteToExpire float64 `json:"minute_to_expire"`
|
||||
TimeInForce string `json:"time_in_force"`
|
||||
}
|
||||
|
||||
// Time is a custom type that wraps time.Time to implement json.Unmarshaller
|
||||
type Time time.Time
|
||||
|
||||
// UnmarshalJSON implements the json.Unmarshaller interface for Time
|
||||
func (t *Time) UnmarshalJSON(data []byte) error {
|
||||
var str string
|
||||
if err := json.Unmarshal(data, &str); err != nil {
|
||||
return err
|
||||
}
|
||||
parsedTime, err := time.Parse("2006-01-02T15:04:05.999999999", str)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*t = Time(parsedTime)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Time returns the time.Time representation of the DateTime type
|
||||
func (t *Time) Time() time.Time { return time.Time(*t) }
|
||||
|
||||
@@ -271,11 +271,6 @@ func (b *Bitflyer) GetRecentTrades(ctx context.Context, p currency.Pair, assetTy
|
||||
}
|
||||
resp := make([]trade.Data, len(tradeData))
|
||||
for i := range tradeData {
|
||||
var timestamp time.Time
|
||||
timestamp, err = time.Parse("2006-01-02T15:04:05.999999999", tradeData[i].ExecDate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var side order.Side
|
||||
side, err = order.StringToOrderSide(tradeData[i].Side)
|
||||
if err != nil {
|
||||
@@ -289,7 +284,7 @@ func (b *Bitflyer) GetRecentTrades(ctx context.Context, p currency.Pair, assetTy
|
||||
Side: side,
|
||||
Price: tradeData[i].Price,
|
||||
Amount: tradeData[i].Size,
|
||||
Timestamp: timestamp,
|
||||
Timestamp: tradeData[i].ExecDate.Time(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user