mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-16 15:09:57 +00:00
* Adding Public Endpoints and test functions * Adding public endpoints and test functions * Adding private spot endpoints * Adding private endpoints and corresponding tests for margin * Adding Margin Private endpoints * Adding cross margin and flash swap endpoints * Adding futures private endpoints * Adding futures private endpoints and corresponding tests * Adding Options and SubAccount endpoints and their unit tests * Adding Wrapper functions * Complete wrapper functions and corresponding unit test functions * Fixing wrapper issues and adding websocket functions * Update of Spot websocket and adding futures websocket handlers * completed futures WS push data endpoints * Completed Options websocket endpoints * Adding websocket support for delivery futures and slight update on endpoint funcs * Added Delivery websocket support and fix linter issues * Update on Unit tests * fix slight currency format error * Fix slight endpoint tempos * Update on conditional statements and unit tests issues * fixing slight tempos * Slight model and websocket data push method change * Fix unit test tempos and updating models * Fix on code structures and update on unit tests * Slight code fix * Remove print statements * Update on tradable pairs fetch eps * Fix websocket tempos * Adding types to websocket routine manager * Fix slight issues * Slight fixes * Updating wrapper funcs and models * Slight update * Update on test * Update on tradable pairs * update conditional statements * Fixing slight issues * Updating unit tests * Minor fixes depending review comments * Remove redundant method declaration * Adding missing intervals * Updating fetch tradable pairs * update tradable pairs issues * Addressing small tempos * Slight fix on ticker * Minor Fixes * Minor review comment fixes * Unit test and minor code updates * Slight code updates * Minor updates depending review comments * Fixes * Updating incoming message matcher * Fix missing merge issue * Fix minor wrapper issues * Updating ratelimit and other issues * Updating endpoint models and adding missing eps * Update on code structure and models * Minor codespell fixes * Minor update on models * fix unit test panic * Minor race fix * Fix issues in generating signature and unit tests * Minor update on wrapper and unit tests * Minor fix on wrapper * Mini linter issues fix * Minor fix * endpoint fixes and slight update * Minor fixes * Updating exchange functions and unit tests * Unit test and wrapper updates * Remove options candlestick support * Minor unit test and wrapper fix * Unit test update * minor fix on unit test and wrapper * endpoints constants name change * Add minor wrapper issues * endpoint constants update * endpoint url updates * Updating subscriptions * fixing dual mode endpoint methods * minor fix * rm small tempo * Update on websocket orderbook handling * Orderbook and currency pair update * fix linter and test issues * minor helper function update * Fix wrapper coverage and wrapper issues * delete unused variables * Minor fix on ReadData() call * separating websocket handlers * separating websocket handlers * Minor fix on enabled pair * minor fix * check instrument availability in spot * create a separate subscriber for sake of multiple websocket connection * linter fix * minor websocket and gateio endpoints fix * fix nil pointer exception * minor fixes * spelling fix decerializes -> deserializes * fix Bitfinex unit test issues * minor unknown currency pair labling fix * minor currency pair handling fix * slight update on GetDepositAddress wrapper unit test * setting max request job to 200 * fixing numerical and timestamp type convert * fix value overflow error * change method of parsing orderbook price * unifying timestamp conversion types to gateioTime --------- Co-authored-by: Samuael Adnew <samuaelad@Samuaels-MacBook-Air.local>
134 lines
3.1 KiB
Go
134 lines
3.1 KiB
Go
package gateio
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
type gateioTime time.Time
|
|
|
|
// UnmarshalJSON deserializes json, and timestamp information.
|
|
func (a *gateioTime) 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:
|
|
standard = int64(val)
|
|
case int64:
|
|
standard = val
|
|
case int32:
|
|
standard = int64(val)
|
|
case string:
|
|
if val == "" {
|
|
return nil
|
|
}
|
|
parsedValue, err := strconv.ParseFloat(val, 64)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
standard = int64(parsedValue)
|
|
default:
|
|
return fmt.Errorf("cannot unmarshal %T into gateioTime", val)
|
|
}
|
|
if standard > 9999999999 {
|
|
*a = gateioTime(time.UnixMilli(standard))
|
|
} else {
|
|
*a = gateioTime(time.Unix(standard, 0))
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Time represents a time instance.
|
|
func (a *gateioTime) Time() time.Time { return time.Time(*a) }
|
|
|
|
type gateioNumericalValue float64
|
|
|
|
// UnmarshalJSON is custom type json unmarshaller for gateioNumericalValue
|
|
func (a *gateioNumericalValue) UnmarshalJSON(data []byte) error {
|
|
var num interface{}
|
|
err := json.Unmarshal(data, &num)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
switch d := num.(type) {
|
|
case float64:
|
|
*a = gateioNumericalValue(d)
|
|
case string:
|
|
if d == "" {
|
|
*a = gateioNumericalValue(0)
|
|
return nil
|
|
}
|
|
convNum, err := strconv.ParseFloat(d, 64)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
*a = gateioNumericalValue(convNum)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Float64 returns float64 value from gateioNumericalValue instance.
|
|
func (a *gateioNumericalValue) Float64() float64 { return float64(*a) }
|
|
|
|
// UnmarshalJSON to deserialize timestamp information and create OrderbookItem instance from the list of asks and bids data.
|
|
func (a *Orderbook) UnmarshalJSON(data []byte) error {
|
|
type Alias Orderbook
|
|
type askorbid struct {
|
|
Price gateioNumericalValue `json:"p"`
|
|
Size float64 `json:"s"`
|
|
}
|
|
chil := &struct {
|
|
*Alias
|
|
Current float64 `json:"current"`
|
|
Update float64 `json:"update"`
|
|
Asks []askorbid `json:"asks"`
|
|
Bids []askorbid `json:"bids"`
|
|
}{
|
|
Alias: (*Alias)(a),
|
|
}
|
|
err := json.Unmarshal(data, &chil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
a.Current = time.UnixMilli(int64(chil.Current * 1000))
|
|
a.Update = time.UnixMilli(int64(chil.Update * 1000))
|
|
a.Asks = make([]OrderbookItem, len(chil.Asks))
|
|
a.Bids = make([]OrderbookItem, len(chil.Bids))
|
|
for x := range chil.Asks {
|
|
a.Asks[x] = OrderbookItem{
|
|
Amount: chil.Asks[x].Size,
|
|
Price: chil.Asks[x].Price.Float64(),
|
|
}
|
|
}
|
|
for x := range chil.Bids {
|
|
a.Bids[x] = OrderbookItem{
|
|
Amount: chil.Bids[x].Size,
|
|
Price: chil.Bids[x].Price.Float64(),
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// UnmarshalJSON deserialises the JSON info, including the timestamp
|
|
func (a *WsUserPersonalTrade) UnmarshalJSON(data []byte) error {
|
|
type Alias WsUserPersonalTrade
|
|
chil := &struct {
|
|
*Alias
|
|
CreateTimeMicroS float64 `json:"create_time_ms,string"`
|
|
}{
|
|
Alias: (*Alias)(a),
|
|
}
|
|
if err := json.Unmarshal(data, chil); err != nil {
|
|
return err
|
|
}
|
|
a.CreateTimeMicroS = time.UnixMicro(int64(chil.CreateTimeMicroS * 1000))
|
|
return nil
|
|
}
|