mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-24 15:10:19 +00:00
* starting public endpoints * Adding public endpoints * added public spot market endpoints * websocket subscriptions updates * websocket push data handlers completing * linter fix * Added funding private endpoints * Adding authenticated account endpoints * Added fiat and OTC-RFQ authenticated endpoints * trading authenticated endpoints * completing trade endpoints and add public wrapper endpoints * Authenticated wrapper functions and corresponding unit test * Adding authenticated websocket endpoint and fixing wrapper functions * Documentation and exchange websocket update * update websocket orderbook checksum handling * linter issues fix and unit test update * remove invalid orderbook endpoint and unit test * Documentation, handlers, and model types update * minot fix * Minor fixes * Updating unit tests and added missing endpoints * Add missing credential check * Minor unit test fixes * fix minor linter issue * add snaphot test unit test * Fix on update checksum and documentation update * update exchange, add UpdateOrderExecutionLimits, and update documentation * Minor fix on tickers fetching * Minor websocket fix and smaill unit tests * Minor websocket and naming fixes * uncomment default channels * Fix type and unit test issues * websocket channels and data handling update * Update Advanced-Algo websocket handling and minor fixes * documentation and minor code fixes * Fix name changes * documentation contribution update * intervalToString method update * fix exchange_wrapper_standard tests * Fix minor issues based on exchange_wrapper_standards_test * Fix wrapper extended candlestick check * websocket orders fetching error check method update * Exchange name check and change * docs: Add missing contributors --------- Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
90 lines
2.1 KiB
Go
90 lines
2.1 KiB
Go
package okcoin
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
type okcoinTime time.Time
|
|
|
|
// UnmarshalJSON deserializes timestamp information to time.Time
|
|
func (o *okcoinTime) UnmarshalJSON(data []byte) error {
|
|
var timeMilliSecond interface{}
|
|
err := json.Unmarshal(data, &timeMilliSecond)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
var timestamp int64
|
|
switch value := timeMilliSecond.(type) {
|
|
case string:
|
|
if value == "" {
|
|
*o = okcoinTime(time.Time{}) // in case timestamp information is empty string("") reset okcoinTime to zero.
|
|
return nil
|
|
}
|
|
timestamp, err = strconv.ParseInt(value, 10, 64)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
case int64:
|
|
timestamp = value
|
|
case float64:
|
|
timestamp = int64(value)
|
|
case float32:
|
|
timestamp = int64(value)
|
|
default:
|
|
return fmt.Errorf("cannot unmarshal %T into okcoinTime", value)
|
|
}
|
|
if timestamp > 9999999999 {
|
|
*o = okcoinTime(time.UnixMilli(timestamp))
|
|
} else {
|
|
*o = okcoinTime(time.Unix(timestamp, 0))
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Time returns a time.Time instance from okcoinMilliSec instance
|
|
func (o *okcoinTime) Time() time.Time {
|
|
return time.Time(*o)
|
|
}
|
|
|
|
type okcoinNumber float64
|
|
|
|
// UnmarshalJSON a custom JSON deserialization function for numeric values to okcoinNumber instance.
|
|
func (a *okcoinNumber) UnmarshalJSON(data []byte) error {
|
|
var value interface{}
|
|
err := json.Unmarshal(data, &value)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
switch val := value.(type) {
|
|
case string:
|
|
if val == "" {
|
|
*a = okcoinNumber(0)
|
|
return nil
|
|
}
|
|
floatValue, err := strconv.ParseFloat(val, 64)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
*a = okcoinNumber(floatValue)
|
|
case float64:
|
|
*a = okcoinNumber(val)
|
|
case int64:
|
|
*a = okcoinNumber(val)
|
|
case int32:
|
|
*a = okcoinNumber(int64(val))
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Float64 returns a float64 value from okcoinNumber instance.
|
|
func (a okcoinNumber) Float64() float64 { return float64(a) }
|
|
|
|
// Int64 returns a int64 value from okcoinNumber instance.
|
|
func (a okcoinNumber) Int64() int64 { return int64(a) }
|
|
|
|
// String returns string wrapped float64 value from okcoinNumber instance.
|
|
func (a okcoinNumber) String() string { return strconv.FormatFloat(float64(a), 'f', -1, 64) }
|