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:
Ryan O'Hara-Reid
2024-10-01 10:46:55 +10:00
committed by GitHub
parent bfd499f0c9
commit d31fa3ff3d
29 changed files with 2633 additions and 2894 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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, &timestamp); 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)
}

View File

@@ -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())
}
}