mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-01 07:26:48 +00:00
types: Add Time type from Gateio and share across codebase (#1648)
* consolidate type to types package and share across code base * rm convert type and convert codebase * rm irrelavant test cases * Fix tests * glorious nits * Update exchanges/gateio/gateio_types.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> * thrasher: nits --------- Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io> Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/types"
|
||||
)
|
||||
|
||||
// Ticker holds ticker data
|
||||
@@ -127,17 +128,17 @@ type Orders struct {
|
||||
|
||||
// OrderData contains all individual order details
|
||||
type OrderData struct {
|
||||
OrderID string `json:"order_id"`
|
||||
OrderCurrency string `json:"order_currency"`
|
||||
OrderDate bithumbTime `json:"order_date"`
|
||||
PaymentCurrency string `json:"payment_currency"`
|
||||
Type string `json:"type"`
|
||||
Status string `json:"status"`
|
||||
Units float64 `json:"units,string"`
|
||||
UnitsRemaining float64 `json:"units_remaining,string"`
|
||||
Price float64 `json:"price,string"`
|
||||
Fee float64 `json:"fee,string"`
|
||||
Total float64 `json:"total,string"`
|
||||
OrderID string `json:"order_id"`
|
||||
OrderCurrency string `json:"order_currency"`
|
||||
OrderDate types.Time `json:"order_date"`
|
||||
PaymentCurrency string `json:"payment_currency"`
|
||||
Type string `json:"type"`
|
||||
Status string `json:"status"`
|
||||
Units float64 `json:"units,string"`
|
||||
UnitsRemaining float64 `json:"units_remaining,string"`
|
||||
Price float64 `json:"price,string"`
|
||||
Fee float64 `json:"fee,string"`
|
||||
Total float64 `json:"total,string"`
|
||||
}
|
||||
|
||||
// UserTransactions holds users full transaction list
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/types"
|
||||
)
|
||||
|
||||
// WsResponse is a generalised response data structure which will defer
|
||||
@@ -41,7 +42,7 @@ type WsTicker struct {
|
||||
// WsOrderbooks defines an amalgamated bid ask orderbook tranche list
|
||||
type WsOrderbooks struct {
|
||||
List []WsOrderbook `json:"list"`
|
||||
DateTime bithumbTime `json:"datetime"`
|
||||
DateTime types.Time `json:"datetime"`
|
||||
}
|
||||
|
||||
// WsOrderbook defines a singular orderbook tranche
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
package bithumb
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
// bithumbMSTime provides an internal conversion helper for microsecond parsing
|
||||
type bithumbTime time.Time
|
||||
|
||||
// UnmarshalJSON implements the unmarshal interface
|
||||
func (t *bithumbTime) UnmarshalJSON(data []byte) error {
|
||||
var timestamp string
|
||||
if err := json.Unmarshal(data, ×tamp); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
i, err := strconv.ParseInt(timestamp, 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*t = bithumbTime(time.Unix(0, i*int64(time.Microsecond)))
|
||||
return nil
|
||||
}
|
||||
|
||||
// Time returns a time.Time object
|
||||
func (t bithumbTime) Time() time.Time {
|
||||
return time.Time(t)
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package bithumb
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBithumbTime(t *testing.T) {
|
||||
var newTime bithumbTime
|
||||
err := json.Unmarshal([]byte("bad news"), &newTime)
|
||||
if err == nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
strData := []byte(`"1628739590000000"`) // Thursday, August 12, 2021 3:39:50 AM UTC
|
||||
err = json.Unmarshal(strData, &newTime)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
tt := newTime.Time()
|
||||
if tt.UTC().String() != "2021-08-12 03:39:50 +0000 UTC" {
|
||||
t.Fatalf("expected: %s but received: %s",
|
||||
"2021-08-12 03:39:50 +0000 UTC",
|
||||
tt.UTC().String())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user