From 4c4b6935be5a9c4db766c88788678422f9dc6eda Mon Sep 17 00:00:00 2001 From: Ryan O'Hara-Reid Date: Fri, 14 Jun 2024 11:54:27 +1000 Subject: [PATCH] gateio: update FuturesAccount and Position structs; rename gateioTime to Time (#1532) * 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 * Update exchanges/gateio/gateio_convert.go Co-authored-by: Adrian Gallagher * use Time type acrost file --------- Co-authored-by: Ryan O'Hara-Reid Co-authored-by: Scott Co-authored-by: Adrian Gallagher --- exchanges/gateio/gateio.go | 30 +- exchanges/gateio/gateio_convert.go | 15 +- exchanges/gateio/gateio_test.go | 16 +- exchanges/gateio/gateio_types.go | 709 +++++++++++++------------- exchanges/gateio/gateio_websocket.go | 10 +- exchanges/gateio/gateio_wrapper.go | 2 +- exchanges/gateio/gateio_ws_futures.go | 8 +- exchanges/gateio/gateio_ws_option.go | 8 +- 8 files changed, 410 insertions(+), 388 deletions(-) diff --git a/exchanges/gateio/gateio.go b/exchanges/gateio/gateio.go index 7164f692..902b54c8 100644 --- a/exchanges/gateio/gateio.go +++ b/exchanges/gateio/gateio.go @@ -1152,30 +1152,28 @@ func (g *Gateio) TransferCurrency(ctx context.Context, arg *TransferCurrencyPara if arg.Currency.IsEmpty() { return nil, currency.ErrCurrencyCodeEmpty } - if !strings.EqualFold(arg.From, asset.Spot.String()) { - return nil, fmt.Errorf("%w, only %s accounts can be used to transfer from", asset.ErrNotSupported, asset.Spot) + if arg.From == "" { + return nil, errors.New("from account is required") } - if !g.isAccountAccepted(arg.To) { - return nil, fmt.Errorf("%w, only %v,%v,%v,%v,%v,and %v are supported", asset.ErrNotSupported, asset.Spot, asset.Margin, asset.Futures, asset.DeliveryFutures, asset.CrossMargin, asset.Options) + if arg.To == "" { + return nil, errors.New("to account is required") } - if arg.Amount < 0 { + if arg.To == arg.From { + return nil, errors.New("from and to account cannot be the same") + } + if (arg.To == "margin" || arg.From == "margin") && arg.CurrencyPair.IsEmpty() { + return nil, errors.New("currency pair is required for margin account transfer") + } + if (arg.To == "futures" || arg.From == "futures") && arg.Settle == "" { + return nil, errors.New("settle is required for futures account transfer") + } + if arg.Amount <= 0 { return nil, errInvalidAmount } var response *TransactionIDResponse return response, g.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, walletEPL, http.MethodPost, walletTransfer, nil, &arg, &response) } -func (g *Gateio) isAccountAccepted(account string) bool { - if account == "" { - return false - } - acc, err := asset.New(account) - if err != nil { - return false - } - return acc == asset.Spot || acc == asset.Margin || acc == asset.CrossMargin || acc == asset.Futures || acc == asset.DeliveryFutures || acc == asset.Options -} - func (g *Gateio) assetTypeToString(acc asset.Item) string { if acc == asset.Options { return "options" diff --git a/exchanges/gateio/gateio_convert.go b/exchanges/gateio/gateio_convert.go index d1b3eb05..4c9aea3d 100644 --- a/exchanges/gateio/gateio_convert.go +++ b/exchanges/gateio/gateio_convert.go @@ -8,10 +8,11 @@ import ( "time" ) -type gateioTime time.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 *gateioTime) UnmarshalJSON(data []byte) error { +func (a *Time) UnmarshalJSON(data []byte) error { var value interface{} err := json.Unmarshal(data, &value) if err != nil { @@ -34,20 +35,20 @@ func (a *gateioTime) UnmarshalJSON(data []byte) error { return err } if math.Trunc(parsedValue) != parsedValue { - *a = gateioTime(time.UnixMicro(int64(parsedValue * 1e3))) // Account for "1691122380942.173000" microseconds + *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 gateioTime", val) + return fmt.Errorf("cannot unmarshal %T into Time", val) } if standard > 9999999999 { - *a = gateioTime(time.UnixMilli(standard)) + *a = Time(time.UnixMilli(standard)) } else { - *a = gateioTime(time.Unix(standard, 0)) + *a = Time(time.Unix(standard, 0)) } return nil } // Time represents a time instance. -func (a gateioTime) Time() time.Time { return time.Time(a) } +func (a Time) Time() time.Time { return time.Time(a) } diff --git a/exchanges/gateio/gateio_test.go b/exchanges/gateio/gateio_test.go index e95419aa..e3d075be 100644 --- a/exchanges/gateio/gateio_test.go +++ b/exchanges/gateio/gateio_test.go @@ -3147,7 +3147,7 @@ func TestParseGateioMilliSecTimeUnmarshal(t *testing.T) { float64JSON := `{"number": 1684981731.098}` time := time.UnixMilli(timeWhenTesting) - var in gateioTime + var in Time err := json.Unmarshal([]byte(timeWhenTestingString), &in) if err != nil { t.Fatal(err) @@ -3156,7 +3156,7 @@ func TestParseGateioMilliSecTimeUnmarshal(t *testing.T) { t.Fatalf("found %v, but expected %v", in.Time(), time) } inInteger := struct { - Number gateioTime `json:"number"` + Number Time `json:"number"` }{} err = json.Unmarshal([]byte(integerJSON), &inInteger) if err != nil { @@ -3167,7 +3167,7 @@ func TestParseGateioMilliSecTimeUnmarshal(t *testing.T) { } inFloat64 := struct { - Number gateioTime `json:"number"` + Number Time `json:"number"` }{} err = json.Unmarshal([]byte(float64JSON), &inFloat64) if err != nil { @@ -3178,7 +3178,7 @@ func TestParseGateioMilliSecTimeUnmarshal(t *testing.T) { } } -func TestParseGateioTimeUnmarshal(t *testing.T) { +func TestParseTimeUnmarshal(t *testing.T) { t.Parallel() var timeWhenTesting int64 = 1684981731 timeWhenTestingString := `"1684981731"` @@ -3187,7 +3187,7 @@ func TestParseGateioTimeUnmarshal(t *testing.T) { timeWhenTestingStringMicroSecond := `"1691122380942.173000"` whenTime := time.Unix(timeWhenTesting, 0) - var in gateioTime + var in Time err := json.Unmarshal([]byte(timeWhenTestingString), &in) if err != nil { t.Fatal(err) @@ -3196,7 +3196,7 @@ func TestParseGateioTimeUnmarshal(t *testing.T) { t.Fatalf("found %v, but expected %v", in.Time(), whenTime) } inInteger := struct { - Number gateioTime `json:"number"` + Number Time `json:"number"` }{} err = json.Unmarshal([]byte(integerJSON), &inInteger) if err != nil { @@ -3207,7 +3207,7 @@ func TestParseGateioTimeUnmarshal(t *testing.T) { } inFloat64 := struct { - Number gateioTime `json:"number"` + Number Time `json:"number"` }{} err = json.Unmarshal([]byte(float64JSON), &inFloat64) if err != nil { @@ -3218,7 +3218,7 @@ func TestParseGateioTimeUnmarshal(t *testing.T) { t.Fatalf("found %v, but expected %v", inFloat64.Number.Time(), msTime) } - var microSeconds gateioTime + var microSeconds Time err = json.Unmarshal([]byte(timeWhenTestingStringMicroSecond), µSeconds) if err != nil { t.Fatal(err) diff --git a/exchanges/gateio/gateio_types.go b/exchanges/gateio/gateio_types.go index 9ccc1113..013e7c06 100644 --- a/exchanges/gateio/gateio_types.go +++ b/exchanges/gateio/gateio_types.go @@ -520,15 +520,15 @@ type Ticker struct { Low24H types.Number `json:"low_24h"` EtfNetValue string `json:"etf_net_value"` EtfPreNetValue string `json:"etf_pre_net_value"` - EtfPreTimestamp gateioTime `json:"etf_pre_timestamp"` + EtfPreTimestamp Time `json:"etf_pre_timestamp"` EtfLeverage types.Number `json:"etf_leverage"` } // OrderbookData holds orderbook ask and bid datas. type OrderbookData struct { ID int64 `json:"id"` - Current gateioTime `json:"current"` // The timestamp of the response data being generated (in milliseconds) - Update gateioTime `json:"update"` // The timestamp of when the orderbook last changed (in milliseconds) + Current Time `json:"current"` // The timestamp of the response data being generated (in milliseconds) + Update Time `json:"update"` // The timestamp of when the orderbook last changed (in milliseconds) Asks [][2]string `json:"asks"` Bids [][2]string `json:"bids"` } @@ -582,8 +582,8 @@ type OrderbookItem struct { // Orderbook stores the orderbook data type Orderbook struct { ID int64 `json:"id"` - Current gateioTime `json:"current"` // The timestamp of the response data being generated (in milliseconds) - Update gateioTime `json:"update"` // The timestamp of when the orderbook last changed (in milliseconds) + Current Time `json:"current"` // The timestamp of the response data being generated (in milliseconds) + Update Time `json:"update"` // The timestamp of when the orderbook last changed (in milliseconds) Bids []OrderbookItem `json:"bids"` Asks []OrderbookItem `json:"asks"` } @@ -591,8 +591,8 @@ type Orderbook struct { // Trade represents market trade. type Trade struct { ID int64 `json:"id,string"` - TradingTime gateioTime `json:"create_time"` - CreateTimeMs gateioTime `json:"create_time_ms"` + TradingTime Time `json:"create_time"` + CreateTimeMs Time `json:"create_time_ms"` OrderID string `json:"order_id"` Side string `json:"side"` Role string `json:"role"` @@ -674,8 +674,8 @@ type FuturesContract struct { TakerFeeRate types.Number `json:"taker_fee_rate"` FundingRate types.Number `json:"funding_rate"` OrderSizeMax int64 `json:"order_size_max"` - FundingNextApply gateioTime `json:"funding_next_apply"` - ConfigChangeTime gateioTime `json:"config_change_time"` + FundingNextApply Time `json:"funding_next_apply"` + ConfigChangeTime Time `json:"config_change_time"` ShortUsers int64 `json:"short_users"` TradeSize int64 `json:"trade_size"` PositionSize int64 `json:"position_size"` @@ -689,7 +689,7 @@ type FuturesContract struct { // TradingHistoryItem represents futures trading history item. type TradingHistoryItem struct { ID int64 `json:"id"` - CreateTime gateioTime `json:"create_time"` + CreateTime Time `json:"create_time"` Contract string `json:"contract"` Text string `json:"text"` Size float64 `json:"size"` @@ -702,7 +702,7 @@ type TradingHistoryItem struct { // FuturesCandlestick represents futures candlestick data type FuturesCandlestick struct { - Timestamp gateioTime `json:"t"` + Timestamp Time `json:"t"` Volume float64 `json:"v"` ClosePrice types.Number `json:"c"` HighestPrice types.Number `json:"h"` @@ -715,7 +715,7 @@ type FuturesCandlestick struct { // FuturesPremiumIndexKLineResponse represents premium index K-Line information. type FuturesPremiumIndexKLineResponse struct { - UnixTimestamp gateioTime `json:"t"` + UnixTimestamp Time `json:"t"` ClosePrice types.Number `json:"c"` HighestPrice types.Number `json:"h"` LowestPrice types.Number `json:"l"` @@ -744,32 +744,32 @@ type FuturesTicker struct { // FuturesFundingRate represents futures funding rate response. type FuturesFundingRate struct { - Timestamp gateioTime `json:"t"` + Timestamp Time `json:"t"` Rate types.Number `json:"r"` } // InsuranceBalance represents futures insurance balance item. type InsuranceBalance struct { - Timestamp gateioTime `json:"t"` - Balance float64 `json:"b"` + Timestamp Time `json:"t"` + Balance float64 `json:"b"` } // ContractStat represents futures stats type ContractStat struct { - Time gateioTime `json:"time"` - LongShortTaker float64 `json:"lsr_taker"` - LongShortAccount float64 `json:"lsr_account"` - LongLiqSize float64 `json:"long_liq_size"` - ShortLiquidationSize float64 `json:"short_liq_size"` - OpenInterest float64 `json:"open_interest"` - ShortLiquidationUsd float64 `json:"short_liq_usd"` - MarkPrice float64 `json:"mark_price"` - TopLongShortSize float64 `json:"top_lsr_size"` - ShortLiquidationAmount float64 `json:"short_liq_amount"` - LongLiquidiationAmount float64 `json:"long_liq_amount"` - OpenInterestUsd float64 `json:"open_interest_usd"` - TopLongShortAccount float64 `json:"top_lsr_account"` - LongLiquidationUSD float64 `json:"long_liq_usd"` + Time Time `json:"time"` + LongShortTaker float64 `json:"lsr_taker"` + LongShortAccount float64 `json:"lsr_account"` + LongLiqSize float64 `json:"long_liq_size"` + ShortLiquidationSize float64 `json:"short_liq_size"` + OpenInterest float64 `json:"open_interest"` + ShortLiquidationUsd float64 `json:"short_liq_usd"` + MarkPrice float64 `json:"mark_price"` + TopLongShortSize float64 `json:"top_lsr_size"` + ShortLiquidationAmount float64 `json:"short_liq_amount"` + LongLiquidiationAmount float64 `json:"long_liq_amount"` + OpenInterestUsd float64 `json:"open_interest_usd"` + TopLongShortAccount float64 `json:"top_lsr_account"` + LongLiquidationUSD float64 `json:"long_liq_usd"` } // IndexConstituent represents index constituents @@ -783,7 +783,7 @@ type IndexConstituent struct { // LiquidationHistory represents liquidation history for a specifies settle. type LiquidationHistory struct { - Time gateioTime `json:"time"` + Time Time `json:"time"` Contract string `json:"contract"` Size int64 `json:"size"` Leverage string `json:"leverage"` @@ -835,15 +835,15 @@ type DeliveryContract struct { TradeID int64 `json:"trade_id"` TradeSize int64 `json:"trade_size"` PositionSize int64 `json:"position_size"` - ExpireTime gateioTime `json:"expire_time"` - ConfigChangeTime gateioTime `json:"config_change_time"` + ExpireTime Time `json:"expire_time"` + ConfigChangeTime Time `json:"config_change_time"` InDelisting bool `json:"in_delisting"` } // DeliveryTradingHistory represents futures trading history type DeliveryTradingHistory struct { ID int64 `json:"id"` - CreateTime gateioTime `json:"create_time"` + CreateTime Time `json:"create_time"` Contract string `json:"contract"` Size float64 `json:"size"` Price types.Number `json:"price"` @@ -853,7 +853,7 @@ type DeliveryTradingHistory struct { type OptionUnderlying struct { Name string `json:"name"` IndexPrice types.Number `json:"index_price"` - IndexTime gateioTime `json:"index_time"` + IndexTime Time `json:"index_time"` } // OptionContract represents an option contract detail. @@ -882,13 +882,13 @@ type OptionContract struct { OrderSizeMin int64 `json:"order_size_min"` OrderSizeMax int64 `json:"order_size_max"` OrdersLimit int64 `json:"orders_limit"` - CreateTime gateioTime `json:"create_time"` - ExpirationTime gateioTime `json:"expiration_time"` + CreateTime Time `json:"create_time"` + ExpirationTime Time `json:"expiration_time"` } // OptionSettlement list settlement history type OptionSettlement struct { - Timestamp gateioTime `json:"time"` + Timestamp Time `json:"time"` Profit types.Number `json:"profit"` Fee types.Number `json:"fee"` SettlePrice types.Number `json:"settle_price"` @@ -910,7 +910,7 @@ type MyOptionSettlement struct { SettleProfit types.Number `json:"settle_profit"` Contract string `json:"contract"` StrikePrice types.Number `json:"strike_price"` - Time gateioTime `json:"time"` + Time Time `json:"time"` SettlePrice types.Number `json:"settle_price"` Underlying string `json:"underlying"` RealisedPnl string `json:"realised_pnl"` @@ -964,7 +964,7 @@ type OptionAccount struct { // AccountBook represents account changing history item type AccountBook struct { - ChangeTime gateioTime `json:"time"` + ChangeTime Time `json:"time"` AccountChange types.Number `json:"change"` Balance types.Number `json:"balance"` CustomText string `json:"text"` @@ -990,7 +990,7 @@ type UsersPositionForUnderlying struct { // ContractClosePosition represents user's liquidation history type ContractClosePosition struct { - PositionCloseTime gateioTime `json:"time"` + PositionCloseTime Time `json:"time"` Pnl types.Number `json:"pnl"` SettleSize string `json:"settle_size"` Side string `json:"side"` // Position side, long or short @@ -1026,8 +1026,8 @@ type OptionOrderResponse struct { Left float64 `json:"left"` TimeInForce string `json:"tif"` IsReduceOnly bool `json:"is_reduce_only"` - CreateTime gateioTime `json:"create_time"` - FinishTime gateioTime `json:"finish_time"` + CreateTime Time `json:"create_time"` + FinishTime Time `json:"finish_time"` Price types.Number `json:"price"` TakerFee types.Number `json:"tkrf"` @@ -1042,7 +1042,7 @@ type OptionTradingHistory struct { Size float64 `json:"size"` Contract string `json:"contract"` TradeRole string `json:"role"` - CreateTime gateioTime `json:"create_time"` + CreateTime Time `json:"create_time"` OrderID int64 `json:"order_id"` Price types.Number `json:"price"` } @@ -1050,7 +1050,7 @@ type OptionTradingHistory struct { // WithdrawalResponse represents withdrawal response type WithdrawalResponse struct { ID string `json:"id"` - Timestamp gateioTime `json:"timestamp"` + Timestamp Time `json:"timestamp"` Currency string `json:"currency"` WithdrawalAddress string `json:"address"` TransactionID string `json:"txid"` @@ -1091,7 +1091,7 @@ type MultiChainAddressItem struct { // DepositRecord represents deposit record item type DepositRecord struct { ID string `json:"id"` - Timestamp gateioTime `json:"timestamp"` + Timestamp Time `json:"timestamp"` Currency string `json:"currency"` Address string `json:"address"` TransactionID string `json:"txid"` @@ -1129,7 +1129,7 @@ type SubAccountTransferParam struct { // SubAccountTransferResponse represents transfer records between main and sub accounts type SubAccountTransferResponse struct { MainAccountUserID string `json:"uid"` - Timestamp gateioTime `json:"timest"` + Timestamp Time `json:"timest"` Source string `json:"source"` Currency string `json:"currency"` SubAccount string `json:"sub_account"` @@ -1226,13 +1226,13 @@ type AccountBalanceInformation struct { // MarginAccountBalanceChangeInfo represents margin account balance type MarginAccountBalanceChangeInfo struct { - ID string `json:"id"` - Time gateioTime `json:"time"` - TimeMs gateioTime `json:"time_ms"` - Currency string `json:"currency"` - CurrencyPair string `json:"currency_pair"` - AmountChanged string `json:"change"` - Balance string `json:"balance"` + ID string `json:"id"` + Time Time `json:"time"` + TimeMs Time `json:"time_ms"` + Currency string `json:"currency"` + CurrencyPair string `json:"currency_pair"` + AmountChanged string `json:"change"` + Balance string `json:"balance"` } // MarginFundingAccountItem represents funding account list item. @@ -1271,8 +1271,8 @@ type MarginLoanResponse struct { CurrencyPair string `json:"currency_pair,omitempty"` FeeRate types.Number `json:"fee_rate"` Text string `json:"text,omitempty"` - CreateTime gateioTime `json:"create_time"` - ExpireTime gateioTime `json:"expire_time"` + CreateTime Time `json:"create_time"` + ExpireTime Time `json:"expire_time"` Status string `json:"status"` Left types.Number `json:"left"` Repaid types.Number `json:"repaid"` @@ -1328,16 +1328,19 @@ type WalletSavedAddress struct { // PersonalTradingFee represents personal trading fee for specific currency pair type PersonalTradingFee struct { - UserID int64 `json:"user_id"` - TakerFee types.Number `json:"taker_fee"` - MakerFee types.Number `json:"maker_fee"` - GtDiscount bool `json:"gt_discount"` - GtTakerFee types.Number `json:"gt_taker_fee"` - GtMakerFee types.Number `json:"gt_maker_fee"` - LoanFee types.Number `json:"loan_fee"` - PointType string `json:"point_type"` - FuturesTakerFee types.Number `json:"futures_taker_fee"` - FuturesMakerFee types.Number `json:"futures_maker_fee"` + UserID int64 `json:"user_id"` + TakerFee types.Number `json:"taker_fee"` + MakerFee types.Number `json:"maker_fee"` + GtDiscount bool `json:"gt_discount"` + GtTakerFee types.Number `json:"gt_taker_fee"` + GtMakerFee types.Number `json:"gt_maker_fee"` + LoanFee types.Number `json:"loan_fee"` + PointType string `json:"point_type"` + FuturesTakerFee types.Number `json:"futures_taker_fee"` + FuturesMakerFee types.Number `json:"futures_maker_fee"` + DeliveryTakerFee types.Number `json:"delivery_taker_fee"` + DeliveryMakerFee types.Number `json:"delivery_maker_fee"` + DebitFee float64 `json:"debit_fee"` } // UsersAllAccountBalance represents user all account balances. @@ -1394,10 +1397,10 @@ type SpotOrder struct { Succeeded bool `json:"succeeded"` ErrorLabel string `json:"label,omitempty"` Message string `json:"message,omitempty"` - CreateTime gateioTime `json:"create_time,omitempty"` - CreateTimeMs gateioTime `json:"create_time_ms,omitempty"` - UpdateTime gateioTime `json:"update_time,omitempty"` - UpdateTimeMs gateioTime `json:"update_time_ms,omitempty"` + CreateTime Time `json:"create_time,omitempty"` + CreateTimeMs Time `json:"create_time_ms,omitempty"` + UpdateTime Time `json:"update_time,omitempty"` + UpdateTimeMs Time `json:"update_time_ms,omitempty"` CurrencyPair string `json:"currency_pair,omitempty"` Status string `json:"status,omitempty"` Type string `json:"type,omitempty"` @@ -1458,8 +1461,8 @@ type CancelOrderByIDResponse struct { // SpotPersonalTradeHistory represents personal trading history. type SpotPersonalTradeHistory struct { TradeID string `json:"id"` - CreateTime gateioTime `json:"create_time"` - CreateTimeMs gateioTime `json:"create_time_ms"` + CreateTime Time `json:"create_time"` + CreateTimeMs Time `json:"create_time_ms"` CurrencyPair string `json:"currency_pair"` OrderID string `json:"order_id"` Side string `json:"side"` @@ -1480,7 +1483,7 @@ type CountdownCancelOrderParam struct { // TriggerTimeResponse represents trigger time as a response for countdown candle order response type TriggerTimeResponse struct { - TriggerTime gateioTime `json:"trigger_time"` + TriggerTime Time `json:"trigger_time"` } // PriceTriggeredOrderParam represents price triggered order request. @@ -1518,8 +1521,8 @@ type SpotPriceTriggeredOrder struct { Put PutOrderData `json:"put"` AutoOrderID int64 `json:"id"` UserID int64 `json:"user"` - CreationTime gateioTime `json:"ctime"` - FireTime gateioTime `json:"ftime"` + CreationTime Time `json:"ctime"` + FireTime Time `json:"ftime"` FiredOrderID int64 `json:"fired_order_id"` Status string `json:"status"` Reason string `json:"reason"` @@ -1545,18 +1548,18 @@ type RepayLoanRequestParam struct { // LoanRepaymentRecord represents loan repayment history record item. type LoanRepaymentRecord struct { - ID string `json:"id"` - CreateTime gateioTime `json:"create_time"` - Principal string `json:"principal"` - Interest string `json:"interest"` + ID string `json:"id"` + CreateTime Time `json:"create_time"` + Principal string `json:"principal"` + Interest string `json:"interest"` } // LoanRecord represents loan repayment specific record type LoanRecord struct { ID string `json:"id"` LoanID string `json:"loan_id"` - CreateTime gateioTime `json:"create_time"` - ExpireTime gateioTime `json:"expire_time"` + CreateTime Time `json:"create_time"` + ExpireTime Time `json:"expire_time"` Status string `json:"status"` BorrowUserID string `json:"borrow_user_id"` Currency string `json:"currency"` @@ -1623,7 +1626,7 @@ type CrossMarginAccount struct { // CrossMarginAccountHistoryItem represents a cross margin account change history item type CrossMarginAccountHistoryItem struct { ID string `json:"id"` - Time gateioTime `json:"time"` + Time Time `json:"time"` Currency string `json:"currency"` // Currency changed Change string `json:"change"` Balance types.Number `json:"balance"` @@ -1640,8 +1643,8 @@ type CrossMarginBorrowLoanParams struct { // CrossMarginLoanResponse represents a cross margin borrow loan response type CrossMarginLoanResponse struct { ID string `json:"id"` - CreateTime gateioTime `json:"create_time"` - UpdateTime gateioTime `json:"update_time"` + CreateTime Time `json:"create_time"` + UpdateTime Time `json:"update_time"` Currency string `json:"currency"` Amount types.Number `json:"amount"` Text string `json:"text"` @@ -1660,7 +1663,7 @@ type CurrencyAndAmount struct { // RepaymentHistoryItem represents an item in a repayment history. type RepaymentHistoryItem struct { ID string `json:"id"` - CreateTime gateioTime `json:"create_time"` + CreateTime Time `json:"create_time"` LoanID string `json:"loan_id"` Currency string `json:"currency"` Principal types.Number `json:"principal"` @@ -1679,8 +1682,8 @@ type FlashSwapOrderParams struct { // FlashSwapOrderResponse represents create flash swap order response type FlashSwapOrderResponse struct { ID int64 `json:"id"` - CreateTime gateioTime `json:"create_time"` - UpdateTime gateioTime `json:"update_time"` + CreateTime Time `json:"create_time"` + UpdateTime Time `json:"update_time"` UserID int64 `json:"user_id"` SellCurrency string `json:"sell_currency"` SellAmount types.Number `json:"sell_amount"` @@ -1702,33 +1705,44 @@ type InitFlashSwapOrderPreviewResponse struct { // FuturesAccount represents futures account detail type FuturesAccount struct { - User int64 `json:"user"` - Currency string `json:"currency"` - Total types.Number `json:"total"` // total = position_margin + order_margin + available - UnrealisedPnl string `json:"unrealised_pnl"` - PositionMargin string `json:"position_margin"` - OrderMargin string `json:"order_margin"` // Order margin of unfinished orders - Available types.Number `json:"available"` // The available balance for transferring or trading - Point string `json:"point"` - Bonus string `json:"bonus"` - InDualMode bool `json:"in_dual_mode"` // Whether dual mode is enabled - History struct { + User int64 `json:"user"` + Currency string `json:"currency"` + Total types.Number `json:"total"` // total = position_margin + order_margin + available + UnrealisedPnl types.Number `json:"unrealised_pnl"` + PositionMargin types.Number `json:"position_margin"` + OrderMargin types.Number `json:"order_margin"` // Order margin of unfinished orders + Available types.Number `json:"available"` // The available balance for transferring or trading + Point types.Number `json:"point"` + Bonus string `json:"bonus"` + EnabledCredit bool `json:"enable_credit"` + InDualMode bool `json:"in_dual_mode"` // Whether dual mode is enabled + UpdateTime Time `json:"update_time"` + UpdateID int64 `json:"update_id"` + PositionInitialMargine types.Number `json:"position_initial_margin"` // applicable to the portfolio margin account model + MaintenanceMargin types.Number `json:"maintenance_margin"` + MarginMode int64 `json:"margin_mode"` // Margin mode: 1-cross margin, 2-isolated margin, 3-portfolio margin + EnabledEvolvedClassic bool `json:"enable_evolved_classic"` + CrossInitialMargin types.Number `json:"cross_initial_margin"` + CrossUnrealisedPnl types.Number `json:"cross_unrealised_pnl"` + IsolatedPositionMargin types.Number `json:"isolated_position_margin"` + History struct { DepositAndWithdrawal string `json:"dnw"` // total amount of deposit and withdraw ProfitAndLoss types.Number `json:"pnl"` // total amount of trading profit and loss - Fee string `json:"fee"` // total amount of fee - Refr string `json:"refr"` // total amount of referrer rebates - Fund string `json:"fund"` - PointDnw string `json:"point_dnw"` // total amount of point deposit and withdraw - PointFee string `json:"point_fee"` // total amount of point fee - PointRefr string `json:"point_refr"` - BonusDnw string `json:"bonus_dnw"` // total amount of perpetual contract bonus transfer - BonusOffset string `json:"bonus_offset"` // total amount of perpetual contract bonus deduction + Fee types.Number `json:"fee"` // total amount of fee + Refr types.Number `json:"refr"` // total amount of referrer rebates + Fund types.Number `json:"fund"` + PointDNW types.Number `json:"point_dnw"` // total amount of point deposit and withdraw + PointFee types.Number `json:"point_fee"` // total amount of point fee + PointRefr types.Number `json:"point_refr"` + BonusDNW types.Number `json:"bonus_dnw"` // total amount of perpetual contract bonus transfer + BonusOffset types.Number `json:"bonus_offset"` // total amount of perpetual contract bonus deduction + CrossSettle types.Number `json:"cross_settle"` } `json:"history"` } // AccountBookItem represents account book item type AccountBookItem struct { - Time gateioTime `json:"time"` + Time Time `json:"time"` Change types.Number `json:"change"` Balance types.Number `json:"balance"` Text string `json:"text"` @@ -1737,33 +1751,42 @@ type AccountBookItem struct { // Position represents futures position type Position struct { - User int64 `json:"user"` - Contract string `json:"contract"` - Size int64 `json:"size"` - Leverage types.Number `json:"leverage"` - RiskLimit types.Number `json:"risk_limit"` - LeverageMax types.Number `json:"leverage_max"` - MaintenanceRate types.Number `json:"maintenance_rate"` - Value types.Number `json:"value"` - Margin types.Number `json:"margin"` - EntryPrice types.Number `json:"entry_price"` - LiqPrice types.Number `json:"liq_price"` - MarkPrice types.Number `json:"mark_price"` - UnrealisedPnl types.Number `json:"unrealised_pnl"` - RealisedPnl types.Number `json:"realised_pnl"` - HistoryPnl types.Number `json:"history_pnl"` - LastClosePnl types.Number `json:"last_close_pnl"` - RealisedPoint types.Number `json:"realised_point"` - HistoryPoint types.Number `json:"history_point"` - AdlRanking int64 `json:"adl_ranking"` - PendingOrders int64 `json:"pending_orders"` - CloseOrder struct { + User int64 `json:"user"` + Contract string `json:"contract"` + Size float64 `json:"size"` // Denotes long or short position, positive for long, negative for short + Leverage types.Number `json:"leverage"` + RiskLimit types.Number `json:"risk_limit"` + LeverageMax types.Number `json:"leverage_max"` + MaintenanceRate types.Number `json:"maintenance_rate"` + Value types.Number `json:"value"` + Margin types.Number `json:"margin"` + EntryPrice types.Number `json:"entry_price"` + LiquidationPrice types.Number `json:"liq_price"` + MarkPrice types.Number `json:"mark_price"` + InitialMargin types.Number `json:"initial_margin"` + MaintenanceMargin types.Number `json:"maintenance_margin"` + UnrealisedPNL types.Number `json:"unrealised_pnl"` + RealisedPnl types.Number `json:"realised_pnl"` + RealisedPNLPosition types.Number `json:"pnl_pnl"` + RealisedPNLFundingFee types.Number `json:"pnl_fund"` + RealisedPNLTransactionFees types.Number `json:"pnl_fee"` + HistoryPNL types.Number `json:"history_pnl"` + LastClosePNL types.Number `json:"last_close_pnl"` + RealisedPNLPoint types.Number `json:"realised_point"` + RealisedPNLHistoryPoint types.Number `json:"history_point"` + ADLRanking int64 `json:"adl_ranking"` // Ranking of auto deleveraging, a total of 1-5 grades, 1 is the highest, 5 is the lowest, and 6 is the special case when there is no position held or in liquidation + PendingOrders int64 `json:"pending_orders"` + CloseOrder struct { ID int64 `json:"id"` Price types.Number `json:"price"` IsLiq bool `json:"is_liq"` } `json:"close_order"` - Mode string `json:"mode"` - CrossLeverageLimit string `json:"cross_leverage_limit"` + Mode string `json:"mode"` + CrossLeverageLimit types.Number `json:"cross_leverage_limit"` + UpdateTime Time `json:"update_time"` + OpenTime Time `json:"open_time"` + UpdateID int64 `json:"update_id"` + TradeMaxSize types.Number `json:"trade_max_size"` } // DualModeResponse represents dual mode enable or disable @@ -1811,7 +1834,7 @@ type Order struct { ID int64 `json:"id"` User int64 `json:"user"` Contract string `json:"contract"` - CreateTime gateioTime `json:"create_time"` + CreateTime Time `json:"create_time"` Size float64 `json:"size"` Iceberg int64 `json:"iceberg"` RemainingAmount float64 `json:"left"` // Size left to be traded @@ -1826,7 +1849,7 @@ type Order struct { IsOrderForLiquidation bool `json:"is_liq"` Text string `json:"text"` Status string `json:"status"` - FinishTime gateioTime `json:"finish_time"` + FinishTime Time `json:"finish_time"` FinishAs string `json:"finish_as"` } @@ -1838,7 +1861,7 @@ type AmendFuturesOrderParam struct { // PositionCloseHistoryResponse represents a close position history detail type PositionCloseHistoryResponse struct { - Time gateioTime `json:"time"` + Time Time `json:"time"` ProfitAndLoss types.Number `json:"pnl"` Side string `json:"side"` Contract string `json:"contract"` @@ -1847,7 +1870,7 @@ type PositionCloseHistoryResponse struct { // LiquidationHistoryItem liquidation history item type LiquidationHistoryItem struct { - Time gateioTime `json:"time"` + Time Time `json:"time"` Contract string `json:"contract"` Size int64 `json:"size"` Leverage types.Number `json:"leverage"` @@ -1910,20 +1933,20 @@ type PriceTriggeredOrder struct { Rule int64 `json:"rule"` Expiration int64 `json:"expiration"` } `json:"trigger"` - ID int64 `json:"id"` - User int64 `json:"user"` - CreateTime gateioTime `json:"create_time"` - FinishTime gateioTime `json:"finish_time"` - TradeID int64 `json:"trade_id"` - Status string `json:"status"` - FinishAs string `json:"finish_as"` - Reason string `json:"reason"` - OrderType string `json:"order_type"` + ID int64 `json:"id"` + User int64 `json:"user"` + CreateTime Time `json:"create_time"` + FinishTime Time `json:"finish_time"` + TradeID int64 `json:"trade_id"` + Status string `json:"status"` + FinishAs string `json:"finish_as"` + Reason string `json:"reason"` + OrderType string `json:"order_type"` } // SettlementHistoryItem represents a settlement history item type SettlementHistoryItem struct { - Time gateioTime `json:"time"` + Time Time `json:"time"` Contract string `json:"contract"` Size int64 `json:"size"` Leverage string `json:"leverage"` @@ -1944,13 +1967,13 @@ type SubAccountParams struct { // SubAccount represents a subaccount response type SubAccount struct { - Remark string `json:"remark"` // custom text - LoginName string `json:"login_name"` // SubAccount login name - Password string `json:"password"` // The sub-account's password - SubAccountEmail string `json:"email"` // The sub-account's email - UserID int64 `json:"user_id"` - State int64 `json:"state"` - CreateTime gateioTime `json:"create_time"` + Remark string `json:"remark"` // custom text + LoginName string `json:"login_name"` // SubAccount login name + Password string `json:"password"` // The sub-account's password + SubAccountEmail string `json:"email"` // The sub-account's email + UserID int64 `json:"user_id"` + State int64 `json:"state"` + CreateTime Time `json:"create_time"` } // ************************************************************************************************** @@ -1974,7 +1997,7 @@ type WsAuthInput struct { // WsEventResponse represents websocket incoming subscription, unsubscription, and update response type WsEventResponse struct { - Time int64 `json:"time"` + Time Time `json:"time"` ID int64 `json:"id"` Channel string `json:"channel"` Event string `json:"event"` @@ -1990,7 +2013,7 @@ type WsEventResponse struct { // WsResponse represents generalized websocket push data from the server. type WsResponse struct { ID int64 `json:"id"` - Time int64 `json:"time"` + Time Time `json:"time"` Channel string `json:"channel"` Event string `json:"event"` Result json.RawMessage `json:"result"` @@ -2012,8 +2035,8 @@ type WsTicker struct { // WsTrade represents a websocket push data response for a trade type WsTrade struct { ID int64 `json:"id"` - CreateTime gateioTime `json:"create_time"` - CreateTimeMs gateioTime `json:"create_time_ms"` + CreateTime Time `json:"create_time"` + CreateTimeMs Time `json:"create_time_ms"` Side string `json:"side"` CurrencyPair currency.Pair `json:"currency_pair"` Amount types.Number `json:"amount"` @@ -2022,7 +2045,7 @@ type WsTrade struct { // WsCandlesticks represents the candlestick data for spot, margin and cross margin trades pushed through the websocket channel. type WsCandlesticks struct { - Timestamp int64 `json:"t,string"` + Timestamp Time `json:"t"` TotalVolume types.Number `json:"v"` ClosePrice types.Number `json:"c"` HighestPrice types.Number `json:"h"` @@ -2033,7 +2056,7 @@ type WsCandlesticks struct { // WsOrderbookTickerData represents the websocket orderbook best bid or best ask push data type WsOrderbookTickerData struct { - UpdateTimeMS int64 `json:"t"` + UpdateTimeMS Time `json:"t"` UpdateOrderID int64 `json:"u"` CurrencyPair currency.Pair `json:"s"` BestBidPrice types.Number `json:"b"` @@ -2044,9 +2067,9 @@ type WsOrderbookTickerData struct { // WsOrderbookUpdate represents websocket orderbook update push data type WsOrderbookUpdate struct { - UpdateTimeMs gateioTime `json:"t"` + UpdateTimeMs Time `json:"t"` IgnoreField string `json:"e"` - UpdateTime gateioTime `json:"E"` + UpdateTime Time `json:"E"` CurrencyPair currency.Pair `json:"s"` FirstOrderbookUpdatedID int64 `json:"U"` // First update order book id in this event since last update LastOrderbookUpdatedID int64 `json:"u"` @@ -2056,7 +2079,7 @@ type WsOrderbookUpdate struct { // WsOrderbookSnapshot represents a websocket orderbook snapshot push data type WsOrderbookSnapshot struct { - UpdateTimeMs gateioTime `json:"t"` + UpdateTimeMs Time `json:"t"` LastUpdateID int64 `json:"lastUpdateId"` CurrencyPair currency.Pair `json:"s"` Bids [][2]string `json:"bids"` @@ -2089,10 +2112,10 @@ type WsSpotOrder struct { RebatedFee string `json:"rebated_fee,omitempty"` RebatedFeeCurrency string `json:"rebated_fee_currency,omitempty"` Event string `json:"event"` - CreateTime gateioTime `json:"create_time,omitempty"` - CreateTimeMs gateioTime `json:"create_time_ms,omitempty"` - UpdateTime gateioTime `json:"update_time,omitempty"` - UpdateTimeMs gateioTime `json:"update_time_ms,omitempty"` + CreateTime Time `json:"create_time,omitempty"` + CreateTimeMs Time `json:"create_time_ms,omitempty"` + UpdateTime Time `json:"update_time,omitempty"` + UpdateTimeMs Time `json:"update_time_ms,omitempty"` } // WsUserPersonalTrade represents a user's personal trade pushed through the websocket connection. @@ -2101,8 +2124,8 @@ type WsUserPersonalTrade struct { UserID int64 `json:"user_id"` OrderID string `json:"order_id"` CurrencyPair currency.Pair `json:"currency_pair"` - CreateTime int64 `json:"create_time"` - CreateTimeMs gateioTime `json:"create_time_ms"` + CreateTime Time `json:"create_time"` + CreateTimeMs Time `json:"create_time_ms"` Side string `json:"side"` Amount types.Number `json:"amount"` Role string `json:"role"` @@ -2115,8 +2138,8 @@ type WsUserPersonalTrade struct { // WsSpotBalance represents a spot balance. type WsSpotBalance struct { - Timestamp types.Number `json:"timestamp"` - TimestampMs types.Number `json:"timestamp_ms"` + Timestamp Time `json:"timestamp"` + TimestampMs Time `json:"timestamp_ms"` User string `json:"user"` Currency string `json:"currency"` Change types.Number `json:"change"` @@ -2126,8 +2149,8 @@ type WsSpotBalance struct { // WsMarginBalance represents margin account balance push data type WsMarginBalance struct { - Timestamp types.Number `json:"timestamp"` - TimestampMs types.Number `json:"timestamp_ms"` + Timestamp Time `json:"timestamp"` + TimestampMs Time `json:"timestamp_ms"` User string `json:"user"` CurrencyPair string `json:"currency_pair"` Currency string `json:"currency"` @@ -2140,19 +2163,19 @@ type WsMarginBalance struct { // WsFundingBalance represents funding balance push data. type WsFundingBalance struct { - Timestamp int64 `json:"timestamp,string"` - TimestampMs types.Number `json:"timestamp_ms"` - User string `json:"user"` - Currency string `json:"currency"` - Change string `json:"change"` - Freeze string `json:"freeze"` - Lent string `json:"lent"` + Timestamp Time `json:"timestamp"` + TimestampMs Time `json:"timestamp_ms"` + User string `json:"user"` + Currency string `json:"currency"` + Change string `json:"change"` + Freeze string `json:"freeze"` + Lent string `json:"lent"` } // WsCrossMarginBalance represents a cross margin balance detail type WsCrossMarginBalance struct { - Timestamp int64 `json:"timestamp,string"` - TimestampMs types.Number `json:"timestamp_ms"` + Timestamp Time `json:"timestamp"` + TimestampMs Time `json:"timestamp_ms"` User string `json:"user"` Currency string `json:"currency"` Change string `json:"change"` @@ -2162,7 +2185,7 @@ type WsCrossMarginBalance struct { // WsCrossMarginLoan represents a cross margin loan push data type WsCrossMarginLoan struct { - Timestamp gateioTime `json:"timestamp"` + Timestamp Time `json:"timestamp"` User string `json:"user"` Currency string `json:"currency"` Change string `json:"change"` @@ -2197,15 +2220,15 @@ type WsFutureTicker struct { type WsFuturesTrades struct { Size float64 `json:"size"` ID int64 `json:"id"` - CreateTime gateioTime `json:"create_time"` - CreateTimeMs gateioTime `json:"create_time_ms"` + CreateTime Time `json:"create_time"` + CreateTimeMs Time `json:"create_time_ms"` Price types.Number `json:"price"` Contract currency.Pair `json:"contract"` } // WsFuturesOrderbookTicker represents the orderbook ticker push data type WsFuturesOrderbookTicker struct { - TimestampMs gateioTime `json:"t"` + TimestampMs Time `json:"t"` UpdateID int64 `json:"u"` CurrencyPair string `json:"s"` BestBidPrice types.Number `json:"b"` @@ -2216,7 +2239,7 @@ type WsFuturesOrderbookTicker struct { // WsFuturesAndOptionsOrderbookUpdate represents futures and options account orderbook update push data type WsFuturesAndOptionsOrderbookUpdate struct { - TimestampInMs int64 `json:"t"` + TimestampInMs Time `json:"t"` ContractName currency.Pair `json:"s"` FirstUpdatedID int64 `json:"U"` LastUpdatedID int64 `json:"u"` @@ -2232,7 +2255,7 @@ type WsFuturesAndOptionsOrderbookUpdate struct { // WsFuturesOrderbookSnapshot represents a futures orderbook snapshot push data type WsFuturesOrderbookSnapshot struct { - TimestampInMs gateioTime `json:"t"` + TimestampInMs Time `json:"t"` Contract currency.Pair `json:"contract"` OrderbookID int64 `json:"id"` Asks []struct { @@ -2256,12 +2279,12 @@ type WsFuturesOrderbookUpdateEvent struct { // WsFuturesOrder represents futures order type WsFuturesOrder struct { Contract currency.Pair `json:"contract"` - CreateTime gateioTime `json:"create_time"` - CreateTimeMs gateioTime `json:"create_time_ms"` + CreateTime Time `json:"create_time"` + CreateTimeMs Time `json:"create_time_ms"` FillPrice float64 `json:"fill_price"` FinishAs string `json:"finish_as"` - FinishTime int64 `json:"finish_time"` - FinishTimeMs gateioTime `json:"finish_time_ms"` + FinishTime Time `json:"finish_time"` + FinishTimeMs Time `json:"finish_time_ms"` Iceberg int64 `json:"iceberg"` ID int64 `json:"id"` IsClose bool `json:"is_close"` @@ -2283,8 +2306,8 @@ type WsFuturesOrder struct { // WsFuturesUserTrade represents a futures account user trade push data type WsFuturesUserTrade struct { ID string `json:"id"` - CreateTime gateioTime `json:"create_time"` - CreateTimeMs gateioTime `json:"create_time_ms"` + CreateTime Time `json:"create_time"` + CreateTimeMs Time `json:"create_time_ms"` Contract currency.Pair `json:"contract"` OrderID string `json:"order_id"` Size float64 `json:"size"` @@ -2297,43 +2320,43 @@ type WsFuturesUserTrade struct { // WsFuturesLiquidationNotification represents a liquidation notification push data type WsFuturesLiquidationNotification struct { - EntryPrice int64 `json:"entry_price"` - FillPrice float64 `json:"fill_price"` - Left float64 `json:"left"` - Leverage float64 `json:"leverage"` - LiqPrice int64 `json:"liq_price"` - Margin float64 `json:"margin"` - MarkPrice int64 `json:"mark_price"` - OrderID int64 `json:"order_id"` - OrderPrice float64 `json:"order_price"` - Size float64 `json:"size"` - Time int64 `json:"time"` - TimeMs gateioTime `json:"time_ms"` - Contract string `json:"contract"` - User string `json:"user"` + EntryPrice int64 `json:"entry_price"` + FillPrice float64 `json:"fill_price"` + Left float64 `json:"left"` + Leverage float64 `json:"leverage"` + LiqPrice int64 `json:"liq_price"` + Margin float64 `json:"margin"` + MarkPrice int64 `json:"mark_price"` + OrderID int64 `json:"order_id"` + OrderPrice float64 `json:"order_price"` + Size float64 `json:"size"` + Time Time `json:"time"` + TimeMs Time `json:"time_ms"` + Contract string `json:"contract"` + User string `json:"user"` } // WsFuturesAutoDeleveragesNotification represents futures auto deleverages push data type WsFuturesAutoDeleveragesNotification struct { - EntryPrice float64 `json:"entry_price"` - FillPrice float64 `json:"fill_price"` - PositionSize int64 `json:"position_size"` - TradeSize int64 `json:"trade_size"` - Time gateioTime `json:"time"` - TimeMs gateioTime `json:"time_ms"` - Contract string `json:"contract"` - User string `json:"user"` + EntryPrice float64 `json:"entry_price"` + FillPrice float64 `json:"fill_price"` + PositionSize int64 `json:"position_size"` + TradeSize int64 `json:"trade_size"` + Time Time `json:"time"` + TimeMs Time `json:"time_ms"` + Contract string `json:"contract"` + User string `json:"user"` } // WsPositionClose represents a close position futures push data type WsPositionClose struct { - Contract string `json:"contract"` - ProfitAndLoss float64 `json:"pnl,omitempty"` - Side string `json:"side"` - Text string `json:"text"` - Time gateioTime `json:"time"` - TimeMs gateioTime `json:"time_ms"` - User string `json:"user"` + Contract string `json:"contract"` + ProfitAndLoss float64 `json:"pnl,omitempty"` + Side string `json:"side"` + Text string `json:"text"` + Time Time `json:"time"` + TimeMs Time `json:"time_ms"` + User string `json:"user"` // Added in options close position push datas SettleSize float64 `json:"settle_size,omitempty"` @@ -2342,49 +2365,49 @@ type WsPositionClose struct { // WsBalance represents a options and futures balance push data type WsBalance struct { - Balance float64 `json:"balance"` - Change float64 `json:"change"` - Text string `json:"text"` - Time gateioTime `json:"time"` - TimeMs gateioTime `json:"time_ms"` - Type string `json:"type"` - User string `json:"user"` + Balance float64 `json:"balance"` + Change float64 `json:"change"` + Text string `json:"text"` + Time Time `json:"time"` + TimeMs Time `json:"time_ms"` + Type string `json:"type"` + User string `json:"user"` } // WsFuturesReduceRiskLimitNotification represents a futures reduced risk limit push data type WsFuturesReduceRiskLimitNotification struct { - CancelOrders int64 `json:"cancel_orders"` - Contract string `json:"contract"` - LeverageMax int64 `json:"leverage_max"` - LiqPrice float64 `json:"liq_price"` - MaintenanceRate float64 `json:"maintenance_rate"` - RiskLimit int64 `json:"risk_limit"` - Time gateioTime `json:"time"` - TimeMs gateioTime `json:"time_ms"` - User string `json:"user"` + CancelOrders int64 `json:"cancel_orders"` + Contract string `json:"contract"` + LeverageMax int64 `json:"leverage_max"` + LiqPrice float64 `json:"liq_price"` + MaintenanceRate float64 `json:"maintenance_rate"` + RiskLimit int64 `json:"risk_limit"` + Time Time `json:"time"` + TimeMs Time `json:"time_ms"` + User string `json:"user"` } // WsFuturesPosition represents futures notify positions update. type WsFuturesPosition struct { - Contract string `json:"contract"` - CrossLeverageLimit float64 `json:"cross_leverage_limit"` - EntryPrice float64 `json:"entry_price"` - HistoryPnl float64 `json:"history_pnl"` - HistoryPoint int64 `json:"history_point"` - LastClosePnl float64 `json:"last_close_pnl"` - Leverage float64 `json:"leverage"` - LeverageMax float64 `json:"leverage_max"` - LiqPrice float64 `json:"liq_price"` - MaintenanceRate float64 `json:"maintenance_rate"` - Margin float64 `json:"margin"` - Mode string `json:"mode"` - RealisedPnl float64 `json:"realised_pnl"` - RealisedPoint float64 `json:"realised_point"` - RiskLimit float64 `json:"risk_limit"` - Size float64 `json:"size"` - Time gateioTime `json:"time"` - TimeMs gateioTime `json:"time_ms"` - User string `json:"user"` + Contract string `json:"contract"` + CrossLeverageLimit float64 `json:"cross_leverage_limit"` + EntryPrice float64 `json:"entry_price"` + HistoryPnl float64 `json:"history_pnl"` + HistoryPoint int64 `json:"history_point"` + LastClosePnl float64 `json:"last_close_pnl"` + Leverage float64 `json:"leverage"` + LeverageMax float64 `json:"leverage_max"` + LiqPrice float64 `json:"liq_price"` + MaintenanceRate float64 `json:"maintenance_rate"` + Margin float64 `json:"margin"` + Mode string `json:"mode"` + RealisedPnl float64 `json:"realised_pnl"` + RealisedPoint float64 `json:"realised_point"` + RiskLimit float64 `json:"risk_limit"` + Size float64 `json:"size"` + Time Time `json:"time"` + TimeMs Time `json:"time_ms"` + User string `json:"user"` } // WsFuturesAutoOrder represents an auto order push data. @@ -2407,13 +2430,13 @@ type WsFuturesAutoOrder struct { IsClose bool `json:"is_close"` IsReduceOnly bool `json:"is_reduce_only"` } `json:"initial"` - ID int64 `json:"id"` - TradeID int64 `json:"trade_id"` - Status string `json:"status"` - Reason string `json:"reason"` - CreateTime gateioTime `json:"create_time"` - Name string `json:"name"` - IsStopOrder bool `json:"is_stop_order"` + ID int64 `json:"id"` + TradeID int64 `json:"trade_id"` + Status string `json:"status"` + Reason string `json:"reason"` + CreateTime Time `json:"create_time"` + Name string `json:"name"` + IsStopOrder bool `json:"is_stop_order"` StopTrigger struct { Rule int64 `json:"rule"` TriggerPrice string `json:"trigger_price"` @@ -2432,81 +2455,81 @@ type WsOptionUnderlyingTicker struct { // WsOptionsTrades represents options trades for websocket push data. type WsOptionsTrades struct { ID int64 `json:"id"` - CreateTime gateioTime `json:"create_time"` + CreateTime Time `json:"create_time"` Contract currency.Pair `json:"contract"` Size float64 `json:"size"` Price float64 `json:"price"` // Added in options websocket push data - CreateTimeMs gateioTime `json:"create_time_ms"` - Underlying string `json:"underlying"` - IsCall bool `json:"is_call"` // added in underlying trades + CreateTimeMs Time `json:"create_time_ms"` + Underlying string `json:"underlying"` + IsCall bool `json:"is_call"` // added in underlying trades } // WsOptionsUnderlyingPrice represents the underlying price. type WsOptionsUnderlyingPrice struct { - Underlying string `json:"underlying"` - Price float64 `json:"price"` - UpdateTime gateioTime `json:"time"` - UpdateTimeMs gateioTime `json:"time_ms"` + Underlying string `json:"underlying"` + Price float64 `json:"price"` + UpdateTime Time `json:"time"` + UpdateTimeMs Time `json:"time_ms"` } // WsOptionsMarkPrice represents options mark price push data. type WsOptionsMarkPrice struct { - Contract string `json:"contract"` - Price float64 `json:"price"` - UpdateTimeMs gateioTime `json:"time_ms"` - UpdateTime gateioTime `json:"time"` + Contract string `json:"contract"` + Price float64 `json:"price"` + UpdateTimeMs Time `json:"time_ms"` + UpdateTime Time `json:"time"` } // WsOptionsSettlement represents a options settlement push data. type WsOptionsSettlement struct { - Contract string `json:"contract"` - OrderbookID int64 `json:"orderbook_id"` - PositionSize float64 `json:"position_size"` - Profit float64 `json:"profit"` - SettlePrice float64 `json:"settle_price"` - StrikePrice float64 `json:"strike_price"` - Tag string `json:"tag"` - TradeID int64 `json:"trade_id"` - TradeSize int64 `json:"trade_size"` - Underlying string `json:"underlying"` - UpdateTime gateioTime `json:"time"` - UpdateTimeMs gateioTime `json:"time_ms"` + Contract string `json:"contract"` + OrderbookID int64 `json:"orderbook_id"` + PositionSize float64 `json:"position_size"` + Profit float64 `json:"profit"` + SettlePrice float64 `json:"settle_price"` + StrikePrice float64 `json:"strike_price"` + Tag string `json:"tag"` + TradeID int64 `json:"trade_id"` + TradeSize int64 `json:"trade_size"` + Underlying string `json:"underlying"` + UpdateTime Time `json:"time"` + UpdateTimeMs Time `json:"time_ms"` } // WsOptionsContract represents an option contract push data. type WsOptionsContract struct { - Contract string `json:"contract"` - CreateTime gateioTime `json:"create_time"` - ExpirationTime int64 `json:"expiration_time"` - InitMarginHigh float64 `json:"init_margin_high"` - InitMarginLow float64 `json:"init_margin_low"` - IsCall bool `json:"is_call"` - MaintMarginBase float64 `json:"maint_margin_base"` - MakerFeeRate float64 `json:"maker_fee_rate"` - MarkPriceRound float64 `json:"mark_price_round"` - MinBalanceShort float64 `json:"min_balance_short"` - MinOrderMargin float64 `json:"min_order_margin"` - Multiplier float64 `json:"multiplier"` - OrderPriceDeviate float64 `json:"order_price_deviate"` - OrderPriceRound float64 `json:"order_price_round"` - OrderSizeMax float64 `json:"order_size_max"` - OrderSizeMin float64 `json:"order_size_min"` - OrdersLimit float64 `json:"orders_limit"` - RefDiscountRate float64 `json:"ref_discount_rate"` - RefRebateRate float64 `json:"ref_rebate_rate"` - StrikePrice float64 `json:"strike_price"` - Tag string `json:"tag"` - TakerFeeRate float64 `json:"taker_fee_rate"` - Underlying string `json:"underlying"` - Time gateioTime `json:"time"` - TimeMs gateioTime `json:"time_ms"` + Contract string `json:"contract"` + CreateTime Time `json:"create_time"` + ExpirationTime Time `json:"expiration_time"` + InitMarginHigh float64 `json:"init_margin_high"` + InitMarginLow float64 `json:"init_margin_low"` + IsCall bool `json:"is_call"` + MaintMarginBase float64 `json:"maint_margin_base"` + MakerFeeRate float64 `json:"maker_fee_rate"` + MarkPriceRound float64 `json:"mark_price_round"` + MinBalanceShort float64 `json:"min_balance_short"` + MinOrderMargin float64 `json:"min_order_margin"` + Multiplier float64 `json:"multiplier"` + OrderPriceDeviate float64 `json:"order_price_deviate"` + OrderPriceRound float64 `json:"order_price_round"` + OrderSizeMax float64 `json:"order_size_max"` + OrderSizeMin float64 `json:"order_size_min"` + OrdersLimit float64 `json:"orders_limit"` + RefDiscountRate float64 `json:"ref_discount_rate"` + RefRebateRate float64 `json:"ref_rebate_rate"` + StrikePrice float64 `json:"strike_price"` + Tag string `json:"tag"` + TakerFeeRate float64 `json:"taker_fee_rate"` + Underlying string `json:"underlying"` + Time Time `json:"time"` + TimeMs Time `json:"time_ms"` } // WsOptionsContractCandlestick represents an options contract candlestick push data. type WsOptionsContractCandlestick struct { - Timestamp int64 `json:"t"` + Timestamp Time `json:"t"` TotalVolume float64 `json:"v"` ClosePrice types.Number `json:"c"` HighestPrice types.Number `json:"h"` @@ -2518,7 +2541,7 @@ type WsOptionsContractCandlestick struct { // WsOptionsOrderbookTicker represents options orderbook ticker push data. type WsOptionsOrderbookTicker struct { - UpdateTimestamp gateioTime `json:"t"` + UpdateTimestamp Time `json:"t"` UpdateID int64 `json:"u"` ContractName string `json:"s"` BidPrice types.Number `json:"b"` @@ -2529,7 +2552,7 @@ type WsOptionsOrderbookTicker struct { // WsOptionsOrderbookSnapshot represents the options orderbook snapshot push data. type WsOptionsOrderbookSnapshot struct { - Timestamp gateioTime `json:"t"` + Timestamp Time `json:"t"` Contract currency.Pair `json:"contract"` ID int64 `json:"id"` Asks []struct { @@ -2546,7 +2569,7 @@ type WsOptionsOrderbookSnapshot struct { type WsOptionsOrder struct { ID int64 `json:"id"` Contract currency.Pair `json:"contract"` - CreateTime int64 `json:"create_time"` + CreateTime Time `json:"create_time"` FillPrice float64 `json:"fill_price"` FinishAs string `json:"finish_as"` Iceberg float64 `json:"iceberg"` @@ -2565,8 +2588,8 @@ type WsOptionsOrder struct { Tkfr float64 `json:"tkfr"` Underlying string `json:"underlying"` User string `json:"user"` - CreationTime gateioTime `json:"time"` - CreationTimeMs gateioTime `json:"time_ms"` + CreationTime Time `json:"time"` + CreationTimeMs Time `json:"time_ms"` } // WsOptionsUserTrade represents user's personal trades of option account. @@ -2575,8 +2598,8 @@ type WsOptionsUserTrade struct { Underlying string `json:"underlying"` OrderID string `json:"order"` Contract currency.Pair `json:"contract"` - CreateTime gateioTime `json:"create_time"` - CreateTimeMs gateioTime `json:"create_time_ms"` + CreateTime Time `json:"create_time"` + CreateTimeMs Time `json:"create_time_ms"` Price types.Number `json:"price"` Role string `json:"role"` Size float64 `json:"size"` @@ -2584,37 +2607,37 @@ type WsOptionsUserTrade struct { // WsOptionsLiquidates represents the liquidates push data of option account. type WsOptionsLiquidates struct { - User string `json:"user"` - InitMargin float64 `json:"init_margin"` - MaintMargin float64 `json:"maint_margin"` - OrderMargin float64 `json:"order_margin"` - Time gateioTime `json:"time"` - TimeMs gateioTime `json:"time_ms"` + User string `json:"user"` + InitMargin float64 `json:"init_margin"` + MaintMargin float64 `json:"maint_margin"` + OrderMargin float64 `json:"order_margin"` + Time Time `json:"time"` + TimeMs Time `json:"time_ms"` } // WsOptionsUserSettlement represents user's personal settlements push data of options account. type WsOptionsUserSettlement struct { - User string `json:"user"` - Contract string `json:"contract"` - RealisedPnl float64 `json:"realised_pnl"` - SettlePrice float64 `json:"settle_price"` - SettleProfit float64 `json:"settle_profit"` - Size float64 `json:"size"` - StrikePrice float64 `json:"strike_price"` - Underlying string `json:"underlying"` - SettleTime gateioTime `json:"time"` - SettleTimeMs gateioTime `json:"time_ms"` + User string `json:"user"` + Contract string `json:"contract"` + RealisedPnl float64 `json:"realised_pnl"` + SettlePrice float64 `json:"settle_price"` + SettleProfit float64 `json:"settle_profit"` + Size float64 `json:"size"` + StrikePrice float64 `json:"strike_price"` + Underlying string `json:"underlying"` + SettleTime Time `json:"time"` + SettleTimeMs Time `json:"time_ms"` } // WsOptionsPosition represents positions push data for options account. type WsOptionsPosition struct { - EntryPrice float64 `json:"entry_price"` - RealisedPnl float64 `json:"realised_pnl"` - Size float64 `json:"size"` - Contract string `json:"contract"` - User string `json:"user"` - UpdateTime gateioTime `json:"time"` - UpdateTimeMs gateioTime `json:"time_ms"` + EntryPrice float64 `json:"entry_price"` + RealisedPnl float64 `json:"realised_pnl"` + Size float64 `json:"size"` + Contract string `json:"contract"` + User string `json:"user"` + UpdateTime Time `json:"time"` + UpdateTimeMs Time `json:"time_ms"` } // InterSubAccountTransferParams represents parameters to transfer funds between sub-accounts. @@ -2657,8 +2680,8 @@ type CreateAPIKeyResponse struct { APIKey string `json:"key"` Secret string `json:"secret"` State int64 `json:"state"` // State 1 - normal 2 - locked 3 - frozen - CreatedAt gateioTime `json:"created_at"` - UpdatedAt gateioTime `json:"updated_at"` + CreatedAt Time `json:"created_at"` + UpdatedAt Time `json:"updated_at"` } // PriceAndAmount used in updating an order diff --git a/exchanges/gateio/gateio_websocket.go b/exchanges/gateio/gateio_websocket.go index 5ed81aaf..a5b7b43f 100644 --- a/exchanges/gateio/gateio_websocket.go +++ b/exchanges/gateio/gateio_websocket.go @@ -125,7 +125,7 @@ func (g *Gateio) wsHandleData(respRaw []byte) error { switch push.Channel { // TODO: Convert function params below to only use push.Result case spotTickerChannel: - return g.processTicker(push.Result, push.Time) + return g.processTicker(push.Result, push.Time.Time()) case spotTradesChannel: return g.processTrades(push.Result) case spotCandlesticksChannel: @@ -160,7 +160,7 @@ func (g *Gateio) wsHandleData(respRaw []byte) error { return nil } -func (g *Gateio) processTicker(incoming []byte, pushTime int64) error { +func (g *Gateio) processTicker(incoming []byte, pushTime time.Time) error { var data WsTicker err := json.Unmarshal(incoming, &data) if err != nil { @@ -177,7 +177,7 @@ func (g *Gateio) processTicker(incoming []byte, pushTime int64) error { Ask: data.LowestAsk.Float64(), AssetType: asset.Spot, Pair: data.CurrencyPair, - LastUpdated: time.Unix(pushTime, 0), + LastUpdated: pushTime, } assetPairEnabled := g.listOfAssetsCurrencyPairEnabledFor(data.CurrencyPair) if assetPairEnabled[asset.Spot] { @@ -253,7 +253,7 @@ func (g *Gateio) processCandlestick(incoming []byte) error { Pair: currencyPair, AssetType: asset.Spot, Exchange: g.Name, - StartTime: time.Unix(data.Timestamp, 0), + StartTime: data.Timestamp.Time(), Interval: icp[0], OpenPrice: data.OpenPrice.Float64(), ClosePrice: data.ClosePrice.Float64(), @@ -289,7 +289,7 @@ func (g *Gateio) processOrderbookTicker(incoming []byte) error { Exchange: g.Name, Pair: data.CurrencyPair, Asset: asset.Spot, - LastUpdated: time.UnixMilli(data.UpdateTimeMS), + LastUpdated: data.UpdateTimeMS.Time(), Bids: []orderbook.Tranche{{Price: data.BestBidPrice.Float64(), Amount: data.BestBidAmount.Float64()}}, Asks: []orderbook.Tranche{{Price: data.BestAskPrice.Float64(), Amount: data.BestAskAmount.Float64()}}, }) diff --git a/exchanges/gateio/gateio_wrapper.go b/exchanges/gateio/gateio_wrapper.go index bb62857b..0972091d 100644 --- a/exchanges/gateio/gateio_wrapper.go +++ b/exchanges/gateio/gateio_wrapper.go @@ -1606,7 +1606,7 @@ func (g *Gateio) GetActiveOrders(ctx context.Context, req *order.MultiOrderReque continue } var side order.Side - side, err = order.StringToOrderSide(spotOrders[x].Orders[x].Side) + side, err = order.StringToOrderSide(spotOrders[x].Orders[y].Side) if err != nil { log.Errorf(log.ExchangeSys, "%s %v", g.Name, err) } diff --git a/exchanges/gateio/gateio_ws_futures.go b/exchanges/gateio/gateio_ws_futures.go index c24fbcf6..8962212d 100644 --- a/exchanges/gateio/gateio_ws_futures.go +++ b/exchanges/gateio/gateio_ws_futures.go @@ -236,7 +236,7 @@ func (g *Gateio) wsHandleFuturesData(respRaw []byte, assetType asset.Item) error case futuresTradesChannel: return g.processFuturesTrades(respRaw, assetType) case futuresOrderbookChannel: - return g.processFuturesOrderbookSnapshot(push.Event, push.Result, assetType, push.Time) + return g.processFuturesOrderbookSnapshot(push.Event, push.Result, assetType, push.Time.Time()) case futuresOrderbookTickerChannel: return g.processFuturesOrderbookTicker(push.Result) case futuresOrderbookUpdateChannel: @@ -557,7 +557,7 @@ func (g *Gateio) processFuturesAndOptionsOrderbookUpdate(incoming []byte, assetT } } updates := orderbook.Update{ - UpdateTime: time.UnixMilli(data.TimestampInMs), + UpdateTime: data.TimestampInMs.Time(), Pair: data.ContractName, Asset: assetType, } @@ -577,7 +577,7 @@ func (g *Gateio) processFuturesAndOptionsOrderbookUpdate(incoming []byte, assetT return g.Websocket.Orderbook.Update(&updates) } -func (g *Gateio) processFuturesOrderbookSnapshot(event string, incoming []byte, assetType asset.Item, pushTime int64) error { +func (g *Gateio) processFuturesOrderbookSnapshot(event string, incoming []byte, assetType asset.Item, pushTime time.Time) error { if event == "all" { var data WsFuturesOrderbookSnapshot err := json.Unmarshal(incoming, &data) @@ -643,7 +643,7 @@ func (g *Gateio) processFuturesOrderbookSnapshot(event string, incoming []byte, Asset: assetType, Exchange: g.Name, Pair: currencyPair, - LastUpdated: time.Unix(pushTime, 0), + LastUpdated: pushTime, VerifyOrderbook: g.CanVerifyOrderbook, }) if err != nil { diff --git a/exchanges/gateio/gateio_ws_option.go b/exchanges/gateio/gateio_ws_option.go index d69f5425..fe1384c8 100644 --- a/exchanges/gateio/gateio_ws_option.go +++ b/exchanges/gateio/gateio_ws_option.go @@ -379,7 +379,7 @@ func (g *Gateio) wsHandleOptionsData(respRaw []byte) error { optionsUnderlyingCandlesticksChannel: return g.processOptionsCandlestickPushData(respRaw) case optionsOrderbookChannel: - return g.processOptionsOrderbookSnapshotPushData(push.Event, push.Result, push.Time) + return g.processOptionsOrderbookSnapshotPushData(push.Event, push.Result, push.Time.Time()) case optionsOrderbookTickerChannel: return g.processOrderbookTickerPushData(respRaw) case optionsOrderbookUpdateChannel: @@ -531,7 +531,7 @@ func (g *Gateio) processOptionsCandlestickPushData(data []byte) error { Pair: currencyPair, AssetType: asset.Options, Exchange: g.Name, - StartTime: time.Unix(resp.Result[x].Timestamp, 0), + StartTime: resp.Result[x].Timestamp.Time(), Interval: icp[0], OpenPrice: resp.Result[x].OpenPrice.Float64(), ClosePrice: resp.Result[x].ClosePrice.Float64(), @@ -554,7 +554,7 @@ func (g *Gateio) processOrderbookTickerPushData(incoming []byte) error { return nil } -func (g *Gateio) processOptionsOrderbookSnapshotPushData(event string, incoming []byte, pushTime int64) error { +func (g *Gateio) processOptionsOrderbookSnapshotPushData(event string, incoming []byte, pushTime time.Time) error { if event == "all" { var data WsOptionsOrderbookSnapshot err := json.Unmarshal(incoming, &data) @@ -618,7 +618,7 @@ func (g *Gateio) processOptionsOrderbookSnapshotPushData(event string, incoming Asset: asset.Options, Exchange: g.Name, Pair: currencyPair, - LastUpdated: time.Unix(pushTime, 0), + LastUpdated: pushTime, VerifyOrderbook: g.CanVerifyOrderbook, }) if err != nil {