mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-20 15:10:10 +00:00
* gateio: update FuturesAccount struct * gateio: update Position struct * gateio: rm redundant checks and add in actual required checks * export GateioTime * linter: fix * linter: again fix * issue: fix * gateio: update fee struct and such * Update exchanges/gateio/gateio_types.go Co-authored-by: Scott <gloriousCode@users.noreply.github.com> * Update exchanges/gateio/gateio_convert.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> * use Time type acrost file --------- Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io> Co-authored-by: Scott <gloriousCode@users.noreply.github.com> Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
package gateio
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"math"
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
// Time represents a time.Time object that can be unmarshalled from a float64 or string.
|
|
type Time time.Time
|
|
|
|
// UnmarshalJSON deserializes json, and timestamp information.
|
|
func (a *Time) UnmarshalJSON(data []byte) error {
|
|
var value interface{}
|
|
err := json.Unmarshal(data, &value)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
var standard int64
|
|
switch val := value.(type) {
|
|
case float64:
|
|
if math.Trunc(val) != val {
|
|
standard = int64(val * 1e3) // Account for 1684981731.098
|
|
} else {
|
|
standard = int64(val)
|
|
}
|
|
case string:
|
|
if val == "" {
|
|
return nil
|
|
}
|
|
parsedValue, err := strconv.ParseFloat(val, 64)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if math.Trunc(parsedValue) != parsedValue {
|
|
*a = Time(time.UnixMicro(int64(parsedValue * 1e3))) // Account for "1691122380942.173000" microseconds
|
|
return nil
|
|
}
|
|
standard = int64(parsedValue)
|
|
default:
|
|
return fmt.Errorf("cannot unmarshal %T into Time", val)
|
|
}
|
|
if standard > 9999999999 {
|
|
*a = Time(time.UnixMilli(standard))
|
|
} else {
|
|
*a = Time(time.Unix(standard, 0))
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Time represents a time instance.
|
|
func (a Time) Time() time.Time { return time.Time(a) }
|