From 8114fae0e9b7e12baf7e20a68ec932896062737d Mon Sep 17 00:00:00 2001 From: Samuel Reid <43227667+cranktakular@users.noreply.github.com> Date: Tue, 8 Oct 2024 18:18:25 +1100 Subject: [PATCH] Fixes, cleanup, and websocket progress --- exchanges/bitget/bitget.go | 797 +++++------ exchanges/bitget/bitget_test.go | 615 +++----- exchanges/bitget/bitget_types.go | 1986 ++++++++++++++------------ exchanges/bitget/bitget_websocket.go | 448 ++++-- exchanges/bitget/bitget_wrapper.go | 264 ++-- 5 files changed, 2076 insertions(+), 2034 deletions(-) diff --git a/exchanges/bitget/bitget.go b/exchanges/bitget/bitget.go index d15c09ccb1c..c2dac5e6c57 100644 --- a/exchanges/bitget/bitget.go +++ b/exchanges/bitget/bitget.go @@ -205,11 +205,14 @@ const ( // Unauthenticated bitgetCandleDailyChannel = "candle1D" // There's one of these for each time period, but we'll ignore those for now bitgetBookFullChannel = "books" // There's more of these for varying orderbook depths, ignored for now + bitgetIndexPriceChannel = "index-price" // Authenticated - bitgetFillChannel = "fill" - bitgetOrdersChannel = "orders" - bitgetOrdersAlgoChannel = "orders-algo" + bitgetFillChannel = "fill" + bitgetOrdersChannel = "orders" + bitgetOrdersAlgoChannel = "orders-algo" + bitgetPositionsChannel = "positions" + bitgetPositionsHistoryChannel = "positions-history" errIntervalNotSupported = "interval not supported" errAuthenticatedWebsocketDisabled = "%v AuthenticatedWebsocketAPISupport not enabled" @@ -329,8 +332,7 @@ func (bi *Bitget) GetTradeRate(ctx context.Context, pair, businessType string) ( var resp struct { TradeRateResp `json:"data"` } - return &resp.TradeRateResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, - bitgetCommon+bitgetTradeRate, vals, nil, &resp) + return &resp.TradeRateResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, bitgetCommon+bitgetTradeRate, vals, nil, &resp) } // GetSpotTransactionRecords returns the user's spot transaction records @@ -353,8 +355,7 @@ func (bi *Bitget) GetSpotTransactionRecords(ctx context.Context, currency string var resp struct { SpotTrResp []SpotTrResp `json:"data"` } - return resp.SpotTrResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate1, http.MethodGet, - bitgetTax+bitgetSpotRecord, params.Values, nil, &resp) + return resp.SpotTrResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate1, http.MethodGet, bitgetTax+bitgetSpotRecord, params.Values, nil, &resp) } // GetFuturesTransactionRecords returns the user's futures transaction records @@ -379,8 +380,7 @@ func (bi *Bitget) GetFuturesTransactionRecords(ctx context.Context, productType, var resp struct { FutureTrResp []FutureTrResp `json:"data"` } - return resp.FutureTrResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate1, http.MethodGet, - bitgetTax+bitgetFutureRecord, params.Values, nil, &resp) + return resp.FutureTrResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate1, http.MethodGet, bitgetTax+bitgetFutureRecord, params.Values, nil, &resp) } // GetMarginTransactionRecords returns the user's margin transaction records @@ -404,8 +404,7 @@ func (bi *Bitget) GetMarginTransactionRecords(ctx context.Context, marginType, c var resp struct { MarginTrResp []MarginTrResp `json:"data"` } - return resp.MarginTrResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate1, http.MethodGet, - bitgetTax+bitgetMarginRecord, params.Values, nil, &resp) + return resp.MarginTrResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate1, http.MethodGet, bitgetTax+bitgetMarginRecord, params.Values, nil, &resp) } // GetP2PTransactionRecords returns the user's P2P transaction records @@ -428,8 +427,7 @@ func (bi *Bitget) GetP2PTransactionRecords(ctx context.Context, currency string, var resp struct { P2PTrResp []P2PTrResp `json:"data"` } - return resp.P2PTrResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate1, http.MethodGet, - bitgetTax+bitgetP2PRecord, params.Values, nil, &resp) + return resp.P2PTrResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate1, http.MethodGet, bitgetTax+bitgetP2PRecord, params.Values, nil, &resp) } // GetP2PMerchantList returns detailed information on merchants @@ -445,8 +443,7 @@ func (bi *Bitget) GetP2PMerchantList(ctx context.Context, online string, limit, var resp struct { P2PMerListResp `json:"data"` } - return &resp.P2PMerListResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, - bitgetP2P+bitgetMerchantList, vals, nil, &resp) + return &resp.P2PMerListResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, bitgetP2P+bitgetMerchantList, vals, nil, &resp) } // GetMerchantInfo returns detailed information on the user as a merchant @@ -454,8 +451,7 @@ func (bi *Bitget) GetMerchantInfo(ctx context.Context) (*P2PMerInfoResp, error) var resp struct { P2PMerInfoResp `json:"data"` } - return &resp.P2PMerInfoResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, - bitgetP2P+bitgetMerchantInfo, nil, nil, &resp) + return &resp.P2PMerInfoResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, bitgetP2P+bitgetMerchantInfo, nil, nil, &resp) } // GetMerchantP2POrders returns information on the user's P2P orders @@ -483,8 +479,7 @@ func (bi *Bitget) GetMerchantP2POrders(ctx context.Context, startTime, endTime t var resp struct { P2POrdersResp `json:"data"` } - return &resp.P2POrdersResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, - bitgetP2P+bitgetOrderList, params.Values, nil, &resp) + return &resp.P2POrdersResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, bitgetP2P+bitgetOrderList, params.Values, nil, &resp) } // GetMerchantAdvertisementList returns information on a variety of merchant advertisements @@ -516,8 +511,7 @@ func (bi *Bitget) GetMerchantAdvertisementList(ctx context.Context, startTime, e AdList []P2PAdListResp `json:"advList"` } `json:"data"` } - return resp.Data.AdList, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, - bitgetP2P+bitgetAdvList, params.Values, nil, &resp) + return resp.Data.AdList, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, bitgetP2P+bitgetAdvList, params.Values, nil, &resp) } // GetSpotWhaleNetFlow returns the amount whales have been trading in a specified pair recently @@ -624,8 +618,7 @@ func (bi *Bitget) GetFuturesRatios(ctx context.Context, pair, period string) ([] return resp.RatioResp, bi.SendHTTPRequest(ctx, exchange.RestSpot, Rate1, path, vals, &resp) } -// GetSpotFundFlows returns information on volumes and buy/sell ratios for whales, dolphins, and fish for a -// particular pair +// GetSpotFundFlows returns information on volumes and buy/sell ratios for whales, dolphins, and fish for a particular pair func (bi *Bitget) GetSpotFundFlows(ctx context.Context, pair string) (*FundFlowResp, error) { if pair == "" { return nil, errPairEmpty @@ -677,8 +670,7 @@ func (bi *Bitget) GetFuturesAccountRatios(ctx context.Context, pair, period stri return resp.AccountRatioResp, bi.SendHTTPRequest(ctx, exchange.RestSpot, Rate1, path, vals, &resp) } -// CreateVirtualSubaccounts creates a batch of virtual subaccounts. These names must use English letters, -// no spaces, no numbers, and be exactly 8 characters long. +// CreateVirtualSubaccounts creates a batch of virtual subaccounts. These names must use English letters, no spaces, no numbers, and be exactly 8 characters long. func (bi *Bitget) CreateVirtualSubaccounts(ctx context.Context, subaccounts []string) (*CrVirSubResp, error) { if len(subaccounts) == 0 { return nil, errSubaccountEmpty @@ -690,8 +682,7 @@ func (bi *Bitget) CreateVirtualSubaccounts(ctx context.Context, subaccounts []st var resp struct { CrVirSubResp `json:"data"` } - return &resp.CrVirSubResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate5, http.MethodPost, path, - nil, req, &resp) + return &resp.CrVirSubResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate5, http.MethodPost, path, nil, req, &resp) } // ModifyVirtualSubaccount changes the permissions and/or status of a virtual subaccount @@ -714,14 +705,10 @@ func (bi *Bitget) ModifyVirtualSubaccount(ctx context.Context, subaccountID, new var resp struct { SuccessBool `json:"data"` } - return &resp.SuccessBool, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate5, http.MethodPost, path, - nil, req, &resp) + return &resp.SuccessBool, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate5, http.MethodPost, path, nil, req, &resp) } -// CreateSubaccountAndAPIKey creates a subaccounts and an API key. Every account can have up to 20 sub-accounts, -// and every API key can have up to 10 API keys. The name of the sub-account must be exactly 8 English letters. -// The passphrase of the API key must be 8-32 letters and/or numbers. The label must be 20 or fewer characters. -// A maximum of 30 IPs can be a part of the whitelist. +// CreateSubaccountAndAPIKey creates a subaccounts and an API key. Every account can have up to 20 sub-accounts, and every API key can have up to 10 API keys. The name of the sub-account must be exactly 8 English letters. The passphrase of the API key must be 8-32 letters and/or numbers. The label must be 20 or fewer characters. A maximum of 30 IPs can be a part of the whitelist. func (bi *Bitget) CreateSubaccountAndAPIKey(ctx context.Context, subaccountName, passphrase, label string, whiteList, permList []string) ([]CrSubAccAPIKeyResp, error) { if subaccountName == "" { return nil, errSubaccountEmpty @@ -736,8 +723,7 @@ func (bi *Bitget) CreateSubaccountAndAPIKey(ctx context.Context, subaccountName, var resp struct { CrSubAccAPIKeyResp []CrSubAccAPIKeyResp `json:"data"` } - return resp.CrSubAccAPIKeyResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate1, http.MethodPost, - bitgetUser+bitgetBatchCreateSubAccApi, nil, req, &resp) + return resp.CrSubAccAPIKeyResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate1, http.MethodPost, bitgetUser+bitgetBatchCreateSubAccApi, nil, req, &resp) } // GetVirtualSubaccounts returns a list of the user's virtual sub-accounts @@ -754,8 +740,7 @@ func (bi *Bitget) GetVirtualSubaccounts(ctx context.Context, limit, pagination i var resp struct { GetVirSubResp `json:"data"` } - return &resp.GetVirSubResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, - nil, &resp) + return &resp.GetVirSubResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, &resp) } // CreateAPIKey creates an API key for the selected virtual sub-account @@ -780,12 +765,10 @@ func (bi *Bitget) CreateAPIKey(ctx context.Context, subaccountID, passphrase, la var resp struct { AlterAPIKeyResp `json:"data"` } - return &resp.AlterAPIKeyResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate5, http.MethodPost, path, - nil, req, &resp) + return &resp.AlterAPIKeyResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate5, http.MethodPost, path, nil, req, &resp) } -// ModifyAPIKey modifies the label, IP whitelist, and/or permissions of the API key associated with the selected -// virtual sub-account +// ModifyAPIKey modifies the label, IP whitelist, and/or permissions of the API key associated with the selected virtual sub-account func (bi *Bitget) ModifyAPIKey(ctx context.Context, subaccountID, passphrase, label, apiKey string, whiteList, permList []string) (*AlterAPIKeyResp, error) { if apiKey == "" { return nil, errAPIKeyEmpty @@ -810,8 +793,7 @@ func (bi *Bitget) ModifyAPIKey(ctx context.Context, subaccountID, passphrase, la var resp struct { AlterAPIKeyResp `json:"data"` } - return &resp.AlterAPIKeyResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate5, http.MethodPost, path, - nil, req, &resp) + return &resp.AlterAPIKeyResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate5, http.MethodPost, path, nil, req, &resp) } // GetAPIKeys lists the API keys associated with the selected virtual sub-account @@ -825,8 +807,7 @@ func (bi *Bitget) GetAPIKeys(ctx context.Context, subaccountID string) ([]GetAPI var resp struct { GetAPIKeyResp []GetAPIKeyResp `json:"data"` } - return resp.GetAPIKeyResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate5, http.MethodGet, path, vals, - nil, &resp) + return resp.GetAPIKeyResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate5, http.MethodGet, path, vals, nil, &resp) } // GetFundingAssets returns the user's assets @@ -838,8 +819,7 @@ func (bi *Bitget) GetFundingAssets(ctx context.Context, currency string) ([]Fund var resp struct { FundingAssetsResp []FundingAssetsResp `json:"data"` } - return resp.FundingAssetsResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, - bitgetAccount+bitgetFundingAssets, vals, nil, &resp) + return resp.FundingAssetsResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, bitgetAccount+bitgetFundingAssets, vals, nil, &resp) } // GetBotAccountAssets returns the user's bot account assets @@ -851,8 +831,7 @@ func (bi *Bitget) GetBotAccountAssets(ctx context.Context, accountType string) ( var resp struct { BotAccAssetsResp []BotAccAssetsResp `json:"data"` } - return resp.BotAccAssetsResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, - bitgetAccount+bitgetBotAssets, vals, nil, &resp) + return resp.BotAccAssetsResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, bitgetAccount+bitgetBotAssets, vals, nil, &resp) } // GetAssetOverview returns an overview of the user's assets across various account types @@ -860,22 +839,18 @@ func (bi *Bitget) GetAssetOverview(ctx context.Context) ([]AssetOverviewResp, er var resp struct { AssetOverviewResp []AssetOverviewResp `json:"data"` } - return resp.AssetOverviewResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate1, http.MethodGet, - bitgetAccount+bitgetAllAccountBalance, nil, nil, &resp) + return resp.AssetOverviewResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate1, http.MethodGet, bitgetAccount+bitgetAllAccountBalance, nil, nil, &resp) } -// GetConvertCoins returns a list of supported currencies, your balance in those currencies, and the maximum and -// minimum tradable amounts of those currencies +// GetConvertCoins returns a list of supported currencies, your balance in those currencies, and the maximum and minimum tradable amounts of those currencies func (bi *Bitget) GetConvertCoins(ctx context.Context) ([]ConvertCoinsResp, error) { var resp struct { ConvertCoinsResp []ConvertCoinsResp `json:"data"` } - return resp.ConvertCoinsResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, - bitgetConvert+bitgetCurrencies, nil, nil, &resp) + return resp.ConvertCoinsResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, bitgetConvert+bitgetCurrencies, nil, nil, &resp) } -// GetQuotedPrice returns the price of a given amount of one currency in terms of another currency, and an -// ID for this quote, to be used in a subsequent conversion +// GetQuotedPrice returns the price of a given amount of one currency in terms of another currency, and an ID for this quote, to be used in a subsequent conversion func (bi *Bitget) GetQuotedPrice(ctx context.Context, fromCurrency, toCurrency string, fromAmount, toAmount float64) (*QuotedPriceResp, error) { if fromCurrency == "" || toCurrency == "" { return nil, errCurrencyEmpty @@ -894,12 +869,10 @@ func (bi *Bitget) GetQuotedPrice(ctx context.Context, fromCurrency, toCurrency s var resp struct { QuotedPriceResp `json:"data"` } - return &resp.QuotedPriceResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, - bitgetConvert+bitgetQuotedPrice, vals, nil, &resp) + return &resp.QuotedPriceResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, bitgetConvert+bitgetQuotedPrice, vals, nil, &resp) } -// CommitConversion commits a conversion previously quoted by GetQuotedPrice. This quote has to have been issued -// within the last 8 seconds. +// CommitConversion commits a conversion previously quoted by GetQuotedPrice. This quote has to have been issued within the last 8 seconds. func (bi *Bitget) CommitConversion(ctx context.Context, fromCurrency, toCurrency, traceID string, fromAmount, toAmount, price float64) (*CommitConvResp, error) { if fromCurrency == "" || toCurrency == "" { return nil, errCurrencyEmpty @@ -924,8 +897,7 @@ func (bi *Bitget) CommitConversion(ctx context.Context, fromCurrency, toCurrency var resp struct { CommitConvResp `json:"data"` } - return &resp.CommitConvResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, - bitgetConvert+bitgetTrade, nil, req, &resp) + return &resp.CommitConvResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, bitgetConvert+bitgetTrade, nil, req, &resp) } // GetConvertHistory returns a list of the user's previous conversions @@ -945,8 +917,7 @@ func (bi *Bitget) GetConvertHistory(ctx context.Context, startTime, endTime time var resp struct { ConvHistResp `json:"data"` } - return &resp.ConvHistResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, - bitgetConvert+bitgetConvertRecord, params.Values, nil, &resp) + return &resp.ConvHistResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, bitgetConvert+bitgetConvertRecord, params.Values, nil, &resp) } // GetBGBConvertCoins returns a list of available currencies, with information on converting them to BGB @@ -956,8 +927,7 @@ func (bi *Bitget) GetBGBConvertCoins(ctx context.Context) ([]BGBConvertCoinsResp CoinList []BGBConvertCoinsResp `json:"coinList"` } `json:"data"` } - return resp.Data.CoinList, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, - bitgetConvert+bitgetConvertCoinList, nil, nil, &resp) + return resp.Data.CoinList, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, bitgetConvert+bitgetConvertCoinList, nil, nil, &resp) } // ConvertBGB converts all funds in the listed currencies to BGB @@ -973,8 +943,7 @@ func (bi *Bitget) ConvertBGB(ctx context.Context, currencies []string) ([]Conver OrderList []ConvertBGBResp `json:"orderList"` } `json:"data"` } - return resp.Data.OrderList, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, - bitgetConvert+bitgetBGBConvert, nil, req, &resp) + return resp.Data.OrderList, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, bitgetConvert+bitgetBGBConvert, nil, req, &resp) } // GetBGBConvertHistory returns a list of the user's previous BGB conversions @@ -995,8 +964,7 @@ func (bi *Bitget) GetBGBConvertHistory(ctx context.Context, orderID, limit, pagi var resp struct { BGBConvHistResp []BGBConvHistResp `json:"data"` } - return resp.BGBConvHistResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, - bitgetConvert+bitgetBGBConvertRecords, params.Values, nil, &resp) + return resp.BGBConvHistResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, bitgetConvert+bitgetBGBConvertRecords, params.Values, nil, &resp) } // GetCoinInfo returns information on all supported spot currencies, or a single currency of the user's choice @@ -1032,8 +1000,7 @@ func (bi *Bitget) GetSpotVIPFeeRate(ctx context.Context) ([]VIPFeeRateResp, erro return resp.VIPFeeRateResp, bi.SendHTTPRequest(ctx, exchange.RestSpot, Rate10, path, nil, &resp) } -// GetSpotTickerInformation returns the ticker information for all trading pairs, or a single pair of the user's -// choice +// GetSpotTickerInformation returns the ticker information for all trading pairs, or a single pair of the user's choice func (bi *Bitget) GetSpotTickerInformation(ctx context.Context, pair string) ([]TickerResp, error) { vals := url.Values{} vals.Set("symbol", pair) @@ -1044,9 +1011,7 @@ func (bi *Bitget) GetSpotTickerInformation(ctx context.Context, pair string) ([] return resp.TickerResp, bi.SendHTTPRequest(ctx, exchange.RestSpot, Rate20, path, vals, &resp) } -// GetSpotMergeDepth returns part of the orderbook, with options to merge orders of similar price levels together, -// and to change how many results are returned. Limit's a string instead of the typical int64 because the API -// will accept a value of "max" +// GetSpotMergeDepth returns part of the orderbook, with options to merge orders of similar price levels together, and to change how many results are returned. Limit's a string instead of the typical int64 because the API will accept a value of "max" func (bi *Bitget) GetSpotMergeDepth(ctx context.Context, pair, precision, limit string) (*DepthResp, error) { if pair == "" { return nil, errPairEmpty @@ -1062,8 +1027,7 @@ func (bi *Bitget) GetSpotMergeDepth(ctx context.Context, pair, precision, limit return &resp.DepthResp, bi.SendHTTPRequest(ctx, exchange.RestSpot, Rate20, path, vals, &resp) } -// GetOrderbookDepth returns the orderbook for a given trading pair, with options to merge orders of similar price -// levels together, and to change how many results are returned. +// GetOrderbookDepth returns the orderbook for a given trading pair, with options to merge orders of similar price levels together, and to change how many results are returned. func (bi *Bitget) GetOrderbookDepth(ctx context.Context, pair, step string, limit uint8) (*OrderbookResp, error) { vals := url.Values{} vals.Set("symbol", pair) @@ -1174,14 +1138,12 @@ func (bi *Bitget) PlaceSpotOrder(ctx context.Context, pair, side, orderType, str } path := bitgetSpot + bitgetTrade + bitgetPlaceOrder var resp *OrderIDResp - // I suspect the two rate limits have to do with distinguishing ordinary traders, and traders who are also - // copy trade leaders. Since this isn't detectable, it'll be handled in the relevant functions through a bool + // I suspect the two rate limits have to do with distinguishing ordinary traders, and traders who are also copy trade leaders. Since this isn't detectable, it'll be handled in the relevant functions through a bool rLim := Rate10 if isCopyTradeLeader { rLim = Rate1 } - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, rLim, http.MethodPost, path, nil, req, - &resp) + return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, rLim, http.MethodPost, path, nil, req, &resp) } // CancelSpotOrderByID cancels an order on the exchange @@ -1203,8 +1165,7 @@ func (bi *Bitget) CancelSpotOrderByID(ctx context.Context, pair, clientOrderID s } path := bitgetSpot + bitgetTrade + bitgetCancelOrder var resp *OrderIDResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // BatchPlaceSpotOrders places up to fifty orders on the exchange @@ -1227,8 +1188,7 @@ func (bi *Bitget) BatchPlaceSpotOrders(ctx context.Context, pair string, orders if isCopyTradeLeader { rLim = Rate1 } - return &resp.BatchOrderResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, rLim, http.MethodPost, path, nil, req, - &resp) + return &resp.BatchOrderResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, rLim, http.MethodPost, path, nil, req, &resp) } // BatchCancelOrders cancels up to fifty orders on the exchange @@ -1245,8 +1205,7 @@ func (bi *Bitget) BatchCancelOrders(ctx context.Context, pair string, orderIDs [ } path := bitgetSpot + bitgetTrade + bitgetBatchCancel var resp *BatchOrderResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // CancelOrdersBySymbol cancels orders for a given symbol. Doesn't return information on failures/successes @@ -1263,8 +1222,7 @@ func (bi *Bitget) CancelOrdersBySymbol(ctx context.Context, pair string) (string Symbol string `json:"symbol"` } `json:"data"` } - return resp.Data.Symbol, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate5, http.MethodPost, path, nil, req, - &resp) + return resp.Data.Symbol, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate5, http.MethodPost, path, nil, req, &resp) } // GetSpotOrderDetails returns information on a single order @@ -1305,8 +1263,7 @@ func (bi *Bitget) GetUnfilledOrders(ctx context.Context, pair string, startTime, var resp struct { UnfilledOrdersResp []UnfilledOrdersResp `json:"data"` } - return resp.UnfilledOrdersResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate20, http.MethodGet, path, params.Values, - nil, &resp) + return resp.UnfilledOrdersResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate20, http.MethodGet, path, params.Values, nil, &resp) } // GetHistoricalSpotOrders returns the user's spot order history @@ -1352,8 +1309,7 @@ func (bi *Bitget) GetSpotFills(ctx context.Context, pair string, startTime, endT var resp struct { SpotFillsResp []SpotFillsResp `json:"data"` } - return resp.SpotFillsResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + return resp.SpotFillsResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // PlacePlanSpotOrder sets up an order to be placed after certain conditions are met @@ -1395,8 +1351,7 @@ func (bi *Bitget) PlacePlanSpotOrder(ctx context.Context, pair, side, orderType, } path := bitgetSpot + bitgetTrade + bitgetPlacePlanOrder var resp *OrderIDResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate20, http.MethodPost, path, nil, req, - &resp) + return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate20, http.MethodPost, path, nil, req, &resp) } // ModifyPlanSpotOrder alters the price, trigger price, amount, or order type of a plan order @@ -1430,8 +1385,7 @@ func (bi *Bitget) ModifyPlanSpotOrder(ctx context.Context, orderID int64, client } path := bitgetSpot + bitgetTrade + bitgetModifyPlanOrder var resp *OrderIDResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate20, http.MethodPost, path, nil, req, - &resp) + return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate20, http.MethodPost, path, nil, req, &resp) } // CancelPlanSpotOrder cancels a plan order @@ -1450,8 +1404,7 @@ func (bi *Bitget) CancelPlanSpotOrder(ctx context.Context, orderID int64, client var resp struct { SuccessBool `json:"success"` } - return &resp.SuccessBool, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate20, http.MethodPost, path, nil, req, - &resp) + return &resp.SuccessBool, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate20, http.MethodPost, path, nil, req, &resp) } // GetCurrentSpotPlanOrders returns the user's current plan orders @@ -1476,8 +1429,7 @@ func (bi *Bitget) GetCurrentSpotPlanOrders(ctx context.Context, pair string, sta var resp struct { PlanSpotOrderResp `json:"data"` } - return &resp.PlanSpotOrderResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate20, http.MethodGet, path, params.Values, - nil, &resp) + return &resp.PlanSpotOrderResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate20, http.MethodGet, path, params.Values, nil, &resp) } // GetSpotPlanSubOrder returns the sub-orders of a triggered plan order @@ -1491,8 +1443,7 @@ func (bi *Bitget) GetSpotPlanSubOrder(ctx context.Context, orderID string) (*Sub var resp struct { SubOrderResp `json:"data"` } - return &resp.SubOrderResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate20, http.MethodGet, path, vals, nil, - &resp) + return &resp.SubOrderResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate20, http.MethodGet, path, vals, nil, &resp) } // GetSpotPlanOrderHistory returns the user's plan order history @@ -1517,8 +1468,7 @@ func (bi *Bitget) GetSpotPlanOrderHistory(ctx context.Context, pair string, star var resp struct { PlanSpotOrderResp `json:"data"` } - return &resp.PlanSpotOrderResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate20, http.MethodGet, path, params.Values, - nil, &resp) + return &resp.PlanSpotOrderResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate20, http.MethodGet, path, params.Values, nil, &resp) } // BatchCancelSpotPlanOrders cancels all plan orders, with the option to restrict to only those for particular pairs @@ -1529,8 +1479,7 @@ func (bi *Bitget) BatchCancelSpotPlanOrders(ctx context.Context, pairs []string) } path := bitgetSpot + bitgetTrade + bitgetBatchCancelPlanOrder var resp *BatchOrderResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate5, http.MethodPost, path, nil, req, - &resp) + return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate5, http.MethodPost, path, nil, req, &resp) } // GetAccountInfo returns the user's account information @@ -1581,8 +1530,7 @@ func (bi *Bitget) ModifyDepositAccount(ctx context.Context, accountType, currenc var resp struct { SuccessBool `json:"data"` } - return &resp.SuccessBool, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + return &resp.SuccessBool, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // GetSpotAccountBills returns a section of the user's billing history @@ -1608,8 +1556,7 @@ func (bi *Bitget) GetSpotAccountBills(ctx context.Context, currency, groupType, var resp struct { SpotAccBillResp []SpotAccBillResp `json:"data"` } - return resp.SpotAccBillResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + return resp.SpotAccBillResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // TransferAsset transfers a certain amount of a currency or pair between different productType accounts @@ -1640,8 +1587,7 @@ func (bi *Bitget) TransferAsset(ctx context.Context, fromType, toType, currency, var resp struct { TransferResp `json:"data"` } - return &resp.TransferResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + return &resp.TransferResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // GetTransferableCoinList returns a list of coins that can be transferred between the provided accounts @@ -1659,8 +1605,7 @@ func (bi *Bitget) GetTransferableCoinList(ctx context.Context, fromType, toType var resp struct { Data []string `json:"data"` } - return resp.Data, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, - &resp) + return resp.Data, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, &resp) } // SubaccountTransfer transfers assets between sub-accounts @@ -1699,8 +1644,7 @@ func (bi *Bitget) SubaccountTransfer(ctx context.Context, fromType, toType, curr var resp struct { TransferResp `json:"data"` } - return &resp.TransferResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + return &resp.TransferResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // WithdrawFunds withdraws funds from the user's account @@ -1733,8 +1677,7 @@ func (bi *Bitget) WithdrawFunds(ctx context.Context, currency, transferType, add } path := bitgetSpot + bitgetWallet + bitgetWithdrawal var resp *OrderIDResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // GetSubaccountTransferRecord returns the user's sub-account transfer history @@ -1762,8 +1705,7 @@ func (bi *Bitget) GetSubaccountTransferRecord(ctx context.Context, currency, sub var resp struct { SubaccTfrRecResp []SubaccTfrRecResp `json:"data"` } - return resp.SubaccTfrRecResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate20, http.MethodGet, path, params.Values, - nil, &resp) + return resp.SubaccTfrRecResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate20, http.MethodGet, path, params.Values, nil, &resp) } // GetTransferRecord returns the user's transfer history @@ -1795,8 +1737,7 @@ func (bi *Bitget) GetTransferRecord(ctx context.Context, currency, fromType, cli var resp struct { TransferRecResp []TransferRecResp `json:"data"` } - return resp.TransferRecResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate20, http.MethodGet, path, params.Values, - nil, &resp) + return resp.TransferRecResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate20, http.MethodGet, path, params.Values, nil, &resp) } // SwitchBGBDeductionStatus switches the deduction of BGB for trading fees on and off @@ -1811,8 +1752,7 @@ func (bi *Bitget) SwitchBGBDeductionStatus(ctx context.Context, deduct bool) (bo var resp struct { Data bool `json:"data"` } - return resp.Data, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate1, http.MethodPost, path, nil, req, - &resp) + return resp.Data, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate1, http.MethodPost, path, nil, req, &resp) } // GetDepositAddressForCurrency returns the user's deposit address for a particular currency @@ -1827,8 +1767,7 @@ func (bi *Bitget) GetDepositAddressForCurrency(ctx context.Context, currency, ch var resp struct { DepositAddressResp `json:"data"` } - return &resp.DepositAddressResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, - &resp) + return &resp.DepositAddressResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, &resp) } // GetSubaccountDepositAddress returns the deposit address for a particular currency and sub-account @@ -1847,8 +1786,7 @@ func (bi *Bitget) GetSubaccountDepositAddress(ctx context.Context, subaccountID, var resp struct { DepositAddressResp `json:"data"` } - return &resp.DepositAddressResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, - &resp) + return &resp.DepositAddressResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, &resp) } // GetBGBDeductionStatus returns the user's current BGB deduction status @@ -1859,8 +1797,7 @@ func (bi *Bitget) GetBGBDeductionStatus(ctx context.Context) (string, error) { Deduct string `json:"deduct"` } `json:"data"` } - return resp.Data.Deduct, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate5, http.MethodGet, path, nil, nil, - &resp) + return resp.Data.Deduct, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate5, http.MethodGet, path, nil, nil, &resp) } // CancelWithdrawal cancels a large withdrawal request that was placed in the last minute @@ -1873,8 +1810,7 @@ func (bi *Bitget) CancelWithdrawal(ctx context.Context, orderID string) (*Succes } path := bitgetSpot + bitgetWallet + bitgetCancelWithdrawal var resp *SuccessBool - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // GetSubaccountDepositRecords returns the deposit history for a sub-account @@ -1903,8 +1839,7 @@ func (bi *Bitget) GetSubaccountDepositRecords(ctx context.Context, subaccountID, var resp struct { SubaccDepRecResp []SubaccDepRecResp `json:"data"` } - return resp.SubaccDepRecResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + return resp.SubaccDepRecResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // GetWithdrawalRecords returns the user's withdrawal history @@ -1930,8 +1865,7 @@ func (bi *Bitget) GetWithdrawalRecords(ctx context.Context, currency, clientOrde var resp struct { WithdrawRecordsResp []WithdrawRecordsResp `json:"data"` } - return resp.WithdrawRecordsResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + return resp.WithdrawRecordsResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // GetDepositRecords returns the user's cryptocurrency deposit history @@ -1956,8 +1890,7 @@ func (bi *Bitget) GetDepositRecords(ctx context.Context, crypto string, orderID, var resp struct { CryptoDepRecResp []CryptoDepRecResp `json:"data"` } - return resp.CryptoDepRecResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + return resp.CryptoDepRecResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // GetFuturesVIPFeeRate returns the different levels of VIP fee rates for futures trading @@ -1969,9 +1902,7 @@ func (bi *Bitget) GetFuturesVIPFeeRate(ctx context.Context) ([]VIPFeeRateResp, e return resp.VIPFeeRateResp, bi.SendHTTPRequest(ctx, exchange.RestSpot, Rate10, path, nil, &resp) } -// GetFuturesMergeDepth returns part of the orderbook, with options to merge orders of similar price levels together, -// and to change how many results are returned. Limit's a string instead of the typical int64 because the API -// will accept a value of "max" +// GetFuturesMergeDepth returns part of the orderbook, with options to merge orders of similar price levels together, and to change how many results are returned. Limit's a string instead of the typical int64 because the API will accept a value of "max" func (bi *Bitget) GetFuturesMergeDepth(ctx context.Context, pair, productType, precision, limit string) (*DepthResp, error) { if pair == "" { return nil, errPairEmpty @@ -2235,8 +2166,7 @@ func (bi *Bitget) GetOneFuturesAccount(ctx context.Context, pair, productType, m var resp struct { OneAccResp `json:"data"` } - return &resp.OneAccResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, - &resp) + return &resp.OneAccResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, &resp) } // GetAllFuturesAccounts returns details for all accounts @@ -2250,8 +2180,7 @@ func (bi *Bitget) GetAllFuturesAccounts(ctx context.Context, productType string) var resp struct { FutureAccDetails []FutureAccDetails `json:"data"` } - return resp.FutureAccDetails, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, - &resp) + return resp.FutureAccDetails, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, &resp) } // GetFuturesSubaccountAssets returns details on the assets of all sub-accounts @@ -2265,8 +2194,7 @@ func (bi *Bitget) GetFuturesSubaccountAssets(ctx context.Context, productType st var resp struct { SubaccountFuturesResp []SubaccountFuturesResp `json:"data"` } - return resp.SubaccountFuturesResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate1, http.MethodGet, path, vals, nil, - &resp) + return resp.SubaccountFuturesResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate1, http.MethodGet, path, vals, nil, &resp) } // GetEstimatedOpenCount returns the estimated size of open orders for a given pair @@ -2301,8 +2229,7 @@ func (bi *Bitget) GetEstimatedOpenCount(ctx context.Context, pair, productType, Size float64 `json:"size,string"` } `json:"data"` } - return resp.Data.Size, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, - &resp) + return resp.Data.Size, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, &resp) } // ChangeLeverage changes the leverage for the given pair and product type @@ -2330,8 +2257,7 @@ func (bi *Bitget) ChangeLeverage(ctx context.Context, pair, productType, marginC var resp struct { LeverageResp `json:"data"` } - return &resp.LeverageResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate5, http.MethodPost, path, nil, req, - &resp) + return &resp.LeverageResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate5, http.MethodPost, path, nil, req, &resp) } // AdjustIsolatedAutoMargin adjusts the auto margin for a specified isolated margin account @@ -2384,8 +2310,7 @@ func (bi *Bitget) AdjustMargin(ctx context.Context, pair, productType, marginCoi return bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate5, http.MethodPost, path, nil, req, nil) } -// ChangeMarginMode changes the margin mode for a given pair. Can only be done when there the user has no open -// positions or orders +// ChangeMarginMode changes the margin mode for a given pair. Can only be done when there the user has no open positions or orders func (bi *Bitget) ChangeMarginMode(ctx context.Context, pair, productType, marginCoin, marginMode string) (*LeverageResp, error) { if pair == "" { return nil, errPairEmpty @@ -2409,12 +2334,10 @@ func (bi *Bitget) ChangeMarginMode(ctx context.Context, pair, productType, margi var resp struct { LeverageResp `json:"data"` } - return &resp.LeverageResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate5, http.MethodPost, path, nil, req, - &resp) + return &resp.LeverageResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate5, http.MethodPost, path, nil, req, &resp) } -// ChangePositionMode changes the position mode for any pair. Having any positions or orders on any side of any pair -// may cause this to fail. +// ChangePositionMode changes the position mode for any pair. Having any positions or orders on any side of any pair may cause this to fail. func (bi *Bitget) ChangePositionMode(ctx context.Context, productType, positionMode string) (string, error) { if productType == "" { return "", errProductTypeEmpty @@ -2432,8 +2355,7 @@ func (bi *Bitget) ChangePositionMode(ctx context.Context, productType, positionM PosMode string `json:"posMode"` } `json:"data"` } - return resp.Data.PosMode, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate5, http.MethodPost, path, nil, req, - &resp) + return resp.Data.PosMode, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate5, http.MethodPost, path, nil, req, &resp) } // GetFuturesAccountBills returns a section of the user's billing history @@ -2465,8 +2387,7 @@ func (bi *Bitget) GetFuturesAccountBills(ctx context.Context, productType, pair, Bills []FutureAccBillResp `json:"bills"` } `json:"data"` } - return resp.Data.Bills, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + return resp.Data.Bills, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // GetPositionTier returns the position configuration for a given pair @@ -2487,9 +2408,7 @@ func (bi *Bitget) GetPositionTier(ctx context.Context, productType, pair string) return resp.PositionTierResp, bi.SendHTTPRequest(ctx, exchange.RestSpot, Rate10, path, vals, &resp) } -// GetSinglePosition returns position details for a given productType, pair, and marginCoin. The exchange recommends -// using the websocket feed instead, as information from this endpoint may be delayed during settlement or market -// fluctuations +// GetSinglePosition returns position details for a given productType, pair, and marginCoin. The exchange recommends using the websocket feed instead, as information from this endpoint may be delayed during settlement or market fluctuations func (bi *Bitget) GetSinglePosition(ctx context.Context, productType, pair, marginCoin string) ([]PositionResp, error) { if productType == "" { return nil, errProductTypeEmpty @@ -2508,13 +2427,10 @@ func (bi *Bitget) GetSinglePosition(ctx context.Context, productType, pair, marg var resp struct { PositionResp []PositionResp `json:"data"` } - return resp.PositionResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, - &resp) + return resp.PositionResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, &resp) } -// GetAllPositions returns position details for a given productType and marginCoin. The exchange recommends using -// the websocket feed instead, as information from this endpoint may be delayed during settlement or market -// fluctuations +// GetAllPositions returns position details for a given productType and marginCoin. The exchange recommends using the websocket feed instead, as information from this endpoint may be delayed during settlement or market fluctuations func (bi *Bitget) GetAllPositions(ctx context.Context, productType, marginCoin string) ([]PositionResp, error) { if productType == "" { return nil, errProductTypeEmpty @@ -2529,8 +2445,7 @@ func (bi *Bitget) GetAllPositions(ctx context.Context, productType, marginCoin s var resp struct { PositionResp []PositionResp `json:"data"` } - return resp.PositionResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate5, http.MethodGet, path, vals, nil, - &resp) + return resp.PositionResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate5, http.MethodGet, path, vals, nil, &resp) } // GetHistoricalPositions returns historical position details, up to a maximum of three months ago @@ -2554,8 +2469,7 @@ func (bi *Bitget) GetHistoricalPositions(ctx context.Context, pair, productType var resp struct { HistPositionResp `json:"data"` } - return &resp.HistPositionResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate20, http.MethodGet, path, params.Values, - nil, &resp) + return &resp.HistPositionResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate20, http.MethodGet, path, params.Values, nil, &resp) } // PlaceFuturesOrder places a futures order on the exchange @@ -2614,18 +2528,10 @@ func (bi *Bitget) PlaceFuturesOrder(ctx context.Context, pair, productType, marg rLim = Rate1 } var resp *OrderIDResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, rLim, http.MethodPost, path, nil, req, - &resp) -} - -// PlaceReversal attempts to close a position, in part or in whole, and opens a position of corresponding size -// on the opposite side. This operation may only be done in part under certain margin levels, market conditions, -// or other unspecified factors. If a reversal is attempted for an amount greater than the current outstanding position, -// that position will be closed, and a new position will be opened for the amount of the closed position; not the amount -// specified in the request. The side specified in the parameter should correspond to the side of the position you're -// attempting to close; if the original is open_long, use close_long; if the original is open_short, use close_short; -// if the original is sell_single, use buy_single. If the position is sell_single or buy_single, the amount parameter -// will be ignored, and the entire position will be closed, with a corresponding amount opened on the opposite side. + return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, rLim, http.MethodPost, path, nil, req, &resp) +} + +// PlaceReversal attempts to close a position, in part or in whole, and opens a position of corresponding size on the opposite side. This operation may only be done in part under certain margin levels, market conditions, or other unspecified factors. If a reversal is attempted for an amount greater than the current outstanding position, that position will be closed, and a new position will be opened for the amount of the closed position; not the amount specified in the request. The side specified in the parameter should correspond to the side of the position you're attempting to close; if the original is open_long, use close_long; if the original is open_short, use close_short; if the original is sell_single, use buy_single. If the position is sell_single or buy_single, the amount parameter will be ignored, and the entire position will be closed, with a corresponding amount opened on the opposite side. func (bi *Bitget) PlaceReversal(ctx context.Context, pair, marginCoin, productType, side, tradeSide, clientOID string, amount float64, isCopyTradeLeader bool) (*OrderIDResp, error) { if pair == "" { return nil, errPairEmpty @@ -2657,12 +2563,10 @@ func (bi *Bitget) PlaceReversal(ctx context.Context, pair, marginCoin, productTy rLim = Rate1 } var resp *OrderIDResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, rLim, http.MethodPost, path, nil, req, - &resp) + return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, rLim, http.MethodPost, path, nil, req, &resp) } -// BatchPlaceFuturesOrders places multiple orders at once. Can also be used to modify the take-profit and stop-loss -// of an open position. +// BatchPlaceFuturesOrders places multiple orders at once. Can also be used to modify the take-profit and stop-loss of an open position. func (bi *Bitget) BatchPlaceFuturesOrders(ctx context.Context, pair, productType, marginCoin, marginMode string, orders []PlaceFuturesOrderStruct, isCopyTradeLeader bool) (*BatchOrderResp, error) { if pair == "" { return nil, errPairEmpty @@ -2692,14 +2596,10 @@ func (bi *Bitget) BatchPlaceFuturesOrders(ctx context.Context, pair, productType rLim = Rate1 } var resp *BatchOrderResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, rLim, http.MethodPost, path, nil, req, - &resp) + return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, rLim, http.MethodPost, path, nil, req, &resp) } -// ModifyFuturesOrder can change the size, price, take-profit, and stop-loss of an order. Size and price have to be -// modified at the same time, or the request will fail. If size and price are altered, the old order will be cancelled, -// and a new one will be created asynchronously. Due to the asynchronous creation of a new order, a new ClientOrderID -// must be supplied so it can be tracked. +// ModifyFuturesOrder can change the size, price, take-profit, and stop-loss of an order. Size and price have to be modified at the same time, or the request will fail. If size and price are altered, the old order will be cancelled, and a new one will be created asynchronously. Due to the asynchronous creation of a new order, a new ClientOrderID must be supplied so it can be tracked. func (bi *Bitget) ModifyFuturesOrder(ctx context.Context, orderID int64, clientOrderID, pair, productType, newClientOrderID string, newAmount, newPrice, newTakeProfit, newStopLoss float64) (*OrderIDResp, error) { if orderID == 0 && clientOrderID == "" { return nil, errOrderClientEmpty @@ -2734,8 +2634,7 @@ func (bi *Bitget) ModifyFuturesOrder(ctx context.Context, orderID int64, clientO } path := bitgetMix + bitgetOrder + bitgetModifyOrder var resp *OrderIDResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // CancelFuturesOrder cancels an order on the exchange @@ -2764,8 +2663,7 @@ func (bi *Bitget) CancelFuturesOrder(ctx context.Context, pair, productType, mar } path := bitgetMix + bitgetOrder + bitgetCancelOrder var resp *OrderIDResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // BatchCancelFuturesOrders cancels multiple orders at once @@ -2783,8 +2681,7 @@ func (bi *Bitget) BatchCancelFuturesOrders(ctx context.Context, orderIDs []Order } path := bitgetMix + bitgetOrder + bitgetBatchCancelOrders var resp *BatchOrderResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // FlashClosePosition attempts to close a position at the best available price @@ -2799,8 +2696,7 @@ func (bi *Bitget) FlashClosePosition(ctx context.Context, pair, holdSide, produc } path := bitgetMix + bitgetOrder + bitgetClosePositions var resp *BatchOrderResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate1, http.MethodPost, path, nil, req, - &resp) + return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate1, http.MethodPost, path, nil, req, &resp) } // GetFuturesOrderDetails returns details on a given order @@ -2825,8 +2721,7 @@ func (bi *Bitget) GetFuturesOrderDetails(ctx context.Context, pair, productType, } path := bitgetMix + bitgetOrder + bitgetDetail var resp *FuturesOrderDetailResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, - &resp) + return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, &resp) } // GetFuturesFills returns fill details @@ -2852,8 +2747,7 @@ func (bi *Bitget) GetFuturesFills(ctx context.Context, orderID, pagination, limi var resp struct { FuturesFillsResp `json:"data"` } - return &resp.FuturesFillsResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + return &resp.FuturesFillsResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // GetFuturesOrderFillHistory returns historical fill details @@ -2882,8 +2776,7 @@ func (bi *Bitget) GetFuturesOrderFillHistory(ctx context.Context, pair, productT var resp struct { FuturesFillsResp `json:"data"` } - return &resp.FuturesFillsResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + return &resp.FuturesFillsResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // GetPendingFuturesOrders returns detailed information on pending futures orders @@ -2913,8 +2806,7 @@ func (bi *Bitget) GetPendingFuturesOrders(ctx context.Context, orderID, paginati var resp struct { FuturesOrdResp `json:"data"` } - return &resp.FuturesOrdResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + return &resp.FuturesOrdResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // GetHistoricalFuturesOrders returns information on futures orders that are no longer pending @@ -2944,8 +2836,7 @@ func (bi *Bitget) GetHistoricalFuturesOrders(ctx context.Context, orderID, pagin var resp struct { FuturesOrdResp `json:"data"` } - return &resp.FuturesOrdResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + return &resp.FuturesOrdResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // CancelAllFuturesOrders cancels all pending orders @@ -2964,8 +2855,7 @@ func (bi *Bitget) CancelAllFuturesOrders(ctx context.Context, pair, productType, } path := bitgetMix + bitgetOrder + bitgetCancelAllOrders var resp *BatchOrderResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, - req, &resp) + return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // GetFuturesTriggerOrderByID returns information on a particular trigger order @@ -2987,8 +2877,7 @@ func (bi *Bitget) GetFuturesTriggerOrderByID(ctx context.Context, planType, prod var resp struct { SubOrderResp `json:"data"` } - return &resp.SubOrderResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, - &resp) + return &resp.SubOrderResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, &resp) } // PlaceTPSLFuturesOrder places a take-profit or stop-loss futures order @@ -3029,8 +2918,7 @@ func (bi *Bitget) PlaceTPSLFuturesOrder(ctx context.Context, marginCoin, product } path := bitgetMix + bitgetOrder + bitgetPlaceTPSLOrder var resp *OrderIDResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // PlaceTriggerFuturesOrder places a trigger futures order @@ -3068,12 +2956,10 @@ func (bi *Bitget) PlaceTriggerFuturesOrder(ctx context.Context, planType, pair, if triggerPrice == 0 { return nil, errTriggerPriceEmpty } - if (takeProfitTriggerType != "" || takeProfitTriggerPrice != 0 || takeProfitExecutePrice != 0) && - (takeProfitTriggerType == "" || takeProfitTriggerPrice == 0 || takeProfitExecutePrice == 0) { + if (takeProfitTriggerType != "" || takeProfitTriggerPrice != 0 || takeProfitExecutePrice != 0) && (takeProfitTriggerType == "" || takeProfitTriggerPrice == 0 || takeProfitExecutePrice == 0) { return nil, errTakeProfitParamsInconsistency } - if (stopLossTriggerType != "" || stopLossTriggerPrice != 0 || stopLossExecutePrice != 0) && - (stopLossTriggerType == "" || stopLossTriggerPrice == 0 || stopLossExecutePrice == 0) { + if (stopLossTriggerType != "" || stopLossTriggerPrice != 0 || stopLossExecutePrice != 0) && (stopLossTriggerType == "" || stopLossTriggerPrice == 0 || stopLossExecutePrice == 0) { return nil, errStopLossParamsInconsistency } req := map[string]any{ @@ -3109,8 +2995,7 @@ func (bi *Bitget) PlaceTriggerFuturesOrder(ctx context.Context, planType, pair, } path := bitgetMix + bitgetOrder + bitgetPlacePlanOrder var resp *OrderIDResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // ModifyTPSLFuturesOrder modifies a take-profit or stop-loss futures order @@ -3149,8 +3034,7 @@ func (bi *Bitget) ModifyTPSLFuturesOrder(ctx context.Context, orderID int64, cli } path := bitgetMix + bitgetOrder + bitgetModifyTPSLOrder var resp *OrderIDResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // ModifyTriggerFuturesOrder modifies a trigger futures order @@ -3189,8 +3073,7 @@ func (bi *Bitget) ModifyTriggerFuturesOrder(ctx context.Context, orderID int64, } path := bitgetMix + bitgetOrder + bitgetModifyPlanOrder var resp *OrderIDResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // GetPendingTriggerFuturesOrders returns information on pending trigger orders @@ -3224,8 +3107,7 @@ func (bi *Bitget) GetPendingTriggerFuturesOrders(ctx context.Context, orderID, p var resp struct { PlanFuturesOrdResp `json:"data"` } - return &resp.PlanFuturesOrdResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + return &resp.PlanFuturesOrdResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // CancelTriggerFuturesOrders cancels trigger futures orders @@ -3242,8 +3124,7 @@ func (bi *Bitget) CancelTriggerFuturesOrders(ctx context.Context, orderIDList [] } path := bitgetMix + bitgetOrder + bitgetCancelPlanOrder var resp *BatchOrderResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // GetHistoricalTriggerFuturesOrders returns information on historical trigger orders @@ -3278,8 +3159,7 @@ func (bi *Bitget) GetHistoricalTriggerFuturesOrders(ctx context.Context, orderID var resp struct { HistTriggerFuturesOrdResp `json:"data"` } - return &resp.HistTriggerFuturesOrdResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + return &resp.HistTriggerFuturesOrdResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // GetSupportedCurrencies returns information on the currencies supported by the exchange @@ -3315,8 +3195,7 @@ func (bi *Bitget) GetCrossBorrowHistory(ctx context.Context, loanID, limit, pagi var resp struct { BorrowHistCross `json:"data"` } - return &resp.BorrowHistCross, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + return &resp.BorrowHistCross, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // GetCrossRepayHistory returns the repayment history for cross margin @@ -3343,8 +3222,7 @@ func (bi *Bitget) GetCrossRepayHistory(ctx context.Context, repayID, limit, pagi var resp struct { RepayHistResp `json:"data"` } - return &resp.RepayHistResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + return &resp.RepayHistResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // GetCrossInterestHistory returns the interest history for cross margin @@ -3368,8 +3246,7 @@ func (bi *Bitget) GetCrossInterestHistory(ctx context.Context, currency string, var resp struct { InterHistCross `json:"data"` } - return &resp.InterHistCross, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + return &resp.InterHistCross, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // GetCrossLiquidationHistory returns the liquidation history for cross margin @@ -3390,12 +3267,11 @@ func (bi *Bitget) GetCrossLiquidationHistory(ctx context.Context, startTime, end var resp struct { LiquidHistCross `json:"data"` } - return &resp.LiquidHistCross, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + return &resp.LiquidHistCross, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // GetCrossFinancialHistory returns the financial history for cross margin -func (bi *Bitget) GetCrossFinancialHistory(ctx context.Context, marginType, currency string, startTime, endTime time.Time, limit, pagination int64) (*FinHistCross, error) { +func (bi *Bitget) GetCrossFinancialHistory(ctx context.Context, marginType, currency string, startTime, endTime time.Time, limit, pagination int64) (*FinHistCrossResp, error) { var params Params params.Values = make(url.Values) err := params.prepareDateString(startTime, endTime, false, true) @@ -3414,10 +3290,9 @@ func (bi *Bitget) GetCrossFinancialHistory(ctx context.Context, marginType, curr } path := bitgetMargin + bitgetCrossed + bitgetFinancialRecords var resp struct { - FinHistCross `json:"data"` + FinHistCrossResp `json:"data"` } - return &resp.FinHistCross, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + return &resp.FinHistCrossResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // GetCrossAccountAssets returns the account assets for cross margin @@ -3430,8 +3305,7 @@ func (bi *Bitget) GetCrossAccountAssets(ctx context.Context, currency string) ([ var resp struct { CrossAssetResp []CrossAssetResp `json:"data"` } - return resp.CrossAssetResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, - &resp) + return resp.CrossAssetResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, &resp) } // CrossBorrow borrows funds for cross margin @@ -3451,8 +3325,7 @@ func (bi *Bitget) CrossBorrow(ctx context.Context, currency, clientOrderID strin var resp struct { BorrowCross `json:"data"` } - return &resp.BorrowCross, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + return &resp.BorrowCross, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // CrossRepay repays funds for cross margin @@ -3471,8 +3344,7 @@ func (bi *Bitget) CrossRepay(ctx context.Context, currency string, amount float6 var resp struct { RepayCross `json:"data"` } - return &resp.RepayCross, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + return &resp.RepayCross, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // GetCrossRiskRate returns the risk rate for cross margin @@ -3483,8 +3355,7 @@ func (bi *Bitget) GetCrossRiskRate(ctx context.Context) (float64, error) { RiskRateRatio float64 `json:"riskRateRatio"` } `json:"data"` } - return resp.Data.RiskRateRatio, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, nil, nil, - &resp) + return resp.Data.RiskRateRatio, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, nil, nil, &resp) } // GetCrossMaxBorrowable returns the maximum amount that can be borrowed for cross margin @@ -3498,8 +3369,7 @@ func (bi *Bitget) GetCrossMaxBorrowable(ctx context.Context, currency string) (* var resp struct { MaxBorrowCross `json:"data"` } - return &resp.MaxBorrowCross, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, - &resp) + return &resp.MaxBorrowCross, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, &resp) } // GetCrossMaxTransferable returns the maximum amount that can be transferred out of cross margin @@ -3513,8 +3383,7 @@ func (bi *Bitget) GetCrossMaxTransferable(ctx context.Context, currency string) var resp struct { MaxTransferCross `json:"data"` } - return &resp.MaxTransferCross, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, - &resp) + return &resp.MaxTransferCross, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, &resp) } // GetCrossInterestRateAndMaxBorrowable returns the interest rate and maximum borrowable amount for cross margin @@ -3528,8 +3397,7 @@ func (bi *Bitget) GetCrossInterestRateAndMaxBorrowable(ctx context.Context, curr var resp struct { IntRateMaxBorrowCross []IntRateMaxBorrowCross `json:"data"` } - return resp.IntRateMaxBorrowCross, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, - &resp) + return resp.IntRateMaxBorrowCross, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, &resp) } // GetCrossTierConfiguration returns tier information for the user's VIP level @@ -3543,8 +3411,7 @@ func (bi *Bitget) GetCrossTierConfiguration(ctx context.Context, currency string var resp struct { TierConfigCross []TierConfigCross `json:"data"` } - return resp.TierConfigCross, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, - &resp) + return resp.TierConfigCross, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, &resp) } // CrossFlashRepay repays funds for cross margin, with the option to only repay for a particular currency @@ -3556,8 +3423,7 @@ func (bi *Bitget) CrossFlashRepay(ctx context.Context, currency string) (*FlashR var resp struct { FlashRepayCross `json:"data"` } - return &resp.FlashRepayCross, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + return &resp.FlashRepayCross, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // GetCrossFlashRepayResult returns the result of the supplied flash repayments for cross margin @@ -3572,8 +3438,7 @@ func (bi *Bitget) GetCrossFlashRepayResult(ctx context.Context, idList []int64) var resp struct { FlashRepayResult []FlashRepayResult `json:"data"` } - return resp.FlashRepayResult, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + return resp.FlashRepayResult, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // PlaceCrossOrder places an order using cross margin @@ -3613,8 +3478,7 @@ func (bi *Bitget) PlaceCrossOrder(ctx context.Context, pair, orderType, loanType } path := bitgetMargin + bitgetCrossed + bitgetPlaceOrder var resp *OrderIDResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // BatchPlaceCrossOrders places multiple orders using cross margin @@ -3631,8 +3495,7 @@ func (bi *Bitget) BatchPlaceCrossOrders(ctx context.Context, pair string, orders } path := bitgetMargin + bitgetCrossed + bitgetBatchPlaceOrder var resp *BatchOrderResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // CancelCrossOrder cancels an order using cross margin @@ -3654,8 +3517,7 @@ func (bi *Bitget) CancelCrossOrder(ctx context.Context, pair, clientOrderID stri } path := bitgetMargin + bitgetCrossed + bitgetCancelOrder var resp *OrderIDResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // BatchCancelCrossOrders cancels multiple orders using cross margin @@ -3672,8 +3534,7 @@ func (bi *Bitget) BatchCancelCrossOrders(ctx context.Context, pair string, order } path := bitgetMargin + bitgetCrossed + bitgetBatchCancelOrder var resp *BatchOrderResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // GetCrossOpenOrders returns the open orders for cross margin @@ -3702,8 +3563,7 @@ func (bi *Bitget) GetCrossOpenOrders(ctx context.Context, pair, clientOrderID st var resp struct { MarginOpenOrds `json:"data"` } - return &resp.MarginOpenOrds, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + return &resp.MarginOpenOrds, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // GetCrossHistoricalOrders returns the historical orders for cross margin @@ -3733,8 +3593,7 @@ func (bi *Bitget) GetCrossHistoricalOrders(ctx context.Context, pair, enterPoint var resp struct { MarginHistOrds `json:"data"` } - return &resp.MarginHistOrds, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + return &resp.MarginHistOrds, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // GetCrossOrderFills returns the fills for cross margin orders @@ -3762,8 +3621,7 @@ func (bi *Bitget) GetCrossOrderFills(ctx context.Context, pair string, orderID, var resp struct { MarginOrderFills `json:"data"` } - return &resp.MarginOrderFills, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + return &resp.MarginOrderFills, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // GetCrossLiquidationOrders returns the liquidation orders for cross margin @@ -3785,9 +3643,10 @@ func (bi *Bitget) GetCrossLiquidationOrders(ctx context.Context, orderType, pair params.Values.Set("idLessThan", strconv.FormatInt(pagination, 10)) } path := bitgetMargin + bitgetCrossed + bitgetLiquidationOrder - var resp *LiquidationResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + var resp struct { + LiquidationResp `json:"data"` + } + return &resp.LiquidationResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // GetIsolatedRepayHistory returns the repayment history for isolated margin @@ -3818,8 +3677,7 @@ func (bi *Bitget) GetIsolatedRepayHistory(ctx context.Context, pair, currency st var resp struct { RepayHistResp `json:"data"` } - return &resp.RepayHistResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + return &resp.RepayHistResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // GetIsolatedBorrowHistory returns the borrowing history for isolated margin @@ -3847,9 +3705,10 @@ func (bi *Bitget) GetIsolatedBorrowHistory(ctx context.Context, pair, currency s params.Values.Set("coin", currency) } path := bitgetMargin + bitgetIsolated + bitgetBorrowHistory - var resp *BorrowHistIso - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + var resp struct { + BorrowHistIso `json:"data"` + } + return &resp.BorrowHistIso, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // GetIsolatedInterestHistory returns the interest history for isolated margin @@ -3874,9 +3733,10 @@ func (bi *Bitget) GetIsolatedInterestHistory(ctx context.Context, pair, currency params.Values.Set("coin", currency) } path := bitgetMargin + bitgetIsolated + bitgetInterestHistory - var resp *InterHistIso - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + var resp struct { + InterHistIso `json:"data"` + } + return &resp.InterHistIso, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // GetIsolatedLiquidationHistory returns the liquidation history for isolated margin @@ -3898,13 +3758,14 @@ func (bi *Bitget) GetIsolatedLiquidationHistory(ctx context.Context, pair string } params.Values.Set("symbol", pair) path := bitgetMargin + bitgetIsolated + bitgetLiquidationHistory - var resp *LiquidHistIso - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + var resp struct { + LiquidHistIso `json:"data"` + } + return &resp.LiquidHistIso, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // GetIsolatedFinancialHistory returns the financial history for isolated margin -func (bi *Bitget) GetIsolatedFinancialHistory(ctx context.Context, pair, marginType, currency string, startTime, endTime time.Time, limit, pagination int64) (*FinHistIso, error) { +func (bi *Bitget) GetIsolatedFinancialHistory(ctx context.Context, pair, marginType, currency string, startTime, endTime time.Time, limit, pagination int64) (*FinHistIsoResp, error) { if pair == "" { return nil, errPairEmpty } @@ -3926,19 +3787,21 @@ func (bi *Bitget) GetIsolatedFinancialHistory(ctx context.Context, pair, marginT params.Values.Set("coin", currency) } path := bitgetMargin + bitgetIsolated + bitgetFinancialRecords - var resp *FinHistIso - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + var resp struct { + FinHistIsoResp `json:"data"` + } + return &resp.FinHistIsoResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // GetIsolatedAccountAssets returns the account assets for isolated margin -func (bi *Bitget) GetIsolatedAccountAssets(ctx context.Context, pair string) (*IsoAssetResp, error) { +func (bi *Bitget) GetIsolatedAccountAssets(ctx context.Context, pair string) ([]IsoAssetResp, error) { vals := url.Values{} vals.Set("symbol", pair) path := bitgetMargin + bitgetIsolated + "/" + bitgetAccount + bitgetAssets - var resp *IsoAssetResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, - &resp) + var resp struct { + IsoAssetResp []IsoAssetResp `json:"data"` + } + return resp.IsoAssetResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, &resp) } // IsolatedBorrow borrows funds for isolated margin @@ -3959,9 +3822,10 @@ func (bi *Bitget) IsolatedBorrow(ctx context.Context, pair, currency, clientOrde "clientOid": clientOrderID, } path := bitgetMargin + bitgetIsolated + "/" + bitgetAccount + bitgetBorrow - var resp *BorrowIso - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + var resp struct { + BorrowIso `json:"data"` + } + return &resp.BorrowIso, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // IsolatedRepay repays funds for isolated margin @@ -3982,13 +3846,14 @@ func (bi *Bitget) IsolatedRepay(ctx context.Context, amount float64, currency, p "clientOid": clientOrderID, } path := bitgetMargin + bitgetIsolated + "/" + bitgetAccount + bitgetRepay - var resp *RepayIso - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + var resp struct { + RepayIso `json:"data"` + } + return &resp.RepayIso, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // GetIsolatedRiskRate returns the risk rate for isolated margin -func (bi *Bitget) GetIsolatedRiskRate(ctx context.Context, pair string, pagination, limit int64) (*RiskRateIso, error) { +func (bi *Bitget) GetIsolatedRiskRate(ctx context.Context, pair string, pagination, limit int64) ([]RiskRateIso, error) { vals := url.Values{} vals.Set("symbol", pair) if limit != 0 { @@ -3998,35 +3863,38 @@ func (bi *Bitget) GetIsolatedRiskRate(ctx context.Context, pair string, paginati vals.Set("pageNum", strconv.FormatInt(pagination, 10)) } path := bitgetMargin + bitgetIsolated + "/" + bitgetAccount + bitgetRiskRate - var resp *RiskRateIso - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, - &resp) + var resp struct { + RiskRateIso []RiskRateIso `json:"data"` + } + return resp.RiskRateIso, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, &resp) } // GetIsolatedInterestRateAndMaxBorrowable returns the interest rate and maximum borrowable amount for isolated margin -func (bi *Bitget) GetIsolatedInterestRateAndMaxBorrowable(ctx context.Context, pair string) (*IntRateMaxBorrowIso, error) { +func (bi *Bitget) GetIsolatedInterestRateAndMaxBorrowable(ctx context.Context, pair string) ([]IntRateMaxBorrowIso, error) { if pair == "" { return nil, errPairEmpty } vals := url.Values{} vals.Set("symbol", pair) path := bitgetMargin + bitgetIsolated + bitgetInterestRateAndLimit - var resp *IntRateMaxBorrowIso - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, - &resp) + var resp struct { + IntRateMaxBorrowIso []IntRateMaxBorrowIso `json:"data"` + } + return resp.IntRateMaxBorrowIso, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, &resp) } // GetIsolatedTierConfiguration returns tier information for the user's VIP level -func (bi *Bitget) GetIsolatedTierConfiguration(ctx context.Context, pair string) (*TierConfigIso, error) { +func (bi *Bitget) GetIsolatedTierConfiguration(ctx context.Context, pair string) ([]TierConfigIso, error) { if pair == "" { return nil, errPairEmpty } vals := url.Values{} vals.Set("symbol", pair) path := bitgetMargin + bitgetIsolated + bitgetTierData - var resp *TierConfigIso - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, - &resp) + var resp struct { + TierConfigIso []TierConfigIso `json:"data"` + } + return resp.TierConfigIso, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, &resp) } // GetIsolatedMaxBorrowable returns the maximum amount that can be borrowed for isolated margin @@ -4037,9 +3905,10 @@ func (bi *Bitget) GetIsolatedMaxBorrowable(ctx context.Context, pair string) (*M vals := url.Values{} vals.Set("symbol", pair) path := bitgetMargin + bitgetIsolated + "/" + bitgetAccount + bitgetMaxBorrowableAmount - var resp *MaxBorrowIso - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, - &resp) + var resp struct { + MaxBorrowIso `json:"data"` + } + return &resp.MaxBorrowIso, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, &resp) } // GetIsolatedMaxTransferable returns the maximum amount that can be transferred out of isolated margin @@ -4050,20 +3919,22 @@ func (bi *Bitget) GetIsolatedMaxTransferable(ctx context.Context, pair string) ( vals := url.Values{} vals.Set("symbol", pair) path := bitgetMargin + bitgetIsolated + "/" + bitgetAccount + bitgetMaxTransferOutAmount - var resp *MaxTransferIso - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, - &resp) + var resp struct { + MaxTransferIso `json:"data"` + } + return &resp.MaxTransferIso, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, &resp) } // IsolatedFlashRepay repays funds for isolated margin, with the option to only repay for a set of up to 100 pairs -func (bi *Bitget) IsolatedFlashRepay(ctx context.Context, pairs []string) (*FlashRepayIso, error) { +func (bi *Bitget) IsolatedFlashRepay(ctx context.Context, pairs []string) ([]FlashRepayIso, error) { req := map[string]any{ "symbolList": pairs, } path := bitgetMargin + bitgetIsolated + "/" + bitgetAccount + bitgetFlashRepay - var resp *FlashRepayIso - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + var resp struct { + FlashRepayIso []FlashRepayIso `json:"data"` + } + return resp.FlashRepayIso, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // GetIsolatedFlashRepayResult returns the result of the supplied flash repayments for isolated margin @@ -4078,8 +3949,7 @@ func (bi *Bitget) GetIsolatedFlashRepayResult(ctx context.Context, idList []int6 var resp struct { FlashRepayResult []FlashRepayResult `json:"data"` } - return resp.FlashRepayResult, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + return resp.FlashRepayResult, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // PlaceIsolatedOrder places an order using isolated margin @@ -4119,8 +3989,7 @@ func (bi *Bitget) PlaceIsolatedOrder(ctx context.Context, pair, orderType, loanT } path := bitgetMargin + bitgetIsolated + bitgetPlaceOrder var resp *OrderIDResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // BatchPlaceIsolatedOrders places multiple orders using isolated margin @@ -4137,8 +4006,7 @@ func (bi *Bitget) BatchPlaceIsolatedOrders(ctx context.Context, pair string, ord } path := bitgetMargin + bitgetIsolated + bitgetBatchPlaceOrder var resp *BatchOrderResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // CancelIsolatedOrder cancels an order using isolated margin @@ -4160,8 +4028,7 @@ func (bi *Bitget) CancelIsolatedOrder(ctx context.Context, pair, clientOrderID s } path := bitgetMargin + bitgetIsolated + bitgetCancelOrder var resp *OrderIDResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // BatchCancelIsolatedOrders cancels multiple orders using isolated margin @@ -4178,8 +4045,7 @@ func (bi *Bitget) BatchCancelIsolatedOrders(ctx context.Context, pair string, or } path := bitgetMargin + bitgetIsolated + bitgetBatchCancelOrder var resp *BatchOrderResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // GetIsolatedOpenOrders returns the open orders for isolated margin @@ -4208,8 +4074,7 @@ func (bi *Bitget) GetIsolatedOpenOrders(ctx context.Context, pair, clientOrderID var resp struct { MarginOpenOrds `json:"data"` } - return &resp.MarginOpenOrds, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + return &resp.MarginOpenOrds, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // GetIsolatedHistoricalOrders returns the historical orders for isolated margin @@ -4239,8 +4104,7 @@ func (bi *Bitget) GetIsolatedHistoricalOrders(ctx context.Context, pair, enterPo var resp struct { MarginHistOrds `json:"data"` } - return &resp.MarginHistOrds, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + return &resp.MarginHistOrds, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // GetIsolatedOrderFills returns the fills for isolated margin orders @@ -4268,8 +4132,7 @@ func (bi *Bitget) GetIsolatedOrderFills(ctx context.Context, pair string, orderI var resp struct { MarginOrderFills `json:"data"` } - return &resp.MarginOrderFills, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + return &resp.MarginOrderFills, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // GetIsolatedLiquidationOrders returns the liquidation orders for isolated margin @@ -4291,13 +4154,14 @@ func (bi *Bitget) GetIsolatedLiquidationOrders(ctx context.Context, orderType, p params.Values.Set("idLessThan", strconv.FormatInt(pagination, 10)) } path := bitgetMargin + bitgetIsolated + bitgetLiquidationOrder - var resp *LiquidationResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + var resp struct { + LiquidationResp `json:"data"` + } + return &resp.LiquidationResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // GetSavingsProductList returns the list of savings products for a particular currency -func (bi *Bitget) GetSavingsProductList(ctx context.Context, currency, filter string) (*SavingsProductList, error) { +func (bi *Bitget) GetSavingsProductList(ctx context.Context, currency, filter string) ([]SavingsProductList, error) { if currency == "" { return nil, errCurrencyEmpty } @@ -4305,21 +4169,23 @@ func (bi *Bitget) GetSavingsProductList(ctx context.Context, currency, filter st vals.Set("coin", currency) vals.Set("filter", filter) path := bitgetEarn + bitgetSavings + bitgetProduct - var resp *SavingsProductList - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, - &resp) + var resp struct { + SavingsProductList []SavingsProductList `json:"data"` + } + return resp.SavingsProductList, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, &resp) } // GetSavingsBalance returns the savings balance and amount earned in BTC and USDT func (bi *Bitget) GetSavingsBalance(ctx context.Context) (*SavingsBalance, error) { path := bitgetEarn + bitgetSavings + "/" + bitgetAccount - var resp *SavingsBalance - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, nil, nil, - &resp) + var resp struct { + SavingsBalance `json:"data"` + } + return &resp.SavingsBalance, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, nil, nil, &resp) } // GetSavingsAssets returns information on assets held over the last three months -func (bi *Bitget) GetSavingsAssets(ctx context.Context, periodType string, startTime, endTime time.Time, limit, pagination int64) (*SavingsAssets, error) { +func (bi *Bitget) GetSavingsAssets(ctx context.Context, periodType string, startTime, endTime time.Time, limit, pagination int64) (*SavingsAssetsResp, error) { var params Params params.Values = make(url.Values) err := params.prepareDateString(startTime, endTime, true, true) @@ -4334,9 +4200,10 @@ func (bi *Bitget) GetSavingsAssets(ctx context.Context, periodType string, start } params.Values.Set("periodType", periodType) path := bitgetEarn + bitgetSavings + bitgetAssets - var resp *SavingsAssets - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + var resp struct { + SavingsAssetsResp `json:"data"` + } + return &resp.SavingsAssetsResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // GetSavingsRecords returns information on transactions performed over the last three months @@ -4359,9 +4226,10 @@ func (bi *Bitget) GetSavingsRecords(ctx context.Context, currency, periodType, o params.Values.Set("periodType", periodType) params.Values.Set("orderType", orderType) path := bitgetEarn + bitgetSavings + bitgetRecords - var resp *SavingsRecords - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + var resp struct { + SavingsRecords `json:"data"` + } + return &resp.SavingsRecords, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // GetSavingsSubscriptionDetail returns detailed information on subscribing, for a single product @@ -4376,9 +4244,10 @@ func (bi *Bitget) GetSavingsSubscriptionDetail(ctx context.Context, productID in vals.Set("productId", strconv.FormatInt(productID, 10)) vals.Set("periodType", periodType) path := bitgetEarn + bitgetSavings + bitgetSubscribeInfo - var resp *SavingsSubDetail - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, - &resp) + var resp struct { + SavingsSubDetail `json:"data"` + } + return &resp.SavingsSubDetail, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, &resp) } // SubscribeSavings applies funds to a savings product @@ -4398,9 +4267,10 @@ func (bi *Bitget) SubscribeSavings(ctx context.Context, productID int64, periodT "amount": strconv.FormatFloat(amount, 'f', -1, 64), } path := bitgetEarn + bitgetSavings + bitgetSubscribe - var resp *SaveResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + var resp struct { + SaveResp `json:"data"` + } + return &resp.SaveResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // GetSavingsSubscriptionResult returns the result of a subscription attempt @@ -4415,9 +4285,10 @@ func (bi *Bitget) GetSavingsSubscriptionResult(ctx context.Context, orderID int6 vals.Set("orderId", strconv.FormatInt(orderID, 10)) vals.Set("periodType", periodType) path := bitgetEarn + bitgetSavings + bitgetSubscribeResult - var resp *SaveResult - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, - &resp) + var resp struct { + SaveResult `json:"data"` + } + return &resp.SaveResult, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, &resp) } // RedeemSavings redeems funds from a savings product @@ -4438,9 +4309,10 @@ func (bi *Bitget) RedeemSavings(ctx context.Context, productID, orderID int64, p "amount": strconv.FormatFloat(amount, 'f', -1, 64), } path := bitgetEarn + bitgetSavings + bitgetRedeem - var resp *SaveResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + var resp struct { + SaveResp `json:"data"` + } + return &resp.SaveResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // GetSavingsRedemptionResult returns the result of a redemption attempt @@ -4455,25 +4327,27 @@ func (bi *Bitget) GetSavingsRedemptionResult(ctx context.Context, orderID int64, vals.Set("orderId", strconv.FormatInt(orderID, 10)) vals.Set("periodType", periodType) path := bitgetEarn + bitgetSavings + bitgetRedeemResult - var resp *SaveResult - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, - &resp) + var resp struct { + SaveResult `json:"data"` + } + return &resp.SaveResult, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, &resp) } // GetEarnAccountAssets returns the assets in the earn account -func (bi *Bitget) GetEarnAccountAssets(ctx context.Context, currency string) (*EarnAssets, error) { +func (bi *Bitget) GetEarnAccountAssets(ctx context.Context, currency string) ([]EarnAssets, error) { vals := url.Values{} if currency != "" { vals.Set("coin", currency) } path := bitgetEarn + bitgetAccount + bitgetAssets - var resp *EarnAssets - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, - &resp) + var resp struct { + EarnAssets []EarnAssets `json:"data"` + } + return resp.EarnAssets, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, &resp) } // GetSharkFinProducts returns information on Shark Fin products -func (bi *Bitget) GetSharkFinProducts(ctx context.Context, currency string, limit, pagination int64) (*SharkFinProducts, error) { +func (bi *Bitget) GetSharkFinProducts(ctx context.Context, currency string, limit, pagination int64) (*SharkFinProductResp, error) { if currency == "" { return nil, errCurrencyEmpty } @@ -4486,21 +4360,23 @@ func (bi *Bitget) GetSharkFinProducts(ctx context.Context, currency string, limi vals.Set("idLessThan", strconv.FormatInt(pagination, 10)) } path := bitgetEarn + bitgetSharkFin + bitgetProduct - var resp *SharkFinProducts - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, - &resp) + var resp struct { + SharkFinProductResp `json:"data"` + } + return &resp.SharkFinProductResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, &resp) } // GetSharkFinBalance returns the balance and amount earned in BTC and USDT for Shark Fin products func (bi *Bitget) GetSharkFinBalance(ctx context.Context) (*SharkFinBalance, error) { path := bitgetEarn + bitgetSharkFin + "/" + bitgetAccount - var resp *SharkFinBalance - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, nil, nil, - &resp) + var resp struct { + SharkFinBalance `json:"data"` + } + return &resp.SharkFinBalance, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, nil, nil, &resp) } // GetSharkFinAssets returns information on assets held over the last three months for Shark Fin products -func (bi *Bitget) GetSharkFinAssets(ctx context.Context, status string, startTime, endTime time.Time, limit, pagination int64) (*SharkFinAssets, error) { +func (bi *Bitget) GetSharkFinAssets(ctx context.Context, status string, startTime, endTime time.Time, limit, pagination int64) (*SharkFinAssetsResp, error) { var params Params params.Values = make(url.Values) err := params.prepareDateString(startTime, endTime, true, true) @@ -4515,13 +4391,14 @@ func (bi *Bitget) GetSharkFinAssets(ctx context.Context, status string, startTim } params.Values.Set("status", status) path := bitgetEarn + bitgetSharkFin + bitgetAssets - var resp *SharkFinAssets - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + var resp struct { + SharkFinAssetsResp `json:"data"` + } + return &resp.SharkFinAssetsResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // GetSharkFinRecords returns information on transactions performed over the last three months for Shark Fin products -func (bi *Bitget) GetSharkFinRecords(ctx context.Context, currency, transactionType string, startTime, endTime time.Time, limit, pagination int64) (*SharkFinRecords, error) { +func (bi *Bitget) GetSharkFinRecords(ctx context.Context, currency, transactionType string, startTime, endTime time.Time, limit, pagination int64) ([]SharkFinRecords, error) { var params Params params.Values = make(url.Values) err := params.prepareDateString(startTime, endTime, true, true) @@ -4539,9 +4416,12 @@ func (bi *Bitget) GetSharkFinRecords(ctx context.Context, currency, transactionT } params.Values.Set("type", transactionType) path := bitgetEarn + bitgetSharkFin + bitgetRecords - var resp *SharkFinRecords - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + var resp struct { + Data struct { + ResultList []SharkFinRecords `json:"resultList"` + } `json:"data"` + } + return resp.Data.ResultList, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // GetSharkFinSubscriptionDetail returns detailed information on subscribing, for a single product @@ -4552,9 +4432,10 @@ func (bi *Bitget) GetSharkFinSubscriptionDetail(ctx context.Context, productID i vals := url.Values{} vals.Set("productId", strconv.FormatInt(productID, 10)) path := bitgetEarn + bitgetSharkFin + bitgetSubscribeInfo - var resp *SharkFinSubDetail - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, - &resp) + var resp struct { + SharkFinSubDetail `json:"data"` + } + return &resp.SharkFinSubDetail, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, &resp) } // SubscribeSharkFin applies funds to a Shark Fin product @@ -4570,9 +4451,10 @@ func (bi *Bitget) SubscribeSharkFin(ctx context.Context, productID int64, amount "amount": strconv.FormatFloat(amount, 'f', -1, 64), } path := bitgetEarn + bitgetSharkFin + bitgetSubscribe - var resp *SaveResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + var resp struct { + SaveResp `json:"data"` + } + return &resp.SaveResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // GetSharkFinSubscriptionResult returns the result of a subscription attempt @@ -4583,9 +4465,10 @@ func (bi *Bitget) GetSharkFinSubscriptionResult(ctx context.Context, orderID int vals := url.Values{} vals.Set("orderId", strconv.FormatInt(orderID, 10)) path := bitgetEarn + bitgetSharkFin + bitgetSubscribeResult - var resp *SaveResult - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate5, http.MethodGet, path, vals, nil, - &resp) + var resp struct { + SaveResult `json:"data"` + } + return &resp.SaveResult, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate5, http.MethodGet, path, vals, nil, &resp) } // GetLoanCurrencyList returns the list of currencies available for loan @@ -4596,8 +4479,10 @@ func (bi *Bitget) GetLoanCurrencyList(ctx context.Context, currency string) (*Lo vals := url.Values{} vals.Set("coin", currency) path := bitgetEarn + bitgetLoan + "/" + bitgetPublic + bitgetCoinInfos - var resp *LoanCurList - return resp, bi.SendHTTPRequest(ctx, exchange.RestSpot, Rate10, path, vals, &resp) + var resp struct { + LoanCurList `json:"data"` + } + return &resp.LoanCurList, bi.SendHTTPRequest(ctx, exchange.RestSpot, Rate10, path, vals, &resp) } // GetEstimatedInterestAndBorrowable returns the estimated interest and borrowable amount for a currency @@ -4620,8 +4505,10 @@ func (bi *Bitget) GetEstimatedInterestAndBorrowable(ctx context.Context, loanCoi vals.Set("daily", term) vals.Set("pledgeAmount", strconv.FormatFloat(collateralAmount, 'f', -1, 64)) path := bitgetEarn + bitgetLoan + "/" + bitgetPublic + bitgetHourInterest - var resp *EstimateInterest - return resp, bi.SendHTTPRequest(ctx, exchange.RestSpot, Rate10, path, vals, &resp) + var resp struct { + EstimateInterest `json:"data"` + } + return &resp.EstimateInterest, bi.SendHTTPRequest(ctx, exchange.RestSpot, Rate10, path, vals, &resp) } // BorrowFunds borrows funds for a currency, supplying a certain amount of currency as collateral @@ -4646,13 +4533,14 @@ func (bi *Bitget) BorrowFunds(ctx context.Context, loanCoin, collateralCoin, ter "loanAmount": strconv.FormatFloat(loanAmount, 'f', -1, 64), } path := bitgetEarn + bitgetLoan + bitgetBorrow - var resp *BorrowResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + var resp struct { + BorrowResp `json:"data"` + } + return &resp.BorrowResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // GetOngoingLoans returns the ongoing loans, optionally filtered by currency -func (bi *Bitget) GetOngoingLoans(ctx context.Context, orderID int64, loanCoin, collateralCoin string) (*OngoingLoans, error) { +func (bi *Bitget) GetOngoingLoans(ctx context.Context, orderID int64, loanCoin, collateralCoin string) ([]OngoingLoans, error) { vals := url.Values{} if orderID != 0 { vals.Set("orderId", strconv.FormatInt(orderID, 10)) @@ -4660,9 +4548,10 @@ func (bi *Bitget) GetOngoingLoans(ctx context.Context, orderID int64, loanCoin, vals.Set("loanCoin", loanCoin) vals.Set("pledgeCoin", collateralCoin) path := bitgetEarn + bitgetLoan + bitgetOngoingOrders - var resp *OngoingLoans - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, - &resp) + var resp struct { + OngoingLoans []OngoingLoans `json:"data"` + } + return resp.OngoingLoans, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, vals, nil, &resp) } // RepayLoan repays a loan @@ -4688,13 +4577,14 @@ func (bi *Bitget) RepayLoan(ctx context.Context, orderID int64, amount float64, req["repayAll"] = "no" } path := bitgetEarn + bitgetLoan + bitgetRepay - var resp *RepayResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + var resp struct { + RepayResp `json:"data"` + } + return &resp.RepayResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // GetLoanRepayHistory returns the repayment records for a loan -func (bi *Bitget) GetLoanRepayHistory(ctx context.Context, orderID, pagination, limit int64, loanCoin, pledgeCoin string, startTime, endTime time.Time) (*RepayRecords, error) { +func (bi *Bitget) GetLoanRepayHistory(ctx context.Context, orderID, pagination, limit int64, loanCoin, pledgeCoin string, startTime, endTime time.Time) ([]RepayRecords, error) { var params Params params.Values = make(url.Values) err := params.prepareDateString(startTime, endTime, false, false) @@ -4711,9 +4601,10 @@ func (bi *Bitget) GetLoanRepayHistory(ctx context.Context, orderID, pagination, params.Values.Set("limit", strconv.FormatInt(limit, 10)) } path := bitgetEarn + bitgetLoan + bitgetRepayHistory - var resp *RepayRecords - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + var resp struct { + RepayRecords []RepayRecords `json:"data"` + } + return resp.RepayRecords, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // ModifyPledgeRate modifies the amount of collateral pledged for a loan @@ -4737,13 +4628,14 @@ func (bi *Bitget) ModifyPledgeRate(ctx context.Context, orderID int64, amount fl "reviseType": reviseType, } path := bitgetEarn + bitgetLoan + bitgetRevisePledge - var resp *ModPledgeResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, - &resp) + var resp struct { + ModPledgeResp `json:"data"` + } + return &resp.ModPledgeResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodPost, path, nil, req, &resp) } // GetPledgeRateHistory returns the history of pledged rates for loans -func (bi *Bitget) GetPledgeRateHistory(ctx context.Context, orderID, pagination, limit int64, reviseSide, pledgeCoin string, startTime, endTime time.Time) (*PledgeRateHist, error) { +func (bi *Bitget) GetPledgeRateHistory(ctx context.Context, orderID, pagination, limit int64, reviseSide, pledgeCoin string, startTime, endTime time.Time) ([]PledgeRateHist, error) { var params Params params.Values = make(url.Values) err := params.prepareDateString(startTime, endTime, false, false) @@ -4760,13 +4652,14 @@ func (bi *Bitget) GetPledgeRateHistory(ctx context.Context, orderID, pagination, params.Values.Set("limit", strconv.FormatInt(limit, 10)) } path := bitgetEarn + bitgetLoan + bitgetReviseHistory - var resp *PledgeRateHist - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + var resp struct { + PledgeRateHist []PledgeRateHist `json:"data"` + } + return resp.PledgeRateHist, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // GetLoanHistory returns the loan history -func (bi *Bitget) GetLoanHistory(ctx context.Context, orderID, pagination, limit int64, loanCoin, pledgeCoin, status string, startTime, endTime time.Time) (*LoanHistory, error) { +func (bi *Bitget) GetLoanHistory(ctx context.Context, orderID, pagination, limit int64, loanCoin, pledgeCoin, status string, startTime, endTime time.Time) ([]LoanHistory, error) { var params Params params.Values = make(url.Values) err := params.prepareDateString(startTime, endTime, false, false) @@ -4784,21 +4677,23 @@ func (bi *Bitget) GetLoanHistory(ctx context.Context, orderID, pagination, limit params.Values.Set("limit", strconv.FormatInt(limit, 10)) } path := bitgetEarn + bitgetLoan + bitgetBorrowHistory - var resp *LoanHistory - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + var resp struct { + LoanHistory []LoanHistory `json:"data"` + } + return resp.LoanHistory, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // GetDebts returns information on current outstanding pledges and loans func (bi *Bitget) GetDebts(ctx context.Context) (*DebtsResp, error) { path := bitgetEarn + bitgetLoan + bitgetDebts - var resp *DebtsResp - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, nil, nil, - &resp) + var resp struct { + DebtsResp `json:"data"` + } + return &resp.DebtsResp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, nil, nil, &resp) } // GetLiquidationRecords returns the liquidation records -func (bi *Bitget) GetLiquidationRecords(ctx context.Context, orderID, pagination, limit int64, loanCoin, pledgeCoin, status string, startTime, endTime time.Time) (*LiquidRecs, error) { +func (bi *Bitget) GetLiquidationRecords(ctx context.Context, orderID, pagination, limit int64, loanCoin, pledgeCoin, status string, startTime, endTime time.Time) ([]LiquidRecs, error) { var params Params params.Values = make(url.Values) err := params.prepareDateString(startTime, endTime, false, false) @@ -4816,9 +4711,10 @@ func (bi *Bitget) GetLiquidationRecords(ctx context.Context, orderID, pagination params.Values.Set("limit", strconv.FormatInt(limit, 10)) } path := bitgetEarn + bitgetLoan + bitgetReduces - var resp *LiquidRecs - return resp, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, - nil, &resp) + var resp struct { + LiquidRecs []LiquidRecs `json:"data"` + } + return resp.LiquidRecs, bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate10, http.MethodGet, path, params.Values, nil, &resp) } // SendAuthenticatedHTTPRequest sends an authenticated HTTP request @@ -4840,10 +4736,7 @@ func (bi *Bitget) SendAuthenticatedHTTPRequest(ctx context.Context, ep exchange. return nil, err } } - // $ gets escaped in URLs, but the exchange reverses this before checking the signature; if we don't - // reverse it ourselves, they'll consider it invalid. This technically applies to other escape characters - // too, but $ is one we need to worry about, since it's included in some currencies supported by the - // exchange + // $ gets escaped in URLs, but the exchange reverses this before checking the signature; if we don't reverse it ourselves, they'll consider it invalid. This technically applies to other escape characters too, but $ is one we need to worry about, since it's included in some currencies supported by the exchange unescapedPath := strings.ReplaceAll(path, "%24", "$") t := strconv.FormatInt(time.Now().UnixMilli(), 10) message := t + method + "/api/v2/" + unescapedPath + string(payload) @@ -4874,8 +4767,7 @@ func (bi *Bitget) SendAuthenticatedHTTPRequest(ctx context.Context, ep exchange. return bi.SendPayload(ctx, rateLim, newRequest, request.AuthenticatedRequest) } -// SendHTTPRequest sends an unauthenticated HTTP request, with a few assumptions about the request; -// namely that it is a GET request with no body +// SendHTTPRequest sends an unauthenticated HTTP request, with a few assumptions about the request; namely that it is a GET request with no body func (bi *Bitget) SendHTTPRequest(ctx context.Context, ep exchange.URL, rateLim request.EndpointLimit, path string, queryParams url.Values, result any) error { endpoint, err := bi.API.Endpoints.GetURL(ep) if err != nil { @@ -5158,8 +5050,7 @@ func (bi *Bitget) spotOrderHelper(ctx context.Context, path string, vals url.Val var temp struct { Data []OrderDetailTemp `json:"data"` } - err := bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate20, http.MethodGet, path, vals, nil, - &temp) + err := bi.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, Rate20, http.MethodGet, path, vals, nil, &temp) if err != nil { return nil, err } diff --git a/exchanges/bitget/bitget_test.go b/exchanges/bitget/bitget_test.go index 466e5b6ea51..e21f0f66d8c 100644 --- a/exchanges/bitget/bitget_test.go +++ b/exchanges/bitget/bitget_test.go @@ -38,19 +38,15 @@ const ( clientID = "" // Passphrase made at API key creation canManipulateRealOrders = false testingInSandbox = false - - // Needs to be set to a subaccount with deposit transfer permissions so that TestGetSubaccountDepositAddress - // doesn't fail - deposSubaccID = "" - + // Needs to be set to a subaccount with deposit transfer permissions so that TestGetSubaccountDepositAddress doesn't fail + deposSubaccID = "" testSubaccountName = "GCTTESTA" testIP = "14.203.57.50" testAddress = "fake test address" // Test values used with live data, with the goal of never letting an order be executed testAmount = 0.001 testPrice = 1e10 - 1 - // Test values used with demo functionality, with the goal of lining up with the relatively strict currency - // limits present there + // Test values used with demo functionality, with the goal of lining up with the relatively strict currency limits present there testAmount2 = 0.003 testPrice2 = 1667 ) @@ -68,13 +64,11 @@ var ( // Developer-defined constants to aid testing const ( - ordersNotFound = "Orders not found" - - skipTestSubAccNotFound = "appropriate sub-account (equals %v, not equals %v) not found, skipping" - skipInsufficientAPIKeysFound = "insufficient API keys found, skipping" - skipInsufficientBalance = "insufficient balance to place order, skipping" - skipInsufficientOrders = "insufficient orders found, skipping" - + ordersNotFound = "Orders not found" + skipTestSubAccNotFound = "appropriate sub-account (equals %v, not equals %v) not found, skipping" + skipInsufficientAPIKeysFound = "insufficient API keys found, skipping" + skipInsufficientBalance = "insufficient balance to place order, skipping" + skipInsufficientOrders = "insufficient orders found, skipping" errAPIKeyLimitPartial = `Bitget unsuccessful HTTP status code: 400 raw response: {"code":"40063","msg":"API exceeds the maximum limit added","requestTime":` errCurrentlyHoldingPositionPartial = `Bitget unsuccessful HTTP status code: 400 raw response: {"code":"45117","msg":"Currently holding positions or orders, the margin mode cannot be adjusted","requestTime":` ) @@ -155,8 +149,7 @@ func TestGetSpotTransactionRecords(t *testing.T) { _, err := bi.GetSpotTransactionRecords(context.Background(), "", time.Time{}, time.Time{}, 0, 0) assert.ErrorIs(t, err, common.ErrDateUnset) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) - _, err = bi.GetSpotTransactionRecords(context.Background(), "", time.Now().Add(-time.Hour*24*30), time.Now(), 5, - 1<<62) + _, err = bi.GetSpotTransactionRecords(context.Background(), "", time.Now().Add(-time.Hour*24*30), time.Now(), 5, 1<<62) assert.NoError(t, err) } @@ -167,8 +160,7 @@ func TestGetFuturesTransactionRecords(t *testing.T) { _, err = bi.GetFuturesTransactionRecords(context.Background(), "woof", "", time.Time{}, time.Time{}, 0, 0) assert.ErrorIs(t, err, common.ErrDateUnset) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) - _, err = bi.GetFuturesTransactionRecords(context.Background(), "COIN-FUTURES", "", - time.Now().Add(-time.Hour*24*30), time.Now(), 5, 1<<62) + _, err = bi.GetFuturesTransactionRecords(context.Background(), "COIN-FUTURES", "", time.Now().Add(-time.Hour*24*30), time.Now(), 5, 1<<62) assert.NoError(t, err) } @@ -177,8 +169,7 @@ func TestGetMarginTransactionRecords(t *testing.T) { _, err := bi.GetMarginTransactionRecords(context.Background(), "", "", time.Time{}, time.Time{}, 0, 0) assert.ErrorIs(t, err, common.ErrDateUnset) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) - _, err = bi.GetMarginTransactionRecords(context.Background(), "", "", time.Now().Add(-time.Hour*24*30), - time.Now(), 5, 1<<62) + _, err = bi.GetMarginTransactionRecords(context.Background(), "", "", time.Now().Add(-time.Hour*24*30), time.Now(), 5, 1<<62) assert.NoError(t, err) } @@ -187,8 +178,7 @@ func TestGetP2PTransactionRecords(t *testing.T) { _, err := bi.GetP2PTransactionRecords(context.Background(), "", time.Time{}, time.Time{}, 0, 0) assert.ErrorIs(t, err, common.ErrDateUnset) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) - _, err = bi.GetP2PTransactionRecords(context.Background(), "", time.Now().Add(-time.Hour*24*30), time.Now(), 5, - 1<<62) + _, err = bi.GetP2PTransactionRecords(context.Background(), "", time.Now().Add(-time.Hour*24*30), time.Now(), 5, 1<<62) assert.NoError(t, err) } @@ -211,19 +201,16 @@ func TestGetMerchantP2POrders(t *testing.T) { assert.ErrorIs(t, err, common.ErrDateUnset) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) // Can't currently be properly tested due to not knowing any p2p order IDs - _, err = bi.GetMerchantP2POrders(context.Background(), time.Now().Add(-time.Hour*24*7), time.Now(), 5, 0, 0, - 0, "", "", "", "") + _, err = bi.GetMerchantP2POrders(context.Background(), time.Now().Add(-time.Hour*24*7), time.Now(), 5, 0, 0, 0, "", "", "", "") assert.NoError(t, err) } func TestGetMerchantAdvertisementList(t *testing.T) { t.Parallel() - _, err := bi.GetMerchantAdvertisementList(context.Background(), time.Time{}, time.Time{}, 0, 0, 0, 0, "", "", "", - "", "", "") + _, err := bi.GetMerchantAdvertisementList(context.Background(), time.Time{}, time.Time{}, 0, 0, 0, 0, "", "", "", "", "", "") assert.ErrorIs(t, err, common.ErrDateUnset) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) - _, err = bi.GetMerchantAdvertisementList(context.Background(), time.Now().Add(-time.Hour*24*7), time.Now(), 5, - 1<<62, 0, 0, "", "", "", "", "", "") + _, err = bi.GetMerchantAdvertisementList(context.Background(), time.Now().Add(-time.Hour*24*7), time.Now(), 5, 1<<62, 0, 0, "", "", "", "", "", "") assert.NoError(t, err) } @@ -315,8 +302,7 @@ func TestGetFuturesAccountRatios(t *testing.T) { func TestCreateVirtualSubaccounts(t *testing.T) { t.Parallel() - testGetOneArg(t, bi.CreateVirtualSubaccounts, nil, []string{testSubaccountName}, errSubaccountEmpty, - true, true, true) + testGetOneArg(t, bi.CreateVirtualSubaccounts, nil, []string{testSubaccountName}, errSubaccountEmpty, true, true, true) } func TestModifyVirtualSubaccount(t *testing.T) { @@ -347,8 +333,7 @@ func TestCreateSubaccountAndAPIKey(t *testing.T) { // Fails with error "subAccountList not empty" and I'm not sure why. The account I'm testing with is far off // hitting the limit of 20 sub-accounts. // Now it's saying that parameter req cannot be empty, still no clue what that means - _, err = bi.CreateSubaccountAndAPIKey(context.Background(), "MEOWMEOW", "woofwoof", "neighneighneighneighneigh", - ipL, pL) + _, err = bi.CreateSubaccountAndAPIKey(context.Background(), "MEOWMEOW", "woofwoof", "neighneighneighneighneigh", ipL, pL) assert.NoError(t, err) } @@ -401,8 +386,7 @@ func TestModifyAPIKey(t *testing.T) { if len(resp) == 0 { t.Skip(skipInsufficientAPIKeysFound) } - resp2, err := bi.ModifyAPIKey(context.Background(), tarID, clientID, "oink", resp[0].SubaccountApiKey, - ipL, ipL) + resp2, err := bi.ModifyAPIKey(context.Background(), tarID, clientID, "oink", resp[0].SubaccountApiKey, ipL, ipL) assert.NoError(t, err) assert.NotEmpty(t, resp2) } @@ -471,8 +455,7 @@ func TestConvertBGB(t *testing.T) { t.Parallel() // No matter what currency I use, this returns the error "currency does not support convert"; possibly a bad // error message, with the true issue being lack of funds? - testGetOneArg(t, bi.ConvertBGB, nil, []string{testCrypto3.String()}, errCurrencyEmpty, false, true, - canManipulateRealOrders) + testGetOneArg(t, bi.ConvertBGB, nil, []string{testCrypto3.String()}, errCurrencyEmpty, false, true, canManipulateRealOrders) } func TestGetBGBConvertHistory(t *testing.T) { @@ -528,14 +511,11 @@ func TestGetSpotCandlestickData(t *testing.T) { assert.ErrorIs(t, err, errGranEmpty) _, err = bi.GetSpotCandlestickData(context.Background(), "meow", "woof", time.Time{}, time.Time{}, 5, true) assert.ErrorIs(t, err, errEndTimeEmpty) - _, err = bi.GetSpotCandlestickData(context.Background(), "meow", "woof", time.Now().Add(time.Hour), time.Time{}, - 0, false) + _, err = bi.GetSpotCandlestickData(context.Background(), "meow", "woof", time.Now().Add(time.Hour), time.Time{}, 0, false) assert.ErrorIs(t, err, common.ErrStartAfterTimeNow) - _, err = bi.GetSpotCandlestickData(context.Background(), testPair.String(), "1min", time.Time{}, time.Time{}, - 5, false) + _, err = bi.GetSpotCandlestickData(context.Background(), testPair.String(), "1min", time.Time{}, time.Time{}, 5, false) assert.NoError(t, err) - resp, err := bi.GetSpotCandlestickData(context.Background(), testPair.String(), "1min", time.Time{}, time.Now(), 5, - true) + resp, err := bi.GetSpotCandlestickData(context.Background(), testPair.String(), "1min", time.Time{}, time.Now(), 5, true) require.NoError(t, err) assert.NotEmpty(t, resp.SpotCandles) } @@ -572,12 +552,10 @@ func TestPlaceSpotOrder(t *testing.T) { assert.ErrorIs(t, err, errStrategyEmpty) _, err = bi.PlaceSpotOrder(context.Background(), testPair.String(), "sell", "limit", "IOC", "", 0, 0, false) assert.ErrorIs(t, err, errLimitPriceEmpty) - _, err = bi.PlaceSpotOrder(context.Background(), testPair.String(), "sell", "limit", "IOC", "", testPrice, 0, - false) + _, err = bi.PlaceSpotOrder(context.Background(), testPair.String(), "sell", "limit", "IOC", "", testPrice, 0, false) assert.ErrorIs(t, err, errAmountEmpty) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi, canManipulateRealOrders) - _, err = bi.PlaceSpotOrder(context.Background(), testPair.String(), "sell", "limit", "IOC", "", testPrice, - testAmount, true) + _, err = bi.PlaceSpotOrder(context.Background(), testPair.String(), "sell", "limit", "IOC", "", testPrice, testAmount, true) assert.NoError(t, err) } @@ -593,8 +571,7 @@ func TestCancelSpotOrderByID(t *testing.T) { if len(resp) == 0 { t.Skip(skipInsufficientOrders) } - _, err = bi.CancelSpotOrderByID(context.Background(), testPair.String(), resp[0].ClientOrderID, - int64(resp[0].OrderID)) + _, err = bi.CancelSpotOrderByID(context.Background(), testPair.String(), resp[0].ClientOrderID, int64(resp[0].OrderID)) assert.NoError(t, err) } @@ -632,7 +609,7 @@ func TestBatchCancelOrders(t *testing.T) { t.Skip(skipInsufficientOrders) } req = append(req, OrderIDStruct{ - OrderID: int64(resp[0].OrderID), + OrderID: resp[0].OrderID, ClientOrderID: resp[0].ClientOrderID, }) resp2, err := bi.BatchCancelOrders(context.Background(), testPair.String(), req) @@ -642,8 +619,7 @@ func TestBatchCancelOrders(t *testing.T) { func TestCancelOrderBySymbol(t *testing.T) { t.Parallel() - testGetOneArg(t, bi.CancelOrdersBySymbol, "", testPair.String(), errPairEmpty, true, true, - canManipulateRealOrders) + testGetOneArg(t, bi.CancelOrdersBySymbol, "", testPair.String(), errPairEmpty, true, true, canManipulateRealOrders) } func TestGetSpotOrderDetails(t *testing.T) { @@ -652,7 +628,7 @@ func TestGetSpotOrderDetails(t *testing.T) { assert.ErrorIs(t, err, errOrderClientEmpty) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) ordIDs := getPlanOrdIDHelper(t, false) - _, err = bi.GetSpotOrderDetails(context.Background(), ordIDs.OrderID, ordIDs.ClientOrderID) + _, err = bi.GetSpotOrderDetails(context.Background(), int64(ordIDs.OrderID), ordIDs.ClientOrderID) assert.NoError(t, err) } @@ -702,8 +678,7 @@ func TestPlacePlanSpotOrder(t *testing.T) { _, err = bi.PlacePlanSpotOrder(context.Background(), "meow", "woof", "neigh", "", "", "", "", 1, 0, 1) assert.ErrorIs(t, err, errTriggerTypeEmpty) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi, canManipulateRealOrders) - resp, err := bi.PlacePlanSpotOrder(context.Background(), testPair.String(), "sell", "limit", "", "fill_price", - clientIDGenerator(), "ioc", testPrice, testPrice, testAmount) + resp, err := bi.PlacePlanSpotOrder(context.Background(), testPair.String(), "sell", "limit", "", "fill_price", clientIDGenerator(), "ioc", testPrice, testPrice, testAmount) require.NoError(t, err) assert.NotEmpty(t, resp.Data) } @@ -728,8 +703,7 @@ func TestSpotGetPlanSubOrder(t *testing.T) { } // This gets the error "the current plan order does not exist or has not been triggered" even when using // a plan order that definitely exists and has definitely been triggered. Re-investigate later - testGetOneArg(t, bi.GetSpotPlanSubOrder, "", strconv.FormatInt(ordIDs.OrderID, 10), errOrderIDEmpty, true, - true, true) + testGetOneArg(t, bi.GetSpotPlanSubOrder, "", strconv.FormatInt(int64(ordIDs.OrderID), 10), errOrderIDEmpty, true, true, true) } func TestGetSpotPlanOrderHistory(t *testing.T) { @@ -739,15 +713,13 @@ func TestGetSpotPlanOrderHistory(t *testing.T) { _, err = bi.GetSpotPlanOrderHistory(context.Background(), "meow", time.Time{}, time.Time{}, 0, 0) assert.ErrorIs(t, err, common.ErrDateUnset) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) - _, err = bi.GetSpotPlanOrderHistory(context.Background(), testPair.String(), time.Now().Add(-time.Hour*24*90), - time.Now().Add(-time.Minute), 2, 1<<62) + _, err = bi.GetSpotPlanOrderHistory(context.Background(), testPair.String(), time.Now().Add(-time.Hour*24*90), time.Now().Add(-time.Minute), 2, 1<<62) assert.NoError(t, err) } func TestBatchCancelSpotPlanOrders(t *testing.T) { t.Parallel() - testGetOneArg(t, bi.BatchCancelSpotPlanOrders, nil, []string{testPair.String()}, nil, false, true, - canManipulateRealOrders) + testGetOneArg(t, bi.BatchCancelSpotPlanOrders, nil, []string{testPair.String()}, nil, false, true, canManipulateRealOrders) } func TestGetAccountInfo(t *testing.T) { @@ -805,8 +777,7 @@ func TestTransferAsset(t *testing.T) { _, err = bi.TransferAsset(context.Background(), "meow", "woof", "neigh", "", "", 0) assert.ErrorIs(t, err, errAmountEmpty) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi, canManipulateRealOrders) - _, err = bi.TransferAsset(context.Background(), "spot", "p2p", testCrypto.String(), testPair.String(), - clientIDGenerator(), testAmount) + _, err = bi.TransferAsset(context.Background(), "spot", "p2p", testCrypto.String(), testPair.String(), clientIDGenerator(), testAmount) assert.NoError(t, err) } @@ -839,8 +810,7 @@ func TestSubaccountTransfer(t *testing.T) { sharedtestvalues.SkipTestIfCredentialsUnset(t, bi, canManipulateRealOrders) fromID := subAccTestHelper(t, "", strings.ToLower(string(testSubaccountName[:3]))+"****@virtual-bitget.com") toID := subAccTestHelper(t, strings.ToLower(string(testSubaccountName[:3]))+"****@virtual-bitget.com", "") - _, err = bi.SubaccountTransfer(context.Background(), "spot", "p2p", testCrypto.String(), testPair.String(), - clientIDGenerator(), fromID, toID, testAmount) + _, err = bi.SubaccountTransfer(context.Background(), "spot", "p2p", testCrypto.String(), testPair.String(), clientIDGenerator(), fromID, toID, testAmount) assert.NoError(t, err) } @@ -855,15 +825,13 @@ func TestWithdrawFunds(t *testing.T) { _, err = bi.WithdrawFunds(context.Background(), "meow", "woof", "neigh", "", "", "", "", "", "", 0) assert.ErrorIs(t, err, errAmountEmpty) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi, canManipulateRealOrders) - _, err = bi.WithdrawFunds(context.Background(), testCrypto.String(), "on_chain", testAddress, testCrypto.String(), "", - "", "", "", clientIDGenerator(), testAmount) + _, err = bi.WithdrawFunds(context.Background(), testCrypto.String(), "on_chain", testAddress, testCrypto.String(), "", "", "", "", clientIDGenerator(), testAmount) assert.NoError(t, err) } func TestGetSubaccountTransferRecord(t *testing.T) { t.Parallel() - _, err := bi.GetSubaccountTransferRecord(context.Background(), "", "", "", time.Now().Add(time.Hour), time.Time{}, 0, - 0) + _, err := bi.GetSubaccountTransferRecord(context.Background(), "", "", "", time.Now().Add(time.Hour), time.Time{}, 0, 0) assert.ErrorIs(t, err, common.ErrStartAfterTimeNow) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) _, err = bi.GetSubaccountTransferRecord(context.Background(), "", "", "meow", time.Time{}, time.Time{}, 3, 1<<62) @@ -879,8 +847,7 @@ func TestGetTransferRecord(t *testing.T) { _, err = bi.GetTransferRecord(context.Background(), "meow", "woof", "", time.Now().Add(time.Hour), time.Time{}, 0, 0) assert.ErrorIs(t, err, common.ErrStartAfterTimeNow) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) - _, err = bi.GetTransferRecord(context.Background(), testCrypto.String(), "spot", "meow", time.Time{}, time.Time{}, - 3, 1<<62) + _, err = bi.GetTransferRecord(context.Background(), testCrypto.String(), "spot", "meow", time.Time{}, time.Time{}, 3, 1<<62) assert.NoError(t, err) } @@ -924,8 +891,7 @@ func TestGetSubaccountDepositRecords(t *testing.T) { t.Parallel() _, err := bi.GetSubaccountDepositRecords(context.Background(), "", "", 0, 0, 0, time.Time{}, time.Time{}) assert.ErrorIs(t, err, errSubaccountEmpty) - _, err = bi.GetSubaccountDepositRecords(context.Background(), "meow", "", 0, 0, 0, time.Now().Add(time.Hour), - time.Time{}) + _, err = bi.GetSubaccountDepositRecords(context.Background(), "meow", "", 0, 0, 0, time.Now().Add(time.Hour), time.Time{}) assert.ErrorIs(t, err, common.ErrStartAfterTimeNow) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) tarID := subAccTestHelper(t, "", "") @@ -938,8 +904,7 @@ func TestGetWithdrawalRecords(t *testing.T) { _, err := bi.GetWithdrawalRecords(context.Background(), "", "", time.Time{}, time.Time{}, 0, 0, 0) assert.ErrorIs(t, err, common.ErrDateUnset) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) - _, err = bi.GetWithdrawalRecords(context.Background(), "", "", time.Now().Add(-time.Hour*24*90), time.Now(), - 1<<62, 0, 5) + _, err = bi.GetWithdrawalRecords(context.Background(), "", "", time.Now().Add(-time.Hour*24*90), time.Now(), 1<<62, 0, 5) assert.NoError(t, err) } @@ -948,8 +913,7 @@ func TestGetDepositRecords(t *testing.T) { _, err := bi.GetDepositRecords(context.Background(), "", 0, 0, 0, time.Time{}, time.Time{}) assert.ErrorIs(t, err, common.ErrDateUnset) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) - _, err = bi.GetDepositRecords(context.Background(), testCrypto.String(), 0, 1<<62, 2, - time.Now().Add(-time.Hour*24*90), time.Now()) + _, err = bi.GetDepositRecords(context.Background(), testCrypto.String(), 0, 1<<62, 2, time.Now().Add(-time.Hour*24*90), time.Now()) assert.NoError(t, err) } @@ -996,11 +960,9 @@ func TestGetFuturesMarketTrades(t *testing.T) { assert.ErrorIs(t, err, errPairEmpty) _, err = bi.GetFuturesMarketTrades(context.Background(), "meow", "", 0, 0, time.Time{}, time.Time{}) assert.ErrorIs(t, err, errProductTypeEmpty) - _, err = bi.GetFuturesMarketTrades(context.Background(), "meow", "woof", 0, 0, time.Now().Add(time.Hour), - time.Time{}) + _, err = bi.GetFuturesMarketTrades(context.Background(), "meow", "woof", 0, 0, time.Now().Add(time.Hour), time.Time{}) assert.ErrorIs(t, err, common.ErrStartAfterTimeNow) - resp, err := bi.GetFuturesMarketTrades(context.Background(), testPair.String(), "USDT-FUTURES", 5, 1<<62, - time.Time{}, time.Time{}) + resp, err := bi.GetFuturesMarketTrades(context.Background(), testPair.String(), "USDT-FUTURES", 5, 1<<62, time.Time{}, time.Time{}) require.NoError(t, err) assert.NotEmpty(t, resp) } @@ -1013,23 +975,18 @@ func TestGetFuturesCandlestickData(t *testing.T) { assert.ErrorIs(t, err, errProductTypeEmpty) _, err = bi.GetFuturesCandlestickData(context.Background(), "meow", "woof", "", time.Time{}, time.Time{}, 0, 0) assert.ErrorIs(t, err, errGranEmpty) - _, err = bi.GetFuturesCandlestickData(context.Background(), "meow", "woof", "neigh", time.Now().Add(time.Hour), - time.Time{}, 0, 0) + _, err = bi.GetFuturesCandlestickData(context.Background(), "meow", "woof", "neigh", time.Now().Add(time.Hour), time.Time{}, 0, 0) assert.ErrorIs(t, err, common.ErrStartAfterTimeNow) - resp, err := bi.GetFuturesCandlestickData(context.Background(), testPair.String(), "USDT-FUTURES", "1m", - time.Time{}, time.Time{}, 5, CallModeNormal) + resp, err := bi.GetFuturesCandlestickData(context.Background(), testPair.String(), "USDT-FUTURES", "1m", time.Time{}, time.Time{}, 5, CallModeNormal) assert.NoError(t, err) assert.NotEmpty(t, resp.FuturesCandles) - resp, err = bi.GetFuturesCandlestickData(context.Background(), testPair.String(), "COIN-FUTURES", "1m", - time.Time{}, time.Time{}, 5, CallModeHistory) + resp, err = bi.GetFuturesCandlestickData(context.Background(), testPair.String(), "COIN-FUTURES", "1m", time.Time{}, time.Time{}, 5, CallModeHistory) assert.NoError(t, err) assert.NotEmpty(t, resp.FuturesCandles) - resp, err = bi.GetFuturesCandlestickData(context.Background(), testPair.String(), "USDC-FUTURES", "1m", - time.Time{}, time.Now(), 5, CallModeIndex) + resp, err = bi.GetFuturesCandlestickData(context.Background(), testPair.String(), "USDC-FUTURES", "1m", time.Time{}, time.Now(), 5, CallModeIndex) assert.NoError(t, err) assert.NotEmpty(t, resp.FuturesCandles) - resp, err = bi.GetFuturesCandlestickData(context.Background(), testPair.String(), "USDT-FUTURES", "1m", - time.Time{}, time.Now(), 5, CallModeMark) + resp, err = bi.GetFuturesCandlestickData(context.Background(), testPair.String(), "USDT-FUTURES", "1m", time.Time{}, time.Now(), 5, CallModeMark) assert.NoError(t, err) assert.NotEmpty(t, resp.FuturesCandles) } @@ -1110,8 +1067,7 @@ func TestGetEstimatedOpenCount(t *testing.T) { _, err = bi.GetEstimatedOpenCount(context.Background(), "meow", "woof", "neigh", 1, 0, 0) assert.ErrorIs(t, err, errOpenPriceEmpty) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) - resp, err := bi.GetEstimatedOpenCount(context.Background(), testPair.String(), "USDT-FUTURES", "USDT", - testPrice, testAmount, 20) + resp, err := bi.GetEstimatedOpenCount(context.Background(), testPair.String(), "USDT-FUTURES", "USDT", testPrice, testAmount, 20) require.NoError(t, err) assert.NotEmpty(t, resp) } @@ -1139,11 +1095,9 @@ func TestAdjustIsolatedAutoMargin(t *testing.T) { err = bi.AdjustIsolatedAutoMargin(context.Background(), "meow", "", "", false, 0) assert.ErrorIs(t, err, errMarginCoinEmpty) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi, canManipulateRealOrders) - err = bi.AdjustIsolatedAutoMargin(context.Background(), testPair2.String(), testFiat2.String(), "long", - false, 0) + err = bi.AdjustIsolatedAutoMargin(context.Background(), testPair2.String(), testFiat2.String(), "long", false, 0) assert.NoError(t, err) - err = bi.AdjustIsolatedAutoMargin(context.Background(), testPair2.String(), testFiat2.String(), "long", - true, 0.01) + err = bi.AdjustIsolatedAutoMargin(context.Background(), testPair2.String(), testFiat2.String(), "long", true, 0.01) assert.NoError(t, err) } @@ -1160,8 +1114,7 @@ func TestAdjustMargin(t *testing.T) { sharedtestvalues.SkipTestIfCredentialsUnset(t, bi, canManipulateRealOrders) // This is getting the error "verification exception margin mode == FIXED", and I can't find a way to // skirt around that - err = bi.AdjustMargin(context.Background(), testPair2.String(), testFiat2.String()+"-FUTURES", testFiat2.String(), - "long", -testAmount) + err = bi.AdjustMargin(context.Background(), testPair2.String(), testFiat2.String()+"-FUTURES", testFiat2.String(), "long", -testAmount) assert.NoError(t, err) } @@ -1176,8 +1129,7 @@ func TestChangeMarginMode(t *testing.T) { _, err = bi.ChangeMarginMode(context.Background(), "meow", "woof", "neigh", "") assert.ErrorIs(t, err, errMarginModeEmpty) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi, canManipulateRealOrders) - _, err = bi.ChangeMarginMode(context.Background(), testPair2.String(), testFiat2.String()+"-FUTURES", - testFiat2.String(), "crossed") + _, err = bi.ChangeMarginMode(context.Background(), testPair2.String(), testFiat2.String()+"-FUTURES", testFiat2.String(), "crossed") if err != nil { if strings.Contains(err.Error(), errCurrentlyHoldingPositionPartial) { t.Log(err) @@ -1203,12 +1155,10 @@ func TestGetFuturesAccountBills(t *testing.T) { t.Parallel() _, err := bi.GetFuturesAccountBills(context.Background(), "", "", "", "", 0, 0, time.Time{}, time.Time{}) assert.ErrorIs(t, err, errProductTypeEmpty) - _, err = bi.GetFuturesAccountBills(context.Background(), "meow", "", "", "", 0, 0, time.Now().Add(time.Hour), - time.Time{}) + _, err = bi.GetFuturesAccountBills(context.Background(), "meow", "", "", "", 0, 0, time.Now().Add(time.Hour), time.Time{}) assert.ErrorIs(t, err, common.ErrStartAfterTimeNow) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) - _, err = bi.GetFuturesAccountBills(context.Background(), testFiat2.String()+"-FUTURES", "", "", "", 0, 0, - time.Time{}, time.Time{}) + _, err = bi.GetFuturesAccountBills(context.Background(), testFiat2.String()+"-FUTURES", "", "", "", 0, 0, time.Time{}, time.Time{}) assert.NoError(t, err) } @@ -1232,8 +1182,7 @@ func TestGetSinglePosition(t *testing.T) { _, err = bi.GetSinglePosition(context.Background(), "meow", "woof", "") assert.ErrorIs(t, err, errMarginCoinEmpty) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) - _, err = bi.GetSinglePosition(context.Background(), testFiat2.String()+"-FUTURES", testPair2.String(), - testFiat2.String()) + _, err = bi.GetSinglePosition(context.Background(), testFiat2.String()+"-FUTURES", testPair2.String(), testFiat2.String()) assert.NoError(t, err) } @@ -1259,34 +1208,24 @@ func TestGetHistoricalPositions(t *testing.T) { func TestPlaceFuturesOrder(t *testing.T) { t.Parallel() - _, err := bi.PlaceFuturesOrder(context.Background(), "", "", "", "", "", "", "", "", "", 0, 0, 0, 0, false, - false) + _, err := bi.PlaceFuturesOrder(context.Background(), "", "", "", "", "", "", "", "", "", 0, 0, 0, 0, false, false) assert.ErrorIs(t, err, errPairEmpty) - _, err = bi.PlaceFuturesOrder(context.Background(), "meow", "", "", "", "", "", "", "", "", 0, 0, 0, 0, false, - false) + _, err = bi.PlaceFuturesOrder(context.Background(), "meow", "", "", "", "", "", "", "", "", 0, 0, 0, 0, false, false) assert.ErrorIs(t, err, errProductTypeEmpty) - _, err = bi.PlaceFuturesOrder(context.Background(), "meow", "woof", "", "", "", "", "", "", "", 0, 0, 0, 0, - false, false) + _, err = bi.PlaceFuturesOrder(context.Background(), "meow", "woof", "", "", "", "", "", "", "", 0, 0, 0, 0, false, false) assert.ErrorIs(t, err, errMarginModeEmpty) - _, err = bi.PlaceFuturesOrder(context.Background(), "meow", "woof", "neigh", "", "", "", "", "", "", 0, 0, 0, - 0, false, false) + _, err = bi.PlaceFuturesOrder(context.Background(), "meow", "woof", "neigh", "", "", "", "", "", "", 0, 0, 0, 0, false, false) assert.ErrorIs(t, err, errMarginCoinEmpty) - _, err = bi.PlaceFuturesOrder(context.Background(), "meow", "woof", "neigh", "oink", "", "", "", "", "", 0, 0, - 0, 0, false, false) + _, err = bi.PlaceFuturesOrder(context.Background(), "meow", "woof", "neigh", "oink", "", "", "", "", "", 0, 0, 0, 0, false, false) assert.ErrorIs(t, err, errSideEmpty) - _, err = bi.PlaceFuturesOrder(context.Background(), "meow", "woof", "neigh", "oink", "quack", "", "", "", "", - 0, 0, 0, 0, false, false) + _, err = bi.PlaceFuturesOrder(context.Background(), "meow", "woof", "neigh", "oink", "quack", "", "", "", "", 0, 0, 0, 0, false, false) assert.ErrorIs(t, err, errOrderTypeEmpty) - _, err = bi.PlaceFuturesOrder(context.Background(), "meow", "woof", "neigh", "oink", "quack", "", "limit", "", - "", 0, 0, 0, 0, false, false) + _, err = bi.PlaceFuturesOrder(context.Background(), "meow", "woof", "neigh", "oink", "quack", "", "limit", "", "", 0, 0, 0, 0, false, false) assert.ErrorIs(t, err, errAmountEmpty) - _, err = bi.PlaceFuturesOrder(context.Background(), "meow", "woof", "neigh", "oink", "quack", "", "limit", "", - "", 0, 0, 1, 0, false, false) + _, err = bi.PlaceFuturesOrder(context.Background(), "meow", "woof", "neigh", "oink", "quack", "", "limit", "", "", 0, 0, 1, 0, false, false) assert.ErrorIs(t, err, errLimitPriceEmpty) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi, canManipulateRealOrders) - resp, err := bi.PlaceFuturesOrder(context.Background(), testPair2.String(), testFiat2.String()+"-FUTURES", - "isolated", testFiat2.String(), "buy", "open", "limit", "GTC", clientIDGenerator(), testPrice2+1, testPrice2-1, - testAmount2, testPrice2, true, true) + resp, err := bi.PlaceFuturesOrder(context.Background(), testPair2.String(), testFiat2.String()+"-FUTURES", "isolated", testFiat2.String(), "buy", "open", "limit", "GTC", clientIDGenerator(), testPrice2+1, testPrice2-1, testAmount2, testPrice2, true, true) assert.NoError(t, err) assert.NotEmpty(t, resp.Data) } @@ -1302,8 +1241,7 @@ func TestPlaceReversal(t *testing.T) { _, err = bi.PlaceReversal(context.Background(), "meow", "woof", "neigh", "", "", "", 0, false) assert.ErrorIs(t, err, errAmountEmpty) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi, canManipulateRealOrders) - _, err = bi.PlaceReversal(context.Background(), testPair2.String(), testFiat2.String(), - testFiat2.String()+"-FUTURES", "Buy", "Open", clientIDGenerator(), testAmount, true) + _, err = bi.PlaceReversal(context.Background(), testPair2.String(), testFiat2.String(), testFiat2.String()+"-FUTURES", "Buy", "Open", clientIDGenerator(), testAmount, true) assert.NoError(t, err) } @@ -1330,8 +1268,7 @@ func TestBatchPlaceFuturesOrders(t *testing.T) { Strategy: "FOK", }, } - _, err = bi.BatchPlaceFuturesOrders(context.Background(), testPair2.String(), testFiat2.String()+"-FUTURES", - testFiat2.String(), "isolated", orders, true) + _, err = bi.BatchPlaceFuturesOrders(context.Background(), testPair2.String(), testFiat2.String()+"-FUTURES", testFiat2.String(), "isolated", orders, true) assert.NoError(t, err) } @@ -1345,8 +1282,7 @@ func TestGetFuturesOrderDetails(t *testing.T) { assert.ErrorIs(t, err, errOrderClientEmpty) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) oID := getFuturesOrdIDHelper(t, false, true) - _, err = bi.GetFuturesOrderDetails(context.Background(), testPair2.String(), testFiat2.String()+"-FUTURES", - oID.ClientOrderID, oID.OrderID) + _, err = bi.GetFuturesOrderDetails(context.Background(), testPair2.String(), testFiat2.String()+"-FUTURES", oID.ClientOrderID, int64(oID.OrderID)) assert.NoError(t, err) } @@ -1357,8 +1293,7 @@ func TestGetFuturesFills(t *testing.T) { _, err = bi.GetFuturesFills(context.Background(), 0, 0, 0, "", "meow", time.Now().Add(time.Hour), time.Time{}) assert.ErrorIs(t, err, common.ErrStartAfterTimeNow) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) - _, err = bi.GetFuturesFills(context.Background(), 0, 1<<62, 5, "", testFiat2.String()+"-FUTURES", time.Time{}, - time.Time{}) + _, err = bi.GetFuturesFills(context.Background(), 0, 1<<62, 5, "", testFiat2.String()+"-FUTURES", time.Time{}, time.Time{}) assert.NoError(t, err) } @@ -1366,19 +1301,16 @@ func TestGetFuturesOrderFillHistory(t *testing.T) { t.Parallel() _, err := bi.GetFuturesOrderFillHistory(context.Background(), "", "", 0, 0, 0, time.Time{}, time.Time{}) assert.ErrorIs(t, err, errProductTypeEmpty) - _, err = bi.GetFuturesOrderFillHistory(context.Background(), "", "meow", 0, 0, 0, time.Now().Add(time.Hour), - time.Time{}) + _, err = bi.GetFuturesOrderFillHistory(context.Background(), "", "meow", 0, 0, 0, time.Now().Add(time.Hour), time.Time{}) assert.ErrorIs(t, err, common.ErrStartAfterTimeNow) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) // Keeps getting "Parameter verification failed" error and I can't figure out why - resp, err := bi.GetFuturesOrderFillHistory(context.Background(), "", testFiat2.String()+"-FUTURES", 0, 1<<62, 5, - time.Time{}, time.Time{}) + resp, err := bi.GetFuturesOrderFillHistory(context.Background(), "", testFiat2.String()+"-FUTURES", 0, 1<<62, 5, time.Time{}, time.Time{}) require.NoError(t, err) if len(resp.FillList) == 0 { t.Skip(skipInsufficientOrders) } - _, err = bi.GetFuturesOrderFillHistory(context.Background(), "", testFiat2.String()+"-FUTURES", - resp.FillList[0].OrderID, 1<<62, 5, time.Time{}, time.Time{}) + _, err = bi.GetFuturesOrderFillHistory(context.Background(), "", testFiat2.String()+"-FUTURES", resp.FillList[0].OrderID, 1<<62, 5, time.Time{}, time.Time{}) assert.NoError(t, err) } @@ -1386,18 +1318,15 @@ func TestGetPendingFuturesOrders(t *testing.T) { t.Parallel() _, err := bi.GetPendingFuturesOrders(context.Background(), 0, 0, 0, "", "", "", "", time.Time{}, time.Time{}) assert.ErrorIs(t, err, errProductTypeEmpty) - _, err = bi.GetPendingFuturesOrders(context.Background(), 0, 0, 0, "", "", "meow", "", time.Now().Add(time.Hour), - time.Time{}) + _, err = bi.GetPendingFuturesOrders(context.Background(), 0, 0, 0, "", "", "meow", "", time.Now().Add(time.Hour), time.Time{}) assert.ErrorIs(t, err, common.ErrStartAfterTimeNow) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) - resp, err := bi.GetPendingFuturesOrders(context.Background(), 0, 1<<62, 5, "", testPair2.String(), - testFiat2.String()+"-FUTURES", "", time.Now().Add(-time.Hour*24*90), time.Now()) + resp, err := bi.GetPendingFuturesOrders(context.Background(), 0, 1<<62, 5, "", testPair2.String(), testFiat2.String()+"-FUTURES", "", time.Now().Add(-time.Hour*24*90), time.Now()) require.NoError(t, err) if len(resp.EntrustedList) == 0 { t.Skip(skipInsufficientOrders) } - _, err = bi.GetPendingFuturesOrders(context.Background(), resp.EntrustedList[0].OrderID, 1<<62, 5, "", - testPair2.String(), testFiat2.String()+"-FUTURES", "", time.Time{}, time.Time{}) + _, err = bi.GetPendingFuturesOrders(context.Background(), resp.EntrustedList[0].OrderID, 1<<62, 5, "", testPair2.String(), testFiat2.String()+"-FUTURES", "", time.Time{}, time.Time{}) assert.NoError(t, err) } @@ -1405,18 +1334,15 @@ func TestGetHistoricalFuturesOrders(t *testing.T) { t.Parallel() _, err := bi.GetHistoricalFuturesOrders(context.Background(), 0, 0, 0, "", "", "", time.Time{}, time.Time{}) assert.ErrorIs(t, err, errProductTypeEmpty) - _, err = bi.GetHistoricalFuturesOrders(context.Background(), 0, 0, 0, "", "", "meow", time.Now().Add(time.Hour), - time.Time{}) + _, err = bi.GetHistoricalFuturesOrders(context.Background(), 0, 0, 0, "", "", "meow", time.Now().Add(time.Hour), time.Time{}) assert.ErrorIs(t, err, common.ErrStartAfterTimeNow) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) - resp, err := bi.GetHistoricalFuturesOrders(context.Background(), 0, 1<<62, 5, "", testPair2.String(), - testFiat2.String()+"-FUTURES", time.Time{}, time.Time{}) + resp, err := bi.GetHistoricalFuturesOrders(context.Background(), 0, 1<<62, 5, "", testPair2.String(), testFiat2.String()+"-FUTURES", time.Time{}, time.Time{}) require.NoError(t, err) if len(resp.EntrustedList) == 0 { t.Skip(skipInsufficientOrders) } - _, err = bi.GetHistoricalFuturesOrders(context.Background(), resp.EntrustedList[0].OrderID, 1<<62, 5, "", - testPair2.String(), testFiat2.String()+"-FUTURES", time.Time{}, time.Time{}) + _, err = bi.GetHistoricalFuturesOrders(context.Background(), resp.EntrustedList[0].OrderID, 1<<62, 5, "", testPair2.String(), testFiat2.String()+"-FUTURES", time.Time{}, time.Time{}) assert.NoError(t, err) } @@ -1429,14 +1355,12 @@ func TestGetFuturesTriggerOrderByID(t *testing.T) { _, err = bi.GetFuturesTriggerOrderByID(context.Background(), "meow", "woof", 0) assert.ErrorIs(t, err, errPlanOrderIDEmpty) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) - resp, err := bi.GetHistoricalTriggerFuturesOrders(context.Background(), 0, 1<<62, 5, "", "normal_plan", "", - testPair2.String(), testFiat2.String()+"-FUTURES", time.Time{}, time.Time{}) + resp, err := bi.GetHistoricalTriggerFuturesOrders(context.Background(), 0, 1<<62, 5, "", "normal_plan", "", testPair2.String(), testFiat2.String()+"-FUTURES", time.Time{}, time.Time{}) require.NoError(t, err) if len(resp.EntrustedList) == 0 { t.Skip(skipInsufficientOrders) } - _, err = bi.GetFuturesTriggerOrderByID(context.Background(), "normal_plan", testFiat2.String()+"-FUTURES", - resp.EntrustedList[0].OrderID) + _, err = bi.GetFuturesTriggerOrderByID(context.Background(), "normal_plan", testFiat2.String()+"-FUTURES", resp.EntrustedList[0].OrderID) assert.NoError(t, err) } @@ -1450,70 +1374,51 @@ func TestPlaceTPSLFuturesOrder(t *testing.T) { assert.ErrorIs(t, err, errPairEmpty) _, err = bi.PlaceTPSLFuturesOrder(context.Background(), "meow", "woof", "neigh", "", "", "", "", "", 0, 0, 0) assert.ErrorIs(t, err, errPlanTypeEmpty) - _, err = bi.PlaceTPSLFuturesOrder(context.Background(), "meow", "woof", "neigh", "oink", "", "", "", "", 0, - 0, 0) + _, err = bi.PlaceTPSLFuturesOrder(context.Background(), "meow", "woof", "neigh", "oink", "", "", "", "", 0, 0, 0) assert.ErrorIs(t, err, errHoldSideEmpty) - _, err = bi.PlaceTPSLFuturesOrder(context.Background(), "meow", "woof", "neigh", "oink", "", "quack", "", "", - 0, 0, 0) + _, err = bi.PlaceTPSLFuturesOrder(context.Background(), "meow", "woof", "neigh", "oink", "", "quack", "", "", 0, 0, 0) assert.ErrorIs(t, err, errTriggerPriceEmpty) - _, err = bi.PlaceTPSLFuturesOrder(context.Background(), "meow", "woof", "neigh", "oink", "", "quack", "", "", - 1, 0, 0) + _, err = bi.PlaceTPSLFuturesOrder(context.Background(), "meow", "woof", "neigh", "oink", "", "quack", "", "", 1, 0, 0) assert.ErrorIs(t, err, errAmountEmpty) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi, canManipulateRealOrders) - resp, err := bi.PlaceTPSLFuturesOrder(context.Background(), testFiat2.String(), testFiat2.String()+"-FUTURES", - testPair2.String(), "profit_plan", "", "short", "", "", testPrice2+2, 0, testAmount2) + resp, err := bi.PlaceTPSLFuturesOrder(context.Background(), testFiat2.String(), testFiat2.String()+"-FUTURES", testPair2.String(), "profit_plan", "", "short", "", "", testPrice2+2, 0, testAmount2) require.NoError(t, err) assert.NotEmpty(t, resp.Data) } func TestPlaceTriggerFuturesOrder(t *testing.T) { t.Parallel() - _, err := bi.PlaceTriggerFuturesOrder(context.Background(), "", "", "", "", "", "", "", "", "", "", "", "", 0, 0, - 0, 0, 0, 0, 0, 0, false) + _, err := bi.PlaceTriggerFuturesOrder(context.Background(), "", "", "", "", "", "", "", "", "", "", "", "", 0, 0, 0, 0, 0, 0, 0, 0, false) assert.ErrorIs(t, err, errPlanTypeEmpty) - _, err = bi.PlaceTriggerFuturesOrder(context.Background(), "meow", "", "", "", "", "", "", "", "", "", "", "", 0, - 0, 0, 0, 0, 0, 0, 0, false) + _, err = bi.PlaceTriggerFuturesOrder(context.Background(), "meow", "", "", "", "", "", "", "", "", "", "", "", 0, 0, 0, 0, 0, 0, 0, 0, false) assert.ErrorIs(t, err, errPairEmpty) - _, err = bi.PlaceTriggerFuturesOrder(context.Background(), "meow", "woof", "", "", "", "", "", "", "", "", "", "", - 0, 0, 0, 0, 0, 0, 0, 0, false) + _, err = bi.PlaceTriggerFuturesOrder(context.Background(), "meow", "woof", "", "", "", "", "", "", "", "", "", "", 0, 0, 0, 0, 0, 0, 0, 0, false) assert.ErrorIs(t, err, errProductTypeEmpty) - _, err = bi.PlaceTriggerFuturesOrder(context.Background(), "meow", "woof", "neigh", "", "", "", "", "", "", "", - "", "", 0, 0, 0, 0, 0, 0, 0, 0, false) + _, err = bi.PlaceTriggerFuturesOrder(context.Background(), "meow", "woof", "neigh", "", "", "", "", "", "", "", "", "", 0, 0, 0, 0, 0, 0, 0, 0, false) assert.ErrorIs(t, err, errMarginModeEmpty) - _, err = bi.PlaceTriggerFuturesOrder(context.Background(), "meow", "woof", "neigh", "oink", "", "", "", "", "", - "", "", "", 0, 0, 0, 0, 0, 0, 0, 0, false) + _, err = bi.PlaceTriggerFuturesOrder(context.Background(), "meow", "woof", "neigh", "oink", "", "", "", "", "", "", "", "", 0, 0, 0, 0, 0, 0, 0, 0, false) assert.ErrorIs(t, err, errMarginCoinEmpty) - _, err = bi.PlaceTriggerFuturesOrder(context.Background(), "meow", "woof", "neigh", "oink", "quack", "", "", "", - "", "", "", "", 0, 0, 0, 0, 0, 0, 0, 0, false) + _, err = bi.PlaceTriggerFuturesOrder(context.Background(), "meow", "woof", "neigh", "oink", "quack", "", "", "", "", "", "", "", 0, 0, 0, 0, 0, 0, 0, 0, false) assert.ErrorIs(t, err, errTriggerTypeEmpty) - _, err = bi.PlaceTriggerFuturesOrder(context.Background(), "meow", "woof", "neigh", "oink", "quack", "baa", "", - "", "", "", "", "", 0, 0, 0, 0, 0, 0, 0, 0, false) + _, err = bi.PlaceTriggerFuturesOrder(context.Background(), "meow", "woof", "neigh", "oink", "quack", "baa", "", "", "", "", "", "", 0, 0, 0, 0, 0, 0, 0, 0, false) assert.ErrorIs(t, err, errSideEmpty) - _, err = bi.PlaceTriggerFuturesOrder(context.Background(), "meow", "woof", "neigh", "oink", "quack", "baa", - "moo", "", "", "", "", "", 0, 0, 0, 0, 0, 0, 0, 0, false) + _, err = bi.PlaceTriggerFuturesOrder(context.Background(), "meow", "woof", "neigh", "oink", "quack", "baa", "moo", "", "", "", "", "", 0, 0, 0, 0, 0, 0, 0, 0, false) assert.ErrorIs(t, err, errOrderTypeEmpty) - _, err = bi.PlaceTriggerFuturesOrder(context.Background(), "meow", "woof", "neigh", "oink", "quack", "baa", - "moo", "", "cluck", "", "", "", 0, 0, 0, 0, 0, 0, 0, 0, false) + _, err = bi.PlaceTriggerFuturesOrder(context.Background(), "meow", "woof", "neigh", "oink", "quack", "baa", "moo", "", "cluck", "", "", "", 0, 0, 0, 0, 0, 0, 0, 0, false) assert.ErrorIs(t, err, errAmountEmpty) - _, err = bi.PlaceTriggerFuturesOrder(context.Background(), "meow", "woof", "neigh", "oink", "quack", "baa", - "moo", "", "cluck", "", "", "", 1, 0, 0, 0, 0, 0, 0, 0, false) + _, err = bi.PlaceTriggerFuturesOrder(context.Background(), "meow", "woof", "neigh", "oink", "quack", "baa", "moo", "", "cluck", "", "", "", 1, 0, 0, 0, 0, 0, 0, 0, false) assert.ErrorIs(t, err, errExecutePriceEmpty) - _, err = bi.PlaceTriggerFuturesOrder(context.Background(), "meow", "woof", "neigh", "oink", "quack", "baa", - "moo", "", "cluck", "", "", "", 1, 1, 0, 0, 0, 0, 0, 0, false) + _, err = bi.PlaceTriggerFuturesOrder(context.Background(), "meow", "woof", "neigh", "oink", "quack", "baa", "moo", "", "cluck", "", "", "", 1, 1, 0, 0, 0, 0, 0, 0, false) assert.ErrorIs(t, err, errTriggerPriceEmpty) - _, err = bi.PlaceTriggerFuturesOrder(context.Background(), "meow", "woof", "neigh", "oink", "quack", "baa", - "moo", "", "cluck", "", "", "", 1, 1, 0, 1, 1, 0, 0, 0, false) + _, err = bi.PlaceTriggerFuturesOrder(context.Background(), "meow", "woof", "neigh", "oink", "quack", "baa", "moo", "", "cluck", "", "", "", 1, 1, 0, 1, 1, 0, 0, 0, false) assert.ErrorIs(t, err, errTakeProfitParamsInconsistency) - _, err = bi.PlaceTriggerFuturesOrder(context.Background(), "meow", "woof", "neigh", "oink", "quack", "baa", - "moo", "", "cluck", "", "", "", 1, 1, 0, 1, 0, 0, 1, 0, false) + _, err = bi.PlaceTriggerFuturesOrder(context.Background(), "meow", "woof", "neigh", "oink", "quack", "baa", "moo", "", "cluck", "", "", "", 1, 1, 0, 1, 0, 0, 1, 0, false) assert.ErrorIs(t, err, errStopLossParamsInconsistency) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi, canManipulateRealOrders) // This returns the error "The parameter does not meet the specification d delegateType is error". The // documentation doesn't mention that parameter anywhere, nothing seems similar to it, and attempts to send // that parameter with various values, or to tweak other parameters, yielded no difference - resp, err := bi.PlaceTriggerFuturesOrder(context.Background(), "normal_plan", testPair2.String(), - testFiat2.String()+"-FUTURES", "isolated", testFiat2.String(), "mark_price", "Sell", "", "limit", - clientIDGenerator(), "", "", testAmount2*1000, testPrice2+2, 0, testPrice2+1, 0, 0, 0, 0, false) + resp, err := bi.PlaceTriggerFuturesOrder(context.Background(), "normal_plan", testPair2.String(), testFiat2.String()+"-FUTURES", "isolated", testFiat2.String(), "mark_price", "Sell", "", "limit", clientIDGenerator(), "", "", testAmount2*1000, testPrice2+2, 0, testPrice2+1, 0, 0, 0, 0, false) require.NoError(t, err) assert.NotEmpty(t, resp.Data) } @@ -1534,8 +1439,7 @@ func TestModifyTPSLFuturesOrder(t *testing.T) { assert.ErrorIs(t, err, errAmountEmpty) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi, canManipulateRealOrders) ID := getTrigOrdIDHelper(t, []string{"profit_loss"}) - resp, err := bi.ModifyTPSLFuturesOrder(context.Background(), ID.OrderID, ID.ClientOrderID, testFiat2.String(), - testFiat2.String()+"-FUTURES", testPair2.String(), "", testPrice2-1, testPrice2+2, testAmount2, 0.1) + resp, err := bi.ModifyTPSLFuturesOrder(context.Background(), int64(ID.OrderID), ID.ClientOrderID, testFiat2.String(), testFiat2.String()+"-FUTURES", testPair2.String(), "", testPrice2-1, testPrice2+2, testAmount2, 0.1) require.NoError(t, err) assert.NotEmpty(t, resp.Data) } @@ -1555,44 +1459,35 @@ func TestGetPendingTriggerFuturesOrders(t *testing.T) { t.Parallel() _, err := bi.GetPendingTriggerFuturesOrders(context.Background(), 0, 0, 0, "", "", "", "", time.Time{}, time.Time{}) assert.ErrorIs(t, err, errPlanTypeEmpty) - _, err = bi.GetPendingTriggerFuturesOrders(context.Background(), 0, 0, 0, "", "", "meow", "", time.Time{}, - time.Time{}) + _, err = bi.GetPendingTriggerFuturesOrders(context.Background(), 0, 0, 0, "", "", "meow", "", time.Time{}, time.Time{}) assert.ErrorIs(t, err, errProductTypeEmpty) - _, err = bi.GetPendingTriggerFuturesOrders(context.Background(), 0, 0, 0, "", "", "meow", "woof", - time.Now().Add(time.Hour), time.Time{}) + _, err = bi.GetPendingTriggerFuturesOrders(context.Background(), 0, 0, 0, "", "", "meow", "woof", time.Now().Add(time.Hour), time.Time{}) assert.ErrorIs(t, err, common.ErrStartAfterTimeNow) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) - resp, err := bi.GetPendingTriggerFuturesOrders(context.Background(), 0, 1<<62, 5, "", testPair2.String(), - "profit_loss", testFiat2.String()+"-FUTURES", time.Time{}, time.Time{}) + resp, err := bi.GetPendingTriggerFuturesOrders(context.Background(), 0, 1<<62, 5, "", testPair2.String(), "profit_loss", testFiat2.String()+"-FUTURES", time.Time{}, time.Time{}) require.NoError(t, err) if len(resp.EntrustedList) == 0 { t.Skip(skipInsufficientOrders) } - _, err = bi.GetPendingTriggerFuturesOrders(context.Background(), resp.EntrustedList[0].OrderID, 1<<62, 5, "", - testPair2.String(), "profit_loss", testFiat2.String()+"-FUTURES", time.Time{}, time.Time{}) + _, err = bi.GetPendingTriggerFuturesOrders(context.Background(), resp.EntrustedList[0].OrderID, 1<<62, 5, "", testPair2.String(), "profit_loss", testFiat2.String()+"-FUTURES", time.Time{}, time.Time{}) assert.NoError(t, err) } func TestGetHistoricalTriggerFuturesOrders(t *testing.T) { t.Parallel() - _, err := bi.GetHistoricalTriggerFuturesOrders(context.Background(), 0, 0, 0, "", "", "", "", "", time.Time{}, - time.Time{}) + _, err := bi.GetHistoricalTriggerFuturesOrders(context.Background(), 0, 0, 0, "", "", "", "", "", time.Time{}, time.Time{}) assert.ErrorIs(t, err, errPlanTypeEmpty) - _, err = bi.GetHistoricalTriggerFuturesOrders(context.Background(), 0, 0, 0, "", "meow", "", "", "", time.Time{}, - time.Time{}) + _, err = bi.GetHistoricalTriggerFuturesOrders(context.Background(), 0, 0, 0, "", "meow", "", "", "", time.Time{}, time.Time{}) assert.ErrorIs(t, err, errProductTypeEmpty) - _, err = bi.GetHistoricalTriggerFuturesOrders(context.Background(), 0, 0, 0, "", "meow", "", "", "woof", - time.Now().Add(time.Hour), time.Time{}) + _, err = bi.GetHistoricalTriggerFuturesOrders(context.Background(), 0, 0, 0, "", "meow", "", "", "woof", time.Now().Add(time.Hour), time.Time{}) assert.ErrorIs(t, err, common.ErrStartAfterTimeNow) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) - resp, err := bi.GetHistoricalTriggerFuturesOrders(context.Background(), 0, 1<<62, 5, "", "normal_plan", "", - testPair2.String(), testFiat2.String()+"-FUTURES", time.Time{}, time.Time{}) + resp, err := bi.GetHistoricalTriggerFuturesOrders(context.Background(), 0, 1<<62, 5, "", "normal_plan", "", testPair2.String(), testFiat2.String()+"-FUTURES", time.Time{}, time.Time{}) require.NoError(t, err) if len(resp.EntrustedList) == 0 { t.Skip(skipInsufficientOrders) } - _, err = bi.GetHistoricalTriggerFuturesOrders(context.Background(), resp.EntrustedList[0].OrderID, 1<<62, 5, - "", "normal_plan", "", testPair2.String(), testFiat2.String()+"-FUTURES", time.Time{}, time.Time{}) + _, err = bi.GetHistoricalTriggerFuturesOrders(context.Background(), resp.EntrustedList[0].OrderID, 1<<62, 5, "", "normal_plan", "", testPair2.String(), testFiat2.String()+"-FUTURES", time.Time{}, time.Time{}) assert.NoError(t, err) } @@ -1622,8 +1517,7 @@ func TestGetCrossBorrowHistory(t *testing.T) { _, err := bi.GetCrossBorrowHistory(context.Background(), 0, 0, 0, "", time.Time{}, time.Time{}) assert.ErrorIs(t, err, common.ErrDateUnset) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) - _, err = bi.GetCrossBorrowHistory(context.Background(), 1, 2, 1<<62, "", time.Now().Add(-time.Hour*24*85), - time.Time{}) + _, err = bi.GetCrossBorrowHistory(context.Background(), 1, 2, 1<<62, "", time.Now().Add(-time.Hour*24*85), time.Time{}) assert.NoError(t, err) } @@ -1632,8 +1526,7 @@ func TestGetCrossRepayHistory(t *testing.T) { _, err := bi.GetCrossRepayHistory(context.Background(), 0, 0, 0, "", time.Time{}, time.Time{}) assert.ErrorIs(t, err, common.ErrDateUnset) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) - _, err = bi.GetCrossRepayHistory(context.Background(), 1, 2, 1<<62, "", time.Now().Add(-time.Hour*24*85), - time.Time{}) + _, err = bi.GetCrossRepayHistory(context.Background(), 1, 2, 1<<62, "", time.Now().Add(-time.Hour*24*85), time.Time{}) assert.NoError(t, err) } @@ -1642,8 +1535,7 @@ func TestGetCrossInterestHistory(t *testing.T) { _, err := bi.GetCrossInterestHistory(context.Background(), "", time.Time{}, time.Time{}, 0, 0) assert.ErrorIs(t, err, common.ErrDateUnset) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) - _, err = bi.GetCrossInterestHistory(context.Background(), "", time.Now().Add(-time.Hour*24*85), time.Time{}, 2, - 1<<62) + _, err = bi.GetCrossInterestHistory(context.Background(), "", time.Now().Add(-time.Hour*24*85), time.Time{}, 2, 1<<62) assert.NoError(t, err) } @@ -1652,8 +1544,7 @@ func TestGetCrossLiquidationHistory(t *testing.T) { _, err := bi.GetCrossLiquidationHistory(context.Background(), time.Time{}, time.Time{}, 0, 0) assert.ErrorIs(t, err, common.ErrDateUnset) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) - _, err = bi.GetCrossLiquidationHistory(context.Background(), time.Now().Add(-time.Hour*24*85), time.Time{}, 2, - 1<<62) + _, err = bi.GetCrossLiquidationHistory(context.Background(), time.Now().Add(-time.Hour*24*85), time.Time{}, 2, 1<<62) assert.NoError(t, err) } @@ -1662,8 +1553,7 @@ func TestGetCrossFinancialHistory(t *testing.T) { _, err := bi.GetCrossFinancialHistory(context.Background(), "", "", time.Time{}, time.Time{}, 0, 0) assert.ErrorIs(t, err, common.ErrDateUnset) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) - _, err = bi.GetCrossFinancialHistory(context.Background(), "", "", time.Now().Add(-time.Hour*24*85), time.Time{}, - 2, 1<<62) + _, err = bi.GetCrossFinancialHistory(context.Background(), "", "", time.Now().Add(-time.Hour*24*85), time.Time{}, 2, 1<<62) assert.NoError(t, err) } @@ -1712,8 +1602,7 @@ func TestGetCrossMaxTransferable(t *testing.T) { func TestGetCrossInterestRateAndMaxBorrowable(t *testing.T) { t.Parallel() - testGetOneArg(t, bi.GetCrossInterestRateAndMaxBorrowable, "", testFiat.String(), errCurrencyEmpty, false, true, - true) + testGetOneArg(t, bi.GetCrossInterestRateAndMaxBorrowable, "", testFiat.String(), errCurrencyEmpty, false, true, true) } func TestGetCrossTierConfiguration(t *testing.T) { @@ -1788,8 +1677,7 @@ func TestGetCrossOpenOrders(t *testing.T) { assert.ErrorIs(t, err, common.ErrDateUnset) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) resp := getCrossOrdIDHelper(t, true) - _, err = bi.GetCrossOpenOrders(context.Background(), testPair.String(), "", resp.OrderID, - 5, 1<<62, time.Now().Add(-time.Hour*24*85), time.Time{}) + _, err = bi.GetCrossOpenOrders(context.Background(), testPair.String(), "", int64(resp.OrderID), 5, 1<<62, time.Now().Add(-time.Hour*24*85), time.Time{}) assert.NoError(t, err) } @@ -1800,14 +1688,12 @@ func TestGetCrossHistoricalorders(t *testing.T) { _, err = bi.GetCrossHistoricalOrders(context.Background(), "meow", "", "", 0, 0, 0, time.Time{}, time.Time{}) assert.ErrorIs(t, err, common.ErrDateUnset) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) - resp, err := bi.GetCrossHistoricalOrders(context.Background(), testPair.String(), "", "", 0, 5, 1<<62, - time.Now().Add(-time.Hour*24*85), time.Time{}) + resp, err := bi.GetCrossHistoricalOrders(context.Background(), testPair.String(), "", "", 0, 5, 1<<62, time.Now().Add(-time.Hour*24*85), time.Time{}) require.NoError(t, err) if len(resp.OrderList) == 0 { t.Skip(skipInsufficientOrders) } - _, err = bi.GetCrossHistoricalOrders(context.Background(), testPair.String(), "", "", - resp.OrderList[0].OrderID, 5, 1<<62, time.Now().Add(-time.Hour*24*85), time.Time{}) + _, err = bi.GetCrossHistoricalOrders(context.Background(), testPair.String(), "", "", resp.OrderList[0].OrderID, 5, 1<<62, time.Now().Add(-time.Hour*24*85), time.Time{}) assert.NoError(t, err) } @@ -1818,21 +1704,18 @@ func TestGetCrossOrderFills(t *testing.T) { _, err = bi.GetCrossOrderFills(context.Background(), "meow", 0, 0, 0, time.Time{}, time.Time{}) assert.ErrorIs(t, err, common.ErrDateUnset) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) - resp, err := bi.GetCrossOrderFills(context.Background(), testPair.String(), 0, 1<<62, 5, - time.Now().Add(-time.Hour*24*85), time.Time{}) + resp, err := bi.GetCrossOrderFills(context.Background(), testPair.String(), 0, 1<<62, 5, time.Now().Add(-time.Hour*24*85), time.Time{}) require.NoError(t, err) if len(resp.Fills) == 0 { t.Skip(skipInsufficientOrders) } - _, err = bi.GetCrossOrderFills(context.Background(), testPair.String(), resp.Fills[0].OrderID, 1<<62, 5, - time.Now().Add(-time.Hour*24*85), time.Time{}) + _, err = bi.GetCrossOrderFills(context.Background(), testPair.String(), resp.Fills[0].OrderID, 1<<62, 5, time.Now().Add(-time.Hour*24*85), time.Time{}) assert.NoError(t, err) } func TestGetCrossLiquidationOrders(t *testing.T) { t.Parallel() - _, err := bi.GetCrossLiquidationOrders(context.Background(), "", "", "", "", time.Now().Add(time.Hour), time.Time{}, - 5, 1<<62) + _, err := bi.GetCrossLiquidationOrders(context.Background(), "", "", "", "", time.Now().Add(time.Hour), time.Time{}, 5, 1<<62) assert.ErrorIs(t, err, common.ErrStartAfterTimeNow) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) _, err = bi.GetCrossLiquidationOrders(context.Background(), "", "", "", "", time.Time{}, time.Time{}, 5, 1<<62) @@ -1846,14 +1729,12 @@ func TestGetIsolatedRepayHistory(t *testing.T) { _, err = bi.GetIsolatedRepayHistory(context.Background(), "meow", "", 0, 0, 0, time.Time{}, time.Time{}) assert.ErrorIs(t, err, common.ErrDateUnset) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) - resp, err := bi.GetIsolatedRepayHistory(context.Background(), testPair.String(), "", 0, 5, 1<<62, - time.Now().Add(-time.Hour*24*85), time.Time{}) + resp, err := bi.GetIsolatedRepayHistory(context.Background(), testPair.String(), "", 0, 5, 1<<62, time.Now().Add(-time.Hour*24*85), time.Time{}) require.NoError(t, err) if len(resp.ResultList) == 0 { t.Skip(skipInsufficientOrders) } - _, err = bi.GetIsolatedRepayHistory(context.Background(), testPair.String(), "", resp.ResultList[0].RepayID, - 5, 1<<62, time.Now().Add(-time.Hour*24*85), time.Time{}) + _, err = bi.GetIsolatedRepayHistory(context.Background(), testPair.String(), "", resp.ResultList[0].RepayID, 5, 1<<62, time.Now().Add(-time.Hour*24*85), time.Time{}) assert.NoError(t, err) } @@ -1864,8 +1745,7 @@ func TestGetIsolatedInterestHistory(t *testing.T) { _, err = bi.GetIsolatedInterestHistory(context.Background(), "meow", "", time.Time{}, time.Time{}, 0, 0) assert.ErrorIs(t, err, common.ErrDateUnset) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) - _, err = bi.GetIsolatedInterestHistory(context.Background(), testPair.String(), "", - time.Now().Add(-time.Hour*24*85), time.Time{}, 2, 1<<62) + _, err = bi.GetIsolatedInterestHistory(context.Background(), testPair.String(), "", time.Now().Add(-time.Hour*24*85), time.Time{}, 2, 1<<62) assert.NoError(t, err) } @@ -1876,8 +1756,7 @@ func TestGetIsolatedLiquidationHistory(t *testing.T) { _, err = bi.GetIsolatedLiquidationHistory(context.Background(), "meow", time.Time{}, time.Time{}, 0, 0) assert.ErrorIs(t, err, common.ErrDateUnset) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) - _, err = bi.GetIsolatedLiquidationHistory(context.Background(), testPair.String(), - time.Now().Add(-time.Hour*24*85), time.Time{}, 2, 1<<62) + _, err = bi.GetIsolatedLiquidationHistory(context.Background(), testPair.String(), time.Now().Add(-time.Hour*24*85), time.Time{}, 2, 1<<62) assert.NoError(t, err) } @@ -1888,8 +1767,7 @@ func TestGetIsolatedFinancialHistory(t *testing.T) { _, err = bi.GetIsolatedFinancialHistory(context.Background(), "meow", "", "", time.Time{}, time.Time{}, 0, 0) assert.ErrorIs(t, err, common.ErrDateUnset) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) - _, err = bi.GetIsolatedFinancialHistory(context.Background(), testPair.String(), "", "", - time.Now().Add(-time.Hour*24*85), time.Time{}, 2, 1<<62) + _, err = bi.GetIsolatedFinancialHistory(context.Background(), testPair.String(), "", "", time.Now().Add(-time.Hour*24*85), time.Time{}, 2, 1<<62) assert.NoError(t, err) } @@ -1933,8 +1811,7 @@ func TestGetIsolatedRiskRate(t *testing.T) { func TestGetIsolatedInterestRateAndMaxBorrowable(t *testing.T) { t.Parallel() - testGetOneArg(t, bi.GetIsolatedInterestRateAndMaxBorrowable, "", testPair.String(), errPairEmpty, false, true, - true) + testGetOneArg(t, bi.GetIsolatedInterestRateAndMaxBorrowable, "", testPair.String(), errPairEmpty, false, true, true) } func TestGetIsolatedTierConfiguration(t *testing.T) { @@ -1954,8 +1831,7 @@ func TestGetIsolatedMaxTransferable(t *testing.T) { func TestIsolatedFlashRepay(t *testing.T) { t.Parallel() - testGetOneArg(t, bi.IsolatedFlashRepay, nil, []string{testPair.String()}, nil, false, true, - canManipulateRealOrders) + testGetOneArg(t, bi.IsolatedFlashRepay, nil, []string{testPair.String()}, nil, false, true, canManipulateRealOrders) } func TestGetIsolatedFlashRepayResult(t *testing.T) { @@ -1966,8 +1842,8 @@ func TestGetIsolatedFlashRepayResult(t *testing.T) { // This must be done, as this is the only way to get a repayment ID resp, err := bi.IsolatedFlashRepay(context.Background(), []string{testPair.String()}) require.NoError(t, err) - require.NotEmpty(t, resp.Data) - _, err = bi.GetIsolatedFlashRepayResult(context.Background(), []int64{resp.Data[0].RepayID}) + require.NotEmpty(t, resp) + _, err = bi.GetIsolatedFlashRepayResult(context.Background(), []int64{resp[0].RepayID}) assert.NoError(t, err) } @@ -1986,8 +1862,7 @@ func TestPlaceIsolatedOrder(t *testing.T) { _, err = bi.PlaceIsolatedOrder(context.Background(), "meow", "woof", "neigh", "oink", "", "quack", 0, 0, 0) assert.ErrorIs(t, err, errAmountEmpty) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi, canManipulateRealOrders) - _, err = bi.PlaceIsolatedOrder(context.Background(), testPair.String(), "limit", "normal", "GTC", "", "Buy", - testPrice2, testAmount2, 0) + _, err = bi.PlaceIsolatedOrder(context.Background(), testPair.String(), "limit", "normal", "GTC", "", "Buy", testPrice2, testAmount2, 0) assert.NoError(t, err) } @@ -2016,13 +1891,11 @@ func TestGetIsolatedOpenOrders(t *testing.T) { t.Parallel() _, err := bi.GetIsolatedOpenOrders(context.Background(), "", "", 0, 0, 0, time.Time{}, time.Time{}) assert.ErrorIs(t, err, errPairEmpty) - _, err = bi.GetIsolatedOpenOrders(context.Background(), "meow", "", 0, 0, 0, time.Now().Add(time.Hour), - time.Time{}) + _, err = bi.GetIsolatedOpenOrders(context.Background(), "meow", "", 0, 0, 0, time.Now().Add(time.Hour), time.Time{}) assert.ErrorIs(t, err, common.ErrStartAfterTimeNow) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) resp := getIsoOrdIDHelper(t, true) - _, err = bi.GetIsolatedOpenOrders(context.Background(), testPair.String(), "", resp.OrderID, - 5, 1<<62, time.Now().Add(-time.Hour*24*85), time.Time{}) + _, err = bi.GetIsolatedOpenOrders(context.Background(), testPair.String(), "", int64(resp.OrderID), 5, 1<<62, time.Now().Add(-time.Hour*24*85), time.Time{}) assert.NoError(t, err) } @@ -2033,14 +1906,12 @@ func TestGetIsolatedHistoricalOrders(t *testing.T) { _, err = bi.GetIsolatedHistoricalOrders(context.Background(), "meow", "", "", 0, 0, 0, time.Time{}, time.Time{}) assert.ErrorIs(t, err, common.ErrDateUnset) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) - resp, err := bi.GetIsolatedHistoricalOrders(context.Background(), testPair.String(), "", "", 0, 5, 1<<62, - time.Now().Add(-time.Hour*24*85), time.Time{}) + resp, err := bi.GetIsolatedHistoricalOrders(context.Background(), testPair.String(), "", "", 0, 5, 1<<62, time.Now().Add(-time.Hour*24*85), time.Time{}) require.NoError(t, err) if len(resp.OrderList) == 0 { t.Skip(skipInsufficientOrders) } - _, err = bi.GetIsolatedHistoricalOrders(context.Background(), testPair.String(), "", "", - resp.OrderList[0].OrderID, 5, 1<<62, time.Now().Add(-time.Hour*24*85), time.Time{}) + _, err = bi.GetIsolatedHistoricalOrders(context.Background(), testPair.String(), "", "", resp.OrderList[0].OrderID, 5, 1<<62, time.Now().Add(-time.Hour*24*85), time.Time{}) assert.NoError(t, err) } @@ -2051,21 +1922,18 @@ func TestGetIsolatedOrderFills(t *testing.T) { _, err = bi.GetIsolatedOrderFills(context.Background(), "meow", 0, 0, 0, time.Time{}, time.Time{}) assert.ErrorIs(t, err, common.ErrDateUnset) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) - resp, err := bi.GetIsolatedOrderFills(context.Background(), testPair.String(), 0, 1<<62, 5, - time.Now().Add(-time.Hour*24*85), time.Time{}) + resp, err := bi.GetIsolatedOrderFills(context.Background(), testPair.String(), 0, 1<<62, 5, time.Now().Add(-time.Hour*24*85), time.Time{}) require.NoError(t, err) if len(resp.Fills) == 0 { t.Skip(skipInsufficientOrders) } - _, err = bi.GetIsolatedOrderFills(context.Background(), testPair.String(), resp.Fills[0].OrderID, 1<<62, 5, - time.Now().Add(-time.Hour*24*85), time.Time{}) + _, err = bi.GetIsolatedOrderFills(context.Background(), testPair.String(), resp.Fills[0].OrderID, 1<<62, 5, time.Now().Add(-time.Hour*24*85), time.Time{}) assert.NoError(t, err) } func TestGetIsolatedLiquidationOrders(t *testing.T) { t.Parallel() - _, err := bi.GetIsolatedLiquidationOrders(context.Background(), "", "", "", "", time.Now().Add(time.Hour), - time.Time{}, 5, 1<<62) + _, err := bi.GetIsolatedLiquidationOrders(context.Background(), "", "", "", "", time.Now().Add(time.Hour), time.Time{}, 5, 1<<62) assert.ErrorIs(t, err, common.ErrStartAfterTimeNow) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) _, err = bi.GetIsolatedLiquidationOrders(context.Background(), "", "", "", "", time.Time{}, time.Time{}, 5, 1<<62) @@ -2114,8 +1982,8 @@ func TestGetSavingsSubscriptionDetail(t *testing.T) { sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) resp, err := bi.GetSavingsProductList(context.Background(), testCrypto.String(), "") require.NoError(t, err) - require.NotEmpty(t, resp.Data) - _, err = bi.GetSavingsSubscriptionDetail(context.Background(), resp.Data[0].ProductID, resp.Data[0].PeriodType) + require.NotEmpty(t, resp) + _, err = bi.GetSavingsSubscriptionDetail(context.Background(), resp[0].ProductID, resp[0].PeriodType) assert.NoError(t, err) } @@ -2130,12 +1998,11 @@ func TestSubscribeSavings(t *testing.T) { sharedtestvalues.SkipTestIfCredentialsUnset(t, bi, canManipulateRealOrders) resp, err := bi.GetSavingsProductList(context.Background(), testCrypto.String(), "") require.NoError(t, err) - require.NotEmpty(t, resp.Data) - resp2, err := bi.GetSavingsSubscriptionDetail(context.Background(), resp.Data[0].ProductID, resp.Data[0].PeriodType) + require.NotEmpty(t, resp) + resp2, err := bi.GetSavingsSubscriptionDetail(context.Background(), resp[0].ProductID, resp[0].PeriodType) require.NoError(t, err) - require.NotEmpty(t, resp2.Data) - _, err = bi.SubscribeSavings(context.Background(), resp.Data[0].ProductID, resp.Data[0].PeriodType, - resp2.Data.SingleMinAmount) + require.NotEmpty(t, resp2) + _, err = bi.SubscribeSavings(context.Background(), resp[0].ProductID, resp[0].PeriodType, resp2.SingleMinAmount) assert.NoError(t, err) } @@ -2148,10 +2015,10 @@ func TestGetSavingsSubscriptionResult(t *testing.T) { sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) resp, err := bi.GetSavingsRecords(context.Background(), "", "", "", time.Time{}, time.Time{}, 100, 0) require.NoError(t, err) - require.NotEmpty(t, resp.Data.ResultList) + require.NotEmpty(t, resp.ResultList) tarID := -1 - for x := range resp.Data.ResultList { - if resp.Data.ResultList[x].OrderType == "subscribe" { + for x := range resp.ResultList { + if resp.ResultList[x].OrderType == "subscribe" { tarID = x break } @@ -2159,8 +2026,7 @@ func TestGetSavingsSubscriptionResult(t *testing.T) { if tarID == -1 { t.Skip(skipInsufficientOrders) } - _, err = bi.GetSavingsSubscriptionResult(context.Background(), resp.Data.ResultList[tarID].OrderID, - resp.Data.ResultList[tarID].ProductType) + _, err = bi.GetSavingsSubscriptionResult(context.Background(), resp.ResultList[tarID].OrderID, resp.ResultList[tarID].ProductType) assert.NoError(t, err) } @@ -2180,19 +2046,19 @@ func TestRedeemSavings(t *testing.T) { for { resp, err := bi.GetSavingsAssets(context.Background(), "", time.Time{}, time.Time{}, 100, pagination) require.NoError(t, err) - require.NotEmpty(t, resp.Data) - for i := range resp.Data.ResultList { - if resp.Data.ResultList[i].AllowRedemption && resp.Data.ResultList[i].Status != "in_redemption" { - tarProd = resp.Data.ResultList[i].ProductID - tarOrd = resp.Data.ResultList[i].OrderID - tarPeriod = resp.Data.ResultList[i].PeriodType + require.NotEmpty(t, resp) + for i := range resp.ResultList { + if resp.ResultList[i].AllowRedemption && resp.ResultList[i].Status != "in_redemption" { + tarProd = resp.ResultList[i].ProductID + tarOrd = resp.ResultList[i].OrderID + tarPeriod = resp.ResultList[i].PeriodType break } } - if tarProd != 0 || int64(resp.Data.EndID) == pagination || resp.Data.EndID == 0 { + if tarProd != 0 || int64(resp.EndID) == pagination || resp.EndID == 0 { break } else { - pagination = int64(resp.Data.EndID) + pagination = int64(resp.EndID) } } if tarProd == 0 { @@ -2211,10 +2077,10 @@ func TestGetSavingsRedemptionResult(t *testing.T) { sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) resp, err := bi.GetSavingsRecords(context.Background(), "", "", "", time.Time{}, time.Time{}, 100, 0) require.NoError(t, err) - require.NotEmpty(t, resp.Data.ResultList) + require.NotEmpty(t, resp.ResultList) tarID := -1 - for x := range resp.Data.ResultList { - if resp.Data.ResultList[x].OrderType == "redeem" { + for x := range resp.ResultList { + if resp.ResultList[x].OrderType == "redeem" { tarID = x break } @@ -2222,8 +2088,7 @@ func TestGetSavingsRedemptionResult(t *testing.T) { if tarID == -1 { t.Skip(skipInsufficientOrders) } - _, err = bi.GetSavingsRedemptionResult(context.Background(), resp.Data.ResultList[tarID].OrderID, - resp.Data.ResultList[tarID].ProductType) + _, err = bi.GetSavingsRedemptionResult(context.Background(), resp.ResultList[tarID].OrderID, resp.ResultList[tarID].ProductType) assert.NoError(t, err) } @@ -2272,8 +2137,8 @@ func TestGetSharkFinSubscriptionDetail(t *testing.T) { sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) resp, err := bi.GetSharkFinProducts(context.Background(), testCrypto.String(), 5, 1<<62) require.NoError(t, err) - require.NotEmpty(t, resp.Data) - _, err = bi.GetSharkFinSubscriptionDetail(context.Background(), resp.Data.ResultList[0].ProductID) + require.NotEmpty(t, resp) + _, err = bi.GetSharkFinSubscriptionDetail(context.Background(), resp.ResultList[0].ProductID) assert.NoError(t, err) } @@ -2286,9 +2151,8 @@ func TestSubscribeSharkFin(t *testing.T) { sharedtestvalues.SkipTestIfCredentialsUnset(t, bi, canManipulateRealOrders) resp, err := bi.GetSharkFinProducts(context.Background(), testCrypto.String(), 5, 1<<62) require.NoError(t, err) - require.NotEmpty(t, resp.Data) - _, err = bi.SubscribeSharkFin(context.Background(), resp.Data.ResultList[0].ProductID, - resp.Data.ResultList[0].MinAmount) + require.NotEmpty(t, resp) + _, err = bi.SubscribeSharkFin(context.Background(), resp.ResultList[0].ProductID, resp.ResultList[0].MinAmount) assert.NoError(t, err) } @@ -2299,10 +2163,10 @@ func TestGetSharkFinSubscriptionResult(t *testing.T) { sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) resp, err := bi.GetSharkFinRecords(context.Background(), "", "", time.Time{}, time.Time{}, 100, 0) require.NoError(t, err) - require.NotEmpty(t, resp.Data.ResultList) + require.NotEmpty(t, resp) tarID := -1 - for x := range resp.Data.ResultList { - if resp.Data.ResultList[x].Type == "subscribe" { + for x := range resp { + if resp[x].Type == "subscribe" { tarID = x break } @@ -2310,7 +2174,7 @@ func TestGetSharkFinSubscriptionResult(t *testing.T) { if tarID == -1 { t.Skip(skipInsufficientOrders) } - _, err = bi.GetSharkFinSubscriptionResult(context.Background(), resp.Data.ResultList[tarID].OrderID) + _, err = bi.GetSharkFinSubscriptionResult(context.Background(), resp[tarID].OrderID) assert.NoError(t, err) } @@ -2329,8 +2193,7 @@ func TestGetEstimatedInterestAndBorrowable(t *testing.T) { assert.ErrorIs(t, err, errTermEmpty) _, err = bi.GetEstimatedInterestAndBorrowable(context.Background(), "meow", "woof", "neigh", 0) assert.ErrorIs(t, err, errCollateralAmountEmpty) - _, err = bi.GetEstimatedInterestAndBorrowable(context.Background(), testCrypto.String(), testFiat.String(), "SEVEN", - testPrice) + _, err = bi.GetEstimatedInterestAndBorrowable(context.Background(), testCrypto.String(), testFiat.String(), "SEVEN", testPrice) assert.NoError(t, err) } @@ -2354,10 +2217,10 @@ func TestGetOngoingLoans(t *testing.T) { sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) resp, err := bi.GetOngoingLoans(context.Background(), 0, "", "") require.NoError(t, err) - if len(resp.Data) == 0 { + if len(resp) == 0 { t.Skip(skipInsufficientOrders) } - _, err = bi.GetOngoingLoans(context.Background(), resp.Data[0].OrderID, "", "") + _, err = bi.GetOngoingLoans(context.Background(), resp[0].OrderID, "", "") assert.NoError(t, err) } @@ -2383,10 +2246,10 @@ func TestModifyPledgeRate(t *testing.T) { sharedtestvalues.SkipTestIfCredentialsUnset(t, bi, canManipulateRealOrders) resp, err := bi.GetOngoingLoans(context.Background(), 0, "", "") require.NoError(t, err) - if len(resp.Data) == 0 { + if len(resp) == 0 { t.Skip(skipInsufficientOrders) } - _, err = bi.ModifyPledgeRate(context.Background(), resp.Data[0].OrderID, testAmount, testFiat.String(), "IN") + _, err = bi.ModifyPledgeRate(context.Background(), resp[0].OrderID, testAmount, testFiat.String(), "IN") assert.NoError(t, err) } @@ -2395,8 +2258,7 @@ func TestGetPledgeRateHistory(t *testing.T) { _, err := bi.GetPledgeRateHistory(context.Background(), 0, 0, 0, "", "", time.Time{}, time.Time{}) assert.ErrorIs(t, err, common.ErrDateUnset) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) - _, err = bi.GetPledgeRateHistory(context.Background(), 0, 1, 5, "", "", time.Now().Add(-time.Hour*24*85), - time.Now()) + _, err = bi.GetPledgeRateHistory(context.Background(), 0, 1, 5, "", "", time.Now().Add(-time.Hour*24*85), time.Now()) assert.NoError(t, err) } @@ -2422,8 +2284,7 @@ func TestGetLiquidationRecords(t *testing.T) { _, err := bi.GetLiquidationRecords(context.Background(), 0, 0, 0, "", "", "", time.Time{}, time.Time{}) assert.ErrorIs(t, err, common.ErrDateUnset) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) - _, err = bi.GetLiquidationRecords(context.Background(), 0, 1, 5, "", "", "", time.Now().Add(-time.Hour*24*85), - time.Now()) + _, err = bi.GetLiquidationRecords(context.Background(), 0, 1, 5, "", "", "", time.Now().Add(-time.Hour*24*85), time.Now()) assert.NoError(t, err) } @@ -2547,13 +2408,11 @@ func TestGetHistoricTrades(t *testing.T) { t.Parallel() _, err := bi.GetHistoricTrades(context.Background(), fakePair, asset.Spot, time.Time{}, time.Time{}) assert.Error(t, err) - _, err = bi.GetHistoricTrades(context.Background(), testPair, asset.Spot, time.Now().Add(-time.Hour*24*7), - time.Now()) + _, err = bi.GetHistoricTrades(context.Background(), testPair, asset.Spot, time.Now().Add(-time.Hour*24*7), time.Now()) assert.NoError(t, err) _, err = bi.GetHistoricTrades(context.Background(), fakePair, asset.Futures, time.Time{}, time.Time{}) assert.Error(t, err) - _, err = bi.GetHistoricTrades(context.Background(), testPair, asset.Futures, time.Now().Add(-time.Hour*24*7), - time.Now()) + _, err = bi.GetHistoricTrades(context.Background(), testPair, asset.Futures, time.Now().Add(-time.Hour*24*7), time.Now()) assert.NoError(t, err) _, err = bi.GetHistoricTrades(context.Background(), testPair, asset.Empty, time.Time{}, time.Time{}) assert.ErrorIs(t, err, asset.ErrNotSupported) @@ -2614,24 +2473,23 @@ func TestGetOrderInfo(t *testing.T) { sharedtestvalues.SkipTestIfCredentialsUnset(t, bi) oID := getFuturesOrdIDHelper(t, true, false) if oID.ClientOrderID != ordersNotFound { - _, err = bi.GetOrderInfo(context.Background(), strconv.FormatInt(oID.OrderID, 10), testPair2, asset.Futures) + _, err = bi.GetOrderInfo(context.Background(), strconv.FormatInt(int64(oID.OrderID), 10), testPair2, asset.Futures) assert.NoError(t, err) } oID = getIsoOrdIDHelper(t, false) if oID.ClientOrderID != ordersNotFound { - _, err = bi.GetOrderInfo(context.Background(), strconv.FormatInt(oID.OrderID, 10), testPair2, asset.Margin) + _, err = bi.GetOrderInfo(context.Background(), strconv.FormatInt(int64(oID.OrderID), 10), testPair2, asset.Margin) assert.NoError(t, err) } oID = getCrossOrdIDHelper(t, false) if oID.ClientOrderID != ordersNotFound { - _, err = bi.GetOrderInfo(context.Background(), strconv.FormatInt(oID.OrderID, 10), testPair2, asset.CrossMargin) + _, err = bi.GetOrderInfo(context.Background(), strconv.FormatInt(int64(oID.OrderID), 10), testPair2, asset.CrossMargin) assert.NoError(t, err) } resp, err := bi.GetUnfilledOrders(context.Background(), testPair.String(), time.Time{}, time.Time{}, 5, 1<<62, 0) require.NoError(t, err) if len(resp) != 0 { - _, err = bi.GetOrderInfo(context.Background(), strconv.FormatInt(int64(resp[0].OrderID), 10), testPair, - asset.Spot) + _, err = bi.GetOrderInfo(context.Background(), strconv.FormatInt(int64(resp[0].OrderID), 10), testPair, asset.Spot) assert.NoError(t, err) } } @@ -2770,24 +2628,19 @@ func TestGetHistoricCandles(t *testing.T) { t.Parallel() _, err := bi.GetHistoricCandles(context.Background(), currency.Pair{}, asset.Spot, kline.Raw, time.Time{}, time.Time{}) assert.ErrorIs(t, err, currency.ErrCurrencyPairEmpty) - _, err = bi.GetHistoricCandles(context.Background(), testPair, asset.Spot, kline.OneDay, - time.Now().Add(-time.Hour*24*20), time.Now()) + _, err = bi.GetHistoricCandles(context.Background(), testPair, asset.Spot, kline.OneDay, time.Now().Add(-time.Hour*24*20), time.Now()) assert.NoError(t, err) - _, err = bi.GetHistoricCandles(context.Background(), testPair, asset.Futures, kline.OneDay, - time.Now().Add(-time.Hour*24*20), time.Now()) + _, err = bi.GetHistoricCandles(context.Background(), testPair, asset.Futures, kline.OneDay, time.Now().Add(-time.Hour*24*20), time.Now()) assert.NoError(t, err) } func TestGetHistoricCandlesExtended(t *testing.T) { t.Parallel() - _, err := bi.GetHistoricCandlesExtended(context.Background(), currency.Pair{}, asset.Spot, kline.Raw, time.Time{}, - time.Time{}) + _, err := bi.GetHistoricCandlesExtended(context.Background(), currency.Pair{}, asset.Spot, kline.Raw, time.Time{}, time.Time{}) assert.ErrorIs(t, err, currency.ErrCurrencyPairEmpty) - _, err = bi.GetHistoricCandlesExtended(context.Background(), testPair, asset.Spot, kline.OneDay, - time.Now().Add(-time.Hour*24*20), time.Now()) + _, err = bi.GetHistoricCandlesExtended(context.Background(), testPair, asset.Spot, kline.OneDay, time.Now().Add(-time.Hour*24*20), time.Now()) assert.NoError(t, err) - _, err = bi.GetHistoricCandlesExtended(context.Background(), testPair, asset.Futures, kline.OneDay, - time.Now().Add(-time.Hour*24*20), time.Now()) + _, err = bi.GetHistoricCandlesExtended(context.Background(), testPair, asset.Futures, kline.OneDay, time.Now().Add(-time.Hour*24*20), time.Now()) assert.NoError(t, err) } @@ -2949,8 +2802,7 @@ func TestGetLeverage(t *testing.T) { func TestGetOpenInterest(t *testing.T) { t.Parallel() - _, err := bi.GetOpenInterest(context.Background(), key.PairAsset{Base: testCrypto.Item, Quote: testFiat.Item, - Asset: asset.Futures}) + _, err := bi.GetOpenInterest(context.Background(), key.PairAsset{Base: testCrypto.Item, Quote: testFiat.Item, Asset: asset.Futures}) assert.NoError(t, err) } @@ -2972,8 +2824,7 @@ func TestModifyPlanSpotOrder(t *testing.T) { if len(ordID.OrderList) == 0 { t.Skip(skipInsufficientOrders) } - resp, err := bi.ModifyPlanSpotOrder(context.Background(), ordID.OrderList[0].OrderID, - ordID.OrderList[0].ClientOrderID, "limit", testPrice, testPrice, testAmount) + resp, err := bi.ModifyPlanSpotOrder(context.Background(), ordID.OrderList[0].OrderID, ordID.OrderList[0].ClientOrderID, "limit", testPrice, testPrice, testAmount) require.NoError(t, err) assert.NotEmpty(t, resp.Data) } @@ -2988,8 +2839,7 @@ func TestCancelPlanSpotOrder(t *testing.T) { if len(ordID.OrderList) == 0 { t.Skip(skipInsufficientOrders) } - resp, err := bi.CancelPlanSpotOrder(context.Background(), ordID.OrderList[0].OrderID, - ordID.OrderList[0].ClientOrderID) + resp, err := bi.CancelPlanSpotOrder(context.Background(), ordID.OrderList[0].OrderID, ordID.OrderList[0].ClientOrderID) require.NoError(t, err) assert.NotEmpty(t, resp) } @@ -3040,8 +2890,7 @@ func TestCommitConversion(t *testing.T) { sharedtestvalues.SkipTestIfCredentialsUnset(t, bi, canManipulateRealOrders) resp, err := bi.GetQuotedPrice(context.Background(), testCrypto.String(), testFiat.String(), testAmount, 0) require.NoError(t, err) - _, err = bi.CommitConversion(context.Background(), testCrypto.String(), testFiat.String(), resp.TraceID, - resp.FromCoinSize, resp.ToCoinSize, resp.ConvertPrice) + _, err = bi.CommitConversion(context.Background(), testCrypto.String(), testFiat.String(), resp.TraceID, resp.FromCoinSize, resp.ToCoinSize, resp.ConvertPrice) assert.NoError(t, err) } @@ -3052,8 +2901,7 @@ func TestCancelTriggerFuturesOrders(t *testing.T) { sharedtestvalues.SkipTestIfCredentialsUnset(t, bi, canManipulateRealOrders) oID := getTrigOrdIDHelper(t, []string{"profit_loss", "normal_plan", "track_plan"}) ordList = append(ordList, *oID) - resp, err := bi.CancelTriggerFuturesOrders(context.Background(), ordList, testPair2.String(), - testFiat2.String()+"-FUTURES", "", "") + resp, err := bi.CancelTriggerFuturesOrders(context.Background(), ordList, testPair2.String(), testFiat2.String()+"-FUTURES", "", "") require.NoError(t, err) assert.NotEmpty(t, resp) } @@ -3066,12 +2914,12 @@ func TestRepayLoan(t *testing.T) { sharedtestvalues.SkipTestIfCredentialsUnset(t, bi, canManipulateRealOrders) resp, err := bi.GetOngoingLoans(context.Background(), 0, "", "") require.NoError(t, err) - if len(resp.Data) == 0 { + if len(resp) == 0 { t.Skip(skipInsufficientOrders) } - _, err = bi.RepayLoan(context.Background(), resp.Data[0].OrderID, testAmount, false, false) + _, err = bi.RepayLoan(context.Background(), resp[0].OrderID, testAmount, false, false) assert.NoError(t, err) - _, err = bi.RepayLoan(context.Background(), resp.Data[0].OrderID, 0, true, true) + _, err = bi.RepayLoan(context.Background(), resp[0].OrderID, 0, true, true) assert.NoError(t, err) } func TestModifyFuturesOrder(t *testing.T) { @@ -3085,8 +2933,7 @@ func TestModifyFuturesOrder(t *testing.T) { assert.ErrorIs(t, err, errNewClientOrderIDEmpty) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi, canManipulateRealOrders) oID := getFuturesOrdIDHelper(t, true, true) - _, err = bi.ModifyFuturesOrder(context.Background(), oID.OrderID, oID.ClientOrderID, testPair2.String(), - testFiat2.String()+"-FUTURES", clientIDGenerator(), 0, 0, testPrice2+1, testPrice2/10) + _, err = bi.ModifyFuturesOrder(context.Background(), int64(oID.OrderID), oID.ClientOrderID, testPair2.String(), testFiat2.String()+"-FUTURES", clientIDGenerator(), 0, 0, testPrice2+1, testPrice2/10) assert.NoError(t, err) } @@ -3099,8 +2946,7 @@ func TestCancelFuturesOrder(t *testing.T) { assert.ErrorIs(t, err, errOrderClientEmpty) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi, canManipulateRealOrders) oID := getFuturesOrdIDHelper(t, true, true) - _, err = bi.CancelFuturesOrder(context.Background(), testPair2.String(), testFiat2.String()+"-FUTURES", "", - "", oID.OrderID) + _, err = bi.CancelFuturesOrder(context.Background(), testPair2.String(), testFiat2.String()+"-FUTURES", "", "", int64(oID.OrderID)) assert.NoError(t, err) } @@ -3114,8 +2960,7 @@ func TestBatchCancelFuturesOrders(t *testing.T) { OrderID: oID.OrderID, }, } - _, err = bi.BatchCancelFuturesOrders(context.Background(), orders, testPair2.String(), - testFiat2.String()+"-FUTURES", "") + _, err = bi.BatchCancelFuturesOrders(context.Background(), orders, testPair2.String(), testFiat2.String()+"-FUTURES", "") assert.NoError(t, err) } @@ -3131,8 +2976,7 @@ func TestCancelAllFuturesOrders(t *testing.T) { _, err := bi.CancelAllFuturesOrders(context.Background(), "", "", "", 0) assert.ErrorIs(t, err, errProductTypeEmpty) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi, canManipulateRealOrders) - _, err = bi.CancelAllFuturesOrders(context.Background(), "", testFiat2.String()+"-FUTURES", testFiat2.String(), - time.Second*60) + _, err = bi.CancelAllFuturesOrders(context.Background(), "", testFiat2.String()+"-FUTURES", testFiat2.String(), time.Second*60) assert.NoError(t, err) } @@ -3165,14 +3009,14 @@ func TestCancelOrder(t *testing.T) { err = bi.CancelOrder(context.Background(), ord) assert.NoError(t, err) oID := getFuturesOrdIDHelper(t, true, true) - ord.OrderID = strconv.FormatInt(oID.OrderID, 10) + ord.OrderID = strconv.FormatInt(int64(oID.OrderID), 10) ord.Pair = testPair2 ord.AssetType = asset.Futures ord.ClientOrderID = oID.ClientOrderID err = bi.CancelOrder(context.Background(), ord) assert.NoError(t, err) oID = getIsoOrdIDHelper(t, true) - ord.OrderID = strconv.FormatInt(oID.OrderID, 10) + ord.OrderID = strconv.FormatInt(int64(oID.OrderID), 10) ord.AssetType = asset.CrossMargin ord.ClientOrderID = oID.ClientOrderID err = bi.CancelOrder(context.Background(), ord) @@ -3205,7 +3049,7 @@ func TestCancelCrossOrder(t *testing.T) { assert.ErrorIs(t, err, errOrderClientEmpty) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi, canManipulateRealOrders) oID := getCrossOrdIDHelper(t, true) - _, err = bi.CancelCrossOrder(context.Background(), testPair.String(), oID.ClientOrderID, oID.OrderID) + _, err = bi.CancelCrossOrder(context.Background(), testPair.String(), oID.ClientOrderID, int64(oID.OrderID)) assert.NoError(t, err) } @@ -3246,7 +3090,7 @@ func TestCancelBatchOrders(t *testing.T) { if oID.ClientOrderID != ordersNotFound { orders = append(orders, order.Cancel{ AssetType: asset.Futures, - OrderID: strconv.FormatInt(oID.OrderID, 10), + OrderID: strconv.FormatInt(int64(oID.OrderID), 10), ClientOrderID: oID.ClientOrderID, Pair: testPair2, }) @@ -3255,7 +3099,7 @@ func TestCancelBatchOrders(t *testing.T) { if oID.ClientOrderID != ordersNotFound { orders = append(orders, order.Cancel{ AssetType: asset.Margin, - OrderID: strconv.FormatInt(oID.OrderID, 10), + OrderID: strconv.FormatInt(int64(oID.OrderID), 10), ClientOrderID: oID.ClientOrderID, Pair: testPair2, }) @@ -3264,7 +3108,7 @@ func TestCancelBatchOrders(t *testing.T) { if oID.ClientOrderID != ordersNotFound { orders = append(orders, order.Cancel{ AssetType: asset.CrossMargin, - OrderID: strconv.FormatInt(oID.OrderID, 10), + OrderID: strconv.FormatInt(int64(oID.OrderID), 10), ClientOrderID: oID.ClientOrderID, Pair: testPair2, }) @@ -3282,7 +3126,7 @@ func TestCancelIsolatedOrder(t *testing.T) { assert.ErrorIs(t, err, errOrderClientEmpty) sharedtestvalues.SkipTestIfCredentialsUnset(t, bi, canManipulateRealOrders) oID := getIsoOrdIDHelper(t, true) - _, err = bi.CancelIsolatedOrder(context.Background(), testPair2.String(), oID.ClientOrderID, oID.OrderID) + _, err = bi.CancelIsolatedOrder(context.Background(), testPair2.String(), oID.ClientOrderID, int64(oID.OrderID)) assert.NoError(t, err) } @@ -3298,9 +3142,7 @@ func TestBatchCancelIsolatedOrders(t *testing.T) { } type getNoArgsResp interface { - *TimeResp | *P2PMerInfoResp | []ConvertCoinsResp | []BGBConvertCoinsResp | []VIPFeeRateResp | []SupCurrencyResp | - float64 | *SavingsBalance | *SharkFinBalance | *DebtsResp | []AssetOverviewResp | string | - *SymbolsResp | []SubaccountAssetsResp | []exchange.FundingHistory + *TimeResp | *P2PMerInfoResp | []ConvertCoinsResp | []BGBConvertCoinsResp | []VIPFeeRateResp | []SupCurrencyResp | float64 | *SavingsBalance | *SharkFinBalance | *DebtsResp | []AssetOverviewResp | string | *SymbolsResp | []SubaccountAssetsResp | []exchange.FundingHistory } type getNoArgsAssertNotEmpty[G getNoArgsResp] func(context.Context) (G, error) @@ -3312,20 +3154,11 @@ func testGetNoArgs[G getNoArgsResp](t *testing.T, f getNoArgsAssertNotEmpty[G]) } type getOneArgResp interface { - []WhaleNetFlowResp | *FundFlowResp | []WhaleFundFlowResp | *CrVirSubResp | []GetAPIKeyResp | []FundingAssetsResp | - []BotAccAssetsResp | []ConvertBGBResp | []CoinInfoResp | []SymbolInfoResp | []TickerResp | string | - *SubOrderResp | *BatchOrderResp | bool | []FutureTickerResp | []FutureAccDetails | []SubaccountFuturesResp | - []CrossAssetResp | *MaxBorrowCross | *MaxTransferCross | []IntRateMaxBorrowCross | []TierConfigCross | - *FlashRepayCross | *IsoAssetResp | *IntRateMaxBorrowIso | *TierConfigIso | *MaxBorrowIso | *MaxTransferIso | - *FlashRepayIso | *EarnAssets | *LoanCurList | currency.Pairs | time.Time | []futures.Contract | - []fundingrate.LatestRateResponse | []string | *margin.RateHistoryResponse | *fundingrate.HistoricalRates | - []futures.PositionResponse | *withdraw.ExchangeResponse | collateral.Mode | *margin.PositionChangeResponse + []WhaleNetFlowResp | *FundFlowResp | []WhaleFundFlowResp | *CrVirSubResp | []GetAPIKeyResp | []FundingAssetsResp | []BotAccAssetsResp | []ConvertBGBResp | []CoinInfoResp | []SymbolInfoResp | []TickerResp | string | *SubOrderResp | *BatchOrderResp | bool | []FutureTickerResp | []FutureAccDetails | []SubaccountFuturesResp | []CrossAssetResp | *MaxBorrowCross | *MaxTransferCross | []IntRateMaxBorrowCross | []TierConfigCross | *FlashRepayCross | []IsoAssetResp | []IntRateMaxBorrowIso | []TierConfigIso | *MaxBorrowIso | *MaxTransferIso | []FlashRepayIso | []EarnAssets | *LoanCurList | currency.Pairs | time.Time | []futures.Contract | []fundingrate.LatestRateResponse | []string | *margin.RateHistoryResponse | *fundingrate.HistoricalRates | []futures.PositionResponse | *withdraw.ExchangeResponse | collateral.Mode | *margin.PositionChangeResponse } type getOneArgParam interface { - string | []string | bool | asset.Item | *fundingrate.LatestRateRequest | currency.Code | *margin.RateHistoryRequest | - *fundingrate.HistoricalRatesRequest | *futures.PositionsRequest | *withdraw.Request | - *margin.PositionChangeRequest + string | []string | bool | asset.Item | *fundingrate.LatestRateRequest | currency.Code | *margin.RateHistoryRequest | *fundingrate.HistoricalRatesRequest | *futures.PositionsRequest | *withdraw.Request | *margin.PositionChangeRequest } type getOneArgGen[R getOneArgResp, P getOneArgParam] func(context.Context, P) (R, error) @@ -3347,8 +3180,7 @@ func testGetOneArg[R getOneArgResp, P getOneArgParam](t *testing.T, f getOneArgG } type getTwoArgsResp interface { - []FutureTickerResp | *OpenPositionsResp | []FundingTimeResp | []FuturesPriceResp | []FundingCurrentResp | - []ContractConfigResp + []FutureTickerResp | *OpenPositionsResp | []FundingTimeResp | []FuturesPriceResp | []FundingCurrentResp | []ContractConfigResp } type getTwoArgsPairProduct[G getTwoArgsResp] func(context.Context, string, string) (G, error) @@ -3389,14 +3221,12 @@ func subAccTestHelper(t *testing.T, compString, ignoreString string) string { func getPlanOrdIDHelper(t *testing.T, mustBeTriggered bool) *OrderIDStruct { t.Helper() ordIDs := new(OrderIDStruct) - resp, err := bi.GetCurrentSpotPlanOrders(context.Background(), testPair.String(), time.Time{}, time.Time{}, 100, - 1<<62) + resp, err := bi.GetCurrentSpotPlanOrders(context.Background(), testPair.String(), time.Time{}, time.Time{}, 100, 1<<62) if err == nil && len(resp.OrderList) != 0 { for i := range resp.OrderList { - if resp.OrderList[i].ClientOrderID == url.QueryEscape(resp.OrderList[i].ClientOrderID) && - !(mustBeTriggered && resp.OrderList[i].Status == "not_trigger") { + if resp.OrderList[i].ClientOrderID == url.QueryEscape(resp.OrderList[i].ClientOrderID) && !(mustBeTriggered && resp.OrderList[i].Status == "not_trigger") { ordIDs.ClientOrderID = resp.OrderList[i].ClientOrderID - ordIDs.OrderID = resp.OrderList[i].OrderID + ordIDs.OrderID = EmptyInt(resp.OrderList[i].OrderID) } } } @@ -3408,25 +3238,23 @@ func getPlanOrdIDHelper(t *testing.T, mustBeTriggered bool) *OrderIDStruct { func getFuturesOrdIDHelper(t *testing.T, live, skip bool) *OrderIDStruct { t.Helper() - resp, err := bi.GetPendingFuturesOrders(context.Background(), 0, 1<<62, 5, "", testPair2.String(), - testFiat2.String()+"-FUTURES", "", time.Now().Add(-time.Hour*24*90), time.Now()) + resp, err := bi.GetPendingFuturesOrders(context.Background(), 0, 1<<62, 5, "", testPair2.String(), testFiat2.String()+"-FUTURES", "", time.Now().Add(-time.Hour*24*90), time.Now()) assert.NoError(t, err) if resp != nil { if len(resp.EntrustedList) != 0 { return &OrderIDStruct{ - OrderID: resp.EntrustedList[0].OrderID, + OrderID: EmptyInt(resp.EntrustedList[0].OrderID), ClientOrderID: resp.EntrustedList[0].ClientOrderID, } } } if !live { - resp, err := bi.GetHistoricalFuturesOrders(context.Background(), 0, 1<<62, 5, "", testPair2.String(), - testFiat2.String()+"-FUTURES", time.Time{}, time.Time{}) + resp, err := bi.GetHistoricalFuturesOrders(context.Background(), 0, 1<<62, 5, "", testPair2.String(), testFiat2.String()+"-FUTURES", time.Time{}, time.Time{}) assert.NoError(t, err) if resp != nil { if len(resp.EntrustedList) != 0 { return &OrderIDStruct{ - OrderID: resp.EntrustedList[0].OrderID, + OrderID: EmptyInt(resp.EntrustedList[0].OrderID), ClientOrderID: resp.EntrustedList[0].ClientOrderID, } } @@ -3444,13 +3272,12 @@ func getFuturesOrdIDHelper(t *testing.T, live, skip bool) *OrderIDStruct { func getTrigOrdIDHelper(t *testing.T, planTypes []string) *OrderIDStruct { t.Helper() for i := range planTypes { - resp, err := bi.GetPendingTriggerFuturesOrders(context.Background(), 0, 1<<62, 5, "", testPair2.String(), - planTypes[i], testFiat2.String()+"-FUTURES", time.Time{}, time.Time{}) + resp, err := bi.GetPendingTriggerFuturesOrders(context.Background(), 0, 1<<62, 5, "", testPair2.String(), planTypes[i], testFiat2.String()+"-FUTURES", time.Time{}, time.Time{}) assert.NoError(t, err) if resp != nil { if len(resp.EntrustedList) != 0 { return &OrderIDStruct{ - OrderID: resp.EntrustedList[0].OrderID, + OrderID: EmptyInt(resp.EntrustedList[0].OrderID), ClientOrderID: resp.EntrustedList[0].ClientOrderID, } } @@ -3465,12 +3292,11 @@ func getTrigOrdIDHelper(t *testing.T, planTypes []string) *OrderIDStruct { func getCrossOrdIDHelper(t *testing.T, skip bool) *OrderIDStruct { t.Helper() - resp, err := bi.GetCrossOpenOrders(context.Background(), testPair.String(), "", 0, 5, 1<<62, - time.Now().Add(-time.Hour*24*85), time.Time{}) + resp, err := bi.GetCrossOpenOrders(context.Background(), testPair.String(), "", 0, 5, 1<<62, time.Now().Add(-time.Hour*24*85), time.Time{}) require.NoError(t, err) if len(resp.OrderList) != 0 { return &OrderIDStruct{ - OrderID: resp.OrderList[0].OrderID, + OrderID: EmptyInt(resp.OrderList[0].OrderID), ClientOrderID: resp.OrderList[0].ClientOrderID, } } @@ -3485,12 +3311,11 @@ func getCrossOrdIDHelper(t *testing.T, skip bool) *OrderIDStruct { func getIsoOrdIDHelper(t *testing.T, skip bool) *OrderIDStruct { t.Helper() - resp, err := bi.GetIsolatedOpenOrders(context.Background(), testPair.String(), "", 0, 5, 1<<62, - time.Now().Add(-time.Hour*24*85), time.Time{}) + resp, err := bi.GetIsolatedOpenOrders(context.Background(), testPair.String(), "", 0, 5, 1<<62, time.Now().Add(-time.Hour*24*85), time.Time{}) require.NoError(t, err) if len(resp.OrderList) != 0 { return &OrderIDStruct{ - OrderID: resp.OrderList[0].OrderID, + OrderID: EmptyInt(resp.OrderList[0].OrderID), ClientOrderID: resp.OrderList[0].ClientOrderID, } } diff --git a/exchanges/bitget/bitget_types.go b/exchanges/bitget/bitget_types.go index 4700cdcaf3d..9af2b5d3fb7 100644 --- a/exchanges/bitget/bitget_types.go +++ b/exchanges/bitget/bitget_types.go @@ -84,25 +84,28 @@ type P2PTrResp struct { Timestamp UnixTimestamp `json:"ts"` } +// MerchantList is a sub-struct holding information on P2P merchants +type MerchantList struct { + RegisterTime UnixTimestamp `json:"registerTime"` + NickName string `json:"nickName"` + IsOnline string `json:"isOnline"` + MerchantID int64 `json:"merchantId,string"` + AvgPaymentTime int64 `json:"avgPaymentTime,string"` + AvgReleaseTime int64 `json:"avgReleaseTime,string"` + TotalTrades int64 `json:"totalTrades,string"` + TotalBuy int64 `json:"totalBuy,string"` + TotalSell int64 `json:"totalSell,string"` + TotalCompletionRate float64 `json:"totalCompletionRate,string"` + Trades30D int64 `json:"trades30d,string"` + Sell30D float64 `json:"sell30d,string"` + Buy30D float64 `json:"buy30d,string"` + CompletionRate30D float64 `json:"completionRate30d,string"` +} + // P2PMerResp holds information on P2P merchant lists type P2PMerListResp struct { - MerchantList []struct { - RegisterTime UnixTimestamp `json:"registerTime"` - NickName string `json:"nickName"` - IsOnline string `json:"isOnline"` - MerchantID int64 `json:"merchantId,string"` - AvgPaymentTime int64 `json:"avgPaymentTime,string"` - AvgReleaseTime int64 `json:"avgReleaseTime,string"` - TotalTrades int64 `json:"totalTrades,string"` - TotalBuy int64 `json:"totalBuy,string"` - TotalSell int64 `json:"totalSell,string"` - TotalCompletionRate float64 `json:"totalCompletionRate,string"` - Trades30D int64 `json:"trades30d,string"` - Sell30D float64 `json:"sell30d,string"` - Buy30D float64 `json:"buy30d,string"` - CompletionRate30D float64 `json:"completionRate30d,string"` - } `json:"merchantList"` - MinMerchantID int64 `json:"minMerchantId,string"` + MerchantList []MerchantList `json:"merchantList"` + MinMerchantID int64 `json:"minMerchantId,string"` } // YesNoBool is a type used to unmarshal strings that are either "yes" or "no" into bools @@ -130,85 +133,106 @@ type P2PMerInfoResp struct { Mobile string `json:"mobile"` } +// PayMethodInfo is a sub-struct holding information on P2P payment methods +type PayMethodInfo struct { + Name string `json:"name"` + Required YesNoBool `json:"required"` + Type string `json:"type"` + Value string `json:"value"` +} + +// PaymentInfo is a sub-struct holding information on P2P payment methods +type PaymentInfo struct { + PayMethodName string `json:"paymethodName"` + PayMethodID string `json:"paymethodId"` + PayMethodInfo []PayMethodInfo `json:"paymethodInfo"` +} + +// P2POrderList is a sub-struct holding information on P2P orders +type P2POrderList struct { + OrderID int64 `json:"orderId,string"` + OrderNum int64 `json:"orderNo,string"` + AdvNum int64 `json:"advNo,string"` + Side string `json:"side"` + Count float64 `json:"count,string"` + FiatCurrency string `json:"fiat"` + CryptoCurrency string `json:"coin"` + Price float64 `json:"price,string"` + WithdrawTime UnixTimestamp `json:"withdrawTime"` + RepresentTime UnixTimestamp `json:"representTime"` + ReleaseTime UnixTimestamp `json:"releaseTime"` + PaymentTime UnixTimestamp `json:"paymentTime"` + Amount float64 `json:"amount,string"` + Status string `json:"status"` + BuyerRealName string `json:"buyerRealName"` + SellerRealName string `json:"sellerRealName"` + CreationTime UnixTimestamp `json:"ctime"` + UpdateTime UnixTimestamp `json:"utime"` + PaymentInfo PaymentInfo `json:"paymentInfo"` +} + // P2POrdersResp holds information on P2P orders type P2POrdersResp struct { - OrderList []struct { - OrderID int64 `json:"orderId,string"` - OrderNum int64 `json:"orderNo,string"` - AdvNum int64 `json:"advNo,string"` - Side string `json:"side"` - Count float64 `json:"count,string"` - FiatCurrency string `json:"fiat"` - CryptoCurrency string `json:"coin"` - Price float64 `json:"price,string"` - WithdrawTime UnixTimestamp `json:"withdrawTime"` - RepresentTime UnixTimestamp `json:"representTime"` - ReleaseTime UnixTimestamp `json:"releaseTime"` - PaymentTime UnixTimestamp `json:"paymentTime"` - Amount float64 `json:"amount,string"` - Status string `json:"status"` - BuyerRealName string `json:"buyerRealName"` - SellerRealName string `json:"sellerRealName"` - CreationTime UnixTimestamp `json:"ctime"` - UpdateTime UnixTimestamp `json:"utime"` - PaymentInfo struct { - PayMethodName string `json:"paymethodName"` - PayMethodID string `json:"paymethodId"` - PayMethodInfo []struct { - Name string `json:"name"` - Required YesNoBool `json:"required"` - Type string `json:"type"` - Value string `json:"value"` - } `json:"paymethodInfo"` - } `json:"paymentInfo"` - } `json:"orderList"` - MinOrderID int64 `json:"minOrderId,string"` + OrderList []P2POrderList `json:"orderList"` + MinOrderID int64 `json:"minOrderId,string"` +} + +// UserLimitList is a sub-struct holding information on P2P user limits +type UserLimitList struct { + MinCompleteNum int64 `json:"minCompleteNum,string"` + MaxCompleteNum int64 `json:"maxCompleteNum,string"` + PlaceOrderNum int64 `json:"placeOrderNum,string"` + AllowMerchantPlace YesNoBool `json:"allowMerchantPlace"` + CompleteRate30D float64 `json:"completeRate30d,string"` + Country string `json:"country"` +} + +// ReqNameType is a sub-struct holding information on P2P payment methods +type ReqNameType struct { + Required bool `json:"required"` + Name string `json:"name"` + Type string `json:"type"` +} + +// PaymentMethodList is a sub-struct holding information on P2P payment methods +type PaymentMethodList struct { + PaymentMethod string `json:"paymentMethod"` + PaymentID int64 `json:"paymentId,string"` + PaymentInfo []ReqNameType `json:"paymentInfo"` +} + +// MerchantCertifiedList is a sub-struct holding information on P2P merchant certifications +type MerchantCertifiedList struct { + ImageURL string `json:"imageUrl"` + Desc string `json:"desc"` } // P2PAdListResp holds information on P2P advertisements type P2PAdListResp struct { - AdID int64 `json:"adId,string"` - AdvNum int64 `json:"advNo,string"` - Side string `json:"side"` - AdSize float64 `json:"adSize,string"` - Size float64 `json:"size,string"` - CryptoCurrency string `json:"coin"` - Price float64 `json:"price,string"` - CryptoPrecision uint8 `json:"coinPrecision,string"` - FiatCurrency string `json:"fiat"` - FiatPrecision uint8 `json:"fiatPrecision,string"` - FiatSymbol string `json:"fiatSymbol"` - Status string `json:"status"` - Hide YesNoBool `json:"hide"` - MaxTradeAmount float64 `json:"maxTradeAmount,string"` - MinTradeAmount float64 `json:"minTradeAmount,string"` - PayDuration int64 `json:"payDuration,string"` - TurnoverNum int64 `json:"turnoverNum,string"` - TurnoverRate float64 `json:"turnoverRate,string"` - Label string `json:"label"` - CreationTime UnixTimestamp `json:"ctime"` - UpdateTime UnixTimestamp `json:"utime"` - UserLimitList struct { - MinCompleteNum int64 `json:"minCompleteNum,string"` - MaxCompleteNum int64 `json:"maxCompleteNum,string"` - PlaceOrderNum int64 `json:"placeOrderNum,string"` - AllowMerchantPlace YesNoBool `json:"allowMerchantPlace"` - CompleteRate30D float64 `json:"completeRate30d,string"` - Country string `json:"country"` - } `json:"userLimitList"` - PaymentMethodList []struct { - PaymentMethod string `json:"paymentMethod"` - PaymentID int64 `json:"paymentId,string"` - PaymentInfo []struct { - Required bool `json:"required"` - Name string `json:"name"` - Type string `json:"type"` - } `json:"paymentInfo"` - } `json:"paymentMethodList"` - MerchantCertifiedList []struct { - ImageURL string `json:"imageUrl"` - Desc string `json:"desc"` - } `json:"merchantCertifiedList"` + AdID int64 `json:"adId,string"` + AdvNum int64 `json:"advNo,string"` + Side string `json:"side"` + AdSize float64 `json:"adSize,string"` + Size float64 `json:"size,string"` + CryptoCurrency string `json:"coin"` + Price float64 `json:"price,string"` + CryptoPrecision uint8 `json:"coinPrecision,string"` + FiatCurrency string `json:"fiat"` + FiatPrecision uint8 `json:"fiatPrecision,string"` + FiatSymbol string `json:"fiatSymbol"` + Status string `json:"status"` + Hide YesNoBool `json:"hide"` + MaxTradeAmount float64 `json:"maxTradeAmount,string"` + MinTradeAmount float64 `json:"minTradeAmount,string"` + PayDuration int64 `json:"payDuration,string"` + TurnoverNum int64 `json:"turnoverNum,string"` + TurnoverRate float64 `json:"turnoverRate,string"` + Label string `json:"label"` + CreationTime UnixTimestamp `json:"ctime"` + UpdateTime UnixTimestamp `json:"utime"` + UserLimitList UserLimitList `json:"userLimitList"` + PaymentMethodList []PaymentMethodList `json:"paymentMethodList"` + MerchantCertifiedList []MerchantCertifiedList `json:"merchantCertifiedList"` } // WhaleNetFlowResp holds information on whale trading volumes @@ -303,20 +327,26 @@ type AccountRatioResp struct { Timestamp UnixTimestamp `json:"ts"` } +// FailureList is a sub-struct holding information on failures +type FailureList struct { + SubaccountName string `json:"subaAccountName"` +} + +// SuccessList is a sub-struct holding information on successes +type SuccessList struct { + SubaccountUID string `json:"subAccountUid"` + SubaccountName string `json:"subaAccountName"` + Status string `json:"status"` + PermList []string `json:"permList"` + Label string `json:"label"` + CreationTime UnixTimestamp `json:"cTime"` + UpdateTime UnixTimestamp `json:"uTime"` +} + // CrVirSubResp contains information returned when creating virtual sub-accounts type CrVirSubResp struct { - FailureList []struct { - SubaccountName string `json:"subaAccountName"` - } `json:"failureList"` - SuccessList []struct { - SubaccountUID string `json:"subAccountUid"` - SubaccountName string `json:"subaAccountName"` - Status string `json:"status"` - PermList []string `json:"permList"` - Label string `json:"label"` - CreationTime UnixTimestamp `json:"cTime"` - UpdateTime UnixTimestamp `json:"uTime"` - } `json:"successList"` + FailureList []FailureList `json:"failureList"` + SuccessList []SuccessList `json:"successList"` } // SuccessBool is a type used to unmarshal strings that are either "success" or "failure" into bools @@ -334,18 +364,21 @@ type CrSubAccAPIKeyResp struct { IPList []string `json:"ipList"` } +// SubaccountList is a sub-struct holding information on sub-accounts +type SubaccountList struct { + SubaccountUID string `json:"subAccountUid"` + SubaccountName string `json:"subAccountName"` + Label string `json:"label"` + Status string `json:"status"` + PermList []string `json:"permList"` + CreationTime UnixTimestamp `json:"cTime"` + UpdateTime UnixTimestamp `json:"uTime"` +} + // GetVirSubResp contains information on the user's virtual sub-accounts type GetVirSubResp struct { - SubaccountList []struct { - SubaccountUID string `json:"subAccountUid"` - SubaccountName string `json:"subAccountName"` - Label string `json:"label"` - Status string `json:"status"` - PermList []string `json:"permList"` - CreationTime UnixTimestamp `json:"cTime"` - UpdateTime UnixTimestamp `json:"uTime"` - } `json:"subAccountList"` - EndID int64 `json:"endId,string"` + SubaccountList []SubaccountList `json:"subAccountList"` + EndID int64 `json:"endId,string"` } // AlterAPIKeyResp contains information returned when creating or modifying an API key @@ -418,33 +451,39 @@ type CommitConvResp struct { Timestamp UnixTimestamp `json:"ts"` } +// DataList is a sub-struct holding information on the user's conversion history +type DataList struct { + ID int64 `json:"id,string"` + Timestamp UnixTimestamp `json:"ts"` + ConvertPrice float64 `json:"cnvtPrice,string"` + Fee float64 `json:"fee,string"` + FromCoinSize float64 `json:"fromCoinSize,string"` + FromCoin string `json:"fromCoin"` + ToCoinSize float64 `json:"toCoinSize,string"` + ToCoin string `json:"toCoin"` +} + // ConvHistResp contains information on the user's conversion history type ConvHistResp struct { - DataList []struct { - ID int64 `json:"id,string"` - Timestamp UnixTimestamp `json:"ts"` - ConvertPrice float64 `json:"cnvtPrice,string"` - Fee float64 `json:"fee,string"` - FromCoinSize float64 `json:"fromCoinSize,string"` - FromCoin string `json:"fromCoin"` - ToCoinSize float64 `json:"toCoinSize,string"` - ToCoin string `json:"toCoin"` - } `json:"dataList"` - EndID int64 `json:"endId,string"` + DataList []DataList `json:"dataList"` + EndID int64 `json:"endId,string"` +} + +// FeeAndRate is a sub-struct holding information on fees +type FeeAndRate struct { + FeeRate float64 `json:"feeRate,string"` + Fee float64 `json:"fee,string"` } // BGBConvertCoinsResp contains information on the user's available currencies and conversions between those // and BGB type BGBConvertCoinsResp struct { - Coin string `json:"coin"` - Available float64 `json:"available,string"` - BGBEstAmount float64 `json:"bgbEstAmount,string"` - Precision uint8 `json:"precision"` - FeeDetail []struct { - FeeRate float64 `json:"feeRate,string"` - Fee float64 `json:"fee,string"` - } `json:"feeDetail"` - CurrentTime UnixTimestamp `json:"cTime"` + Coin string `json:"coin"` + Available float64 `json:"available,string"` + BGBEstAmount float64 `json:"bgbEstAmount,string"` + Precision uint8 `json:"precision"` + FeeDetail []FeeAndRate `json:"feeDetail"` + CurrentTime UnixTimestamp `json:"cTime"` } // ConvertBGBResp contains information on a series of conversions between BGB and other currencies @@ -453,43 +492,49 @@ type ConvertBGBResp struct { OrderID int64 `json:"orderId,string"` } +// FeeAndCoin is a sub-struct holding information on fees +type FeeAndCoin struct { + FeeCoin string `json:"feeCoin"` + Fee float64 `json:"fee,string"` +} + // BGBConvHistResp contains information on the user's conversion history between BGB and other currencies type BGBConvHistResp struct { - OrderID int64 `json:"orderId,string"` - FromCoin string `json:"fromCoin"` - FromAmount float64 `json:"fromAmount,string"` - FromCoinPrice float64 `json:"fromCoinPrice,string"` - ToCoin string `json:"toCoin"` - ToAmount float64 `json:"toAmount,string"` - ToCoinPrice float64 `json:"toCoinPrice,string"` - FeeDetail struct { - FeeCoin string `json:"feeCoin"` - Fee float64 `json:"fee,string"` - } `json:"feeDetail"` - Status SuccessBool `json:"status"` - CreationTime UnixTimestamp `json:"cTime"` + OrderID int64 `json:"orderId,string"` + FromCoin string `json:"fromCoin"` + FromAmount float64 `json:"fromAmount,string"` + FromCoinPrice float64 `json:"fromCoinPrice,string"` + ToCoin string `json:"toCoin"` + ToAmount float64 `json:"toAmount,string"` + ToCoinPrice float64 `json:"toCoinPrice,string"` + FeeDetail FeeAndCoin `json:"feeDetail"` + Status SuccessBool `json:"status"` + CreationTime UnixTimestamp `json:"cTime"` +} + +// ChainInfo is a sub-struct containing information on supported chains for a currency +type ChainInfo struct { + Chain string `json:"chain"` + NeedTag bool `json:"needTag,string"` + Withdrawable bool `json:"withdrawable,string"` + Rechargeable bool `json:"rechargeable,string"` + WithdrawFee float64 `json:"withdrawFee,string"` + ExtraWithdrawFee float64 `json:"extraWithdrawFee,string"` + DepositConfirm uint16 `json:"depositConfirm,string"` + WithdrawConfirm uint16 `json:"withdrawConfirm,string"` + MinDepositAmount float64 `json:"minDepositAmount,string"` + MinWithdrawAmount float64 `json:"minWithdrawAmount,string"` + BrowserURL string `json:"browserUrl"` + ContractAddress string `json:"contractAddress"` + WithdrawStep uint8 `json:"withdrawStep,string"` } // CoinInfoResp contains information on supported spot currencies type CoinInfoResp struct { - CoinID uint32 `json:"coinId,string"` - Coin string `json:"coin"` - Transfer bool `json:"transfer,string"` - Chains []struct { - Chain string `json:"chain"` - NeedTag bool `json:"needTag,string"` - Withdrawable bool `json:"withdrawable,string"` - Rechargeable bool `json:"rechargeable,string"` - WithdrawFee float64 `json:"withdrawFee,string"` - ExtraWithdrawFee float64 `json:"extraWithdrawFee,string"` - DepositConfirm uint16 `json:"depositConfirm,string"` - WithdrawConfirm uint16 `json:"withdrawConfirm,string"` - MinDepositAmount float64 `json:"minDepositAmount,string"` - MinWithdrawAmount float64 `json:"minWithdrawAmount,string"` - BrowserURL string `json:"browserUrl"` - ContractAddress string `json:"contractAddress"` - WithdrawStep uint8 `json:"withdrawStep,string"` - } `json:"chains"` + CoinID uint32 `json:"coinId,string"` + Coin string `json:"coin"` + Transfer bool `json:"transfer,string"` + Chains []ChainInfo `json:"chains"` } // SymbolInfoResp contains information on supported spot trading pairs @@ -616,24 +661,24 @@ type PlaceSpotOrderStruct struct { // EmptyInt is a type used to unmarshal empty string into 0, and numbers encoded as strings into int64 type EmptyInt int64 +// OrderIDAndError is a sub-struct containing information on an order ID and any errors associated with it +type OrderIDAndError struct { + OrderID EmptyInt `json:"orderId"` + ClientOrderID string `json:"clientOid"` + ErrorCode int64 `json:"errorCode,string"` + ErrorMessage string `json:"errorMsg"` +} + // BatchOrderResp contains information on the success or failure of a batch of orders to place or cancel type BatchOrderResp struct { - SuccessList []struct { - OrderID EmptyInt `json:"orderId"` - ClientOrderID string `json:"clientOid"` - } `json:"successList"` - FailureList []struct { - OrderID EmptyInt `json:"orderId"` - ClientOrderID string `json:"clientOid"` - ErrorCode int64 `json:"errorCode,string"` - ErrorMessage string `json:"errorMsg"` - } `json:"failureList"` + SuccessList []OrderIDStruct `json:"successList"` + FailureList []OrderIDAndError `json:"failureList"` } // OrderIDStruct contains order IDs type OrderIDStruct struct { - OrderID int64 `json:"orderId,string,omitempty"` - ClientOrderID string `json:"clientOid,omitempty"` + OrderID EmptyInt `json:"orderId,string,omitempty"` + ClientOrderID string `json:"clientOid,omitempty"` } // OrderDetailTemp contains information on an order in a partially-unmarshalled state @@ -743,26 +788,29 @@ type OrderIDResp struct { Data OrderIDStruct `json:"data"` } +// PlanSpotOrder is a sub-struct that contains information on a planned order +type PlanSpotOrder struct { + OrderID int64 `json:"orderId,string"` + ClientOrderID string `json:"clientOid"` + Symbol string `json:"symbol"` + TriggerPrice float64 `json:"triggerPrice,string"` + OrderType string `json:"orderType"` + ExecutePrice types.Number `json:"executePrice"` + PlanType string `json:"planType"` + Size float64 `json:"size,string"` + Status string `json:"status"` + Side string `json:"side"` + TriggerType string `json:"triggerType"` + EnterPointSource string `json:"enterPointSource"` + CreationTime UnixTimestamp `json:"cTime"` + UpdateTime UnixTimestamp `json:"uTime"` +} + // PlanSpotOrderResp contains information on plan orders type PlanSpotOrderResp struct { - NextFlag bool `json:"nextFlag"` - IDLessThan EmptyInt `json:"idLessThan"` - OrderList []struct { - OrderID int64 `json:"orderId,string"` - ClientOrderID string `json:"clientOid"` - Symbol string `json:"symbol"` - TriggerPrice float64 `json:"triggerPrice,string"` - OrderType string `json:"orderType"` - ExecutePrice types.Number `json:"executePrice"` - PlanType string `json:"planType"` - Size float64 `json:"size,string"` - Status string `json:"status"` - Side string `json:"side"` - TriggerType string `json:"triggerType"` - EnterPointSource string `json:"enterPointSource"` - CreationTime UnixTimestamp `json:"cTime"` - UpdateTime UnixTimestamp `json:"uTime"` - } `json:"orderList"` + NextFlag bool `json:"nextFlag"` + IDLessThan EmptyInt `json:"idLessThan"` + OrderList []PlanSpotOrder `json:"orderList"` } // SubOrderResp contains information on sub-orders @@ -953,13 +1001,16 @@ const ( CallModeMark ) +// OpenInterestList is a sub-struct containing information on open interest +type OpenInterestList struct { + Symbol string `json:"symbol"` + Size float64 `json:"size,string"` +} + // OpenPositionResp contains information on open positions type OpenPositionsResp struct { - OpenInterestList []struct { - Symbol string `json:"symbol"` - Size float64 `json:"size,string"` - } `json:"openInterestList"` - Timestamp UnixTimestamp `json:"ts"` + OpenInterestList []OpenInterestList `json:"openInterestList"` + Timestamp UnixTimestamp `json:"ts"` } // FundingTimeResp contains information on funding times @@ -1130,26 +1181,29 @@ type PositionResp struct { CreationTime UnixTimestamp `json:"cTime"` } +// HistPositions is a sub-struct containing information on historical positions +type HistPositions struct { + MarginCoin string `json:"marginCoin"` + Symbol string `json:"symbol"` + HoldSide string `json:"holdSide"` + OpenAveragePrice float64 `json:"openAvgPrice,string"` + CloseAveragePrice float64 `json:"closeAvgPrice,string"` + MarginMode string `json:"marginMode"` + OpenTotalPosition float64 `json:"openTotalPos,string"` + CloseTotalPosition float64 `json:"closeTotalPos,string"` + PNL float64 `json:"pnl,string"` + NetProfit float64 `json:"netProfit,string"` + TotalFunding float64 `json:"totalFunding,string"` + OpenFee float64 `json:"openFee,string"` + CloseFee float64 `json:"closeFee,string"` + UpdateTime UnixTimestamp `json:"uTime"` + CreationTime UnixTimestamp `json:"cTime"` +} + // HistPositionResp contains information on historical positions type HistPositionResp struct { - List []struct { - MarginCoin string `json:"marginCoin"` - Symbol string `json:"symbol"` - HoldSide string `json:"holdSide"` - OpenAveragePrice float64 `json:"openAvgPrice,string"` - CloseAveragePrice float64 `json:"closeAvgPrice,string"` - MarginMode string `json:"marginMode"` - OpenTotalPosition float64 `json:"openTotalPos,string"` - CloseTotalPosition float64 `json:"closeTotalPos,string"` - PNL float64 `json:"pnl,string"` - NetProfit float64 `json:"netProfit,string"` - TotalFunding float64 `json:"totalFunding,string"` - OpenFee float64 `json:"openFee,string"` - CloseFee float64 `json:"closeFee,string"` - UpdateTime UnixTimestamp `json:"uTime"` - CreationTime UnixTimestamp `json:"cTime"` - } `json:"list"` - EndID int64 `json:"endId,string"` + List []HistPositions `json:"list"` + EndID int64 `json:"endId,string"` } // PlaceFuturesOrderStruct contains information on an order to be placed @@ -1197,128 +1251,140 @@ type FuturesOrderDetailResp struct { UpdateTime UnixTimestamp `json:"uTime"` } +// FuturesFill is a sub-struct containing information on fulfilled futures orders +type FuturesFill struct { + TradeID int64 `json:"tradeId,string"` + Symbol string `json:"symbol"` + OrderID int64 `json:"orderId,string"` + Price float64 `json:"price,string"` + BaseVolume float64 `json:"baseVolume,string"` + FeeDetail []AbridgedFeeDetail `json:"feeDetail"` + Side string `json:"side"` + QuoteVolume float64 `json:"quoteVolume,string"` + Profit float64 `json:"profit,string"` + EnterPointSource string `json:"enterPointSource"` + TradeSide string `json:"tradeSide"` + PositionMode string `json:"posMode"` + TradeScope string `json:"tradeScope"` + CreationTime UnixTimestamp `json:"cTime"` +} + // FuturesFillsResp contains information on fulfilled futures orders type FuturesFillsResp struct { - FillList []struct { - TradeID int64 `json:"tradeId,string"` - Symbol string `json:"symbol"` - OrderID int64 `json:"orderId,string"` - Price float64 `json:"price,string"` - BaseVolume float64 `json:"baseVolume,string"` - FeeDetail []AbridgedFeeDetail `json:"feeDetail"` - Side string `json:"side"` - QuoteVolume float64 `json:"quoteVolume,string"` - Profit float64 `json:"profit,string"` - EnterPointSource string `json:"enterPointSource"` - TradeSide string `json:"tradeSide"` - PositionMode string `json:"posMode"` - TradeScope string `json:"tradeScope"` - CreationTime UnixTimestamp `json:"cTime"` - } `json:"fillList"` - EndID EmptyInt `json:"endId"` + FillList []FuturesFill `json:"fillList"` + EndID EmptyInt `json:"endId"` +} + +// FuturesOrder is a sub-struct containing information on futures orders +type FuturesOrder struct { + Symbol string `json:"symbol"` + Size float64 `json:"size,string"` + OrderID int64 `json:"orderId,string"` + ClientOrderID string `json:"clientOid"` + BaseVolume float64 `json:"baseVolume,string"` + Fee types.Number `json:"fee"` + Price types.Number `json:"price"` + PriceAverage types.Number `json:"priceAvg"` + Status string `json:"status"` + Side string `json:"side"` + Force string `json:"force"` + TotalProfits float64 `json:"totalProfits,string"` + PositionSide string `json:"posSide"` + MarginCoin string `json:"marginCoin"` + QuoteVolume float64 `json:"quoteVolume,string"` + Leverage float64 `json:"leverage,string"` + MarginMode string `json:"marginMode"` + EnterPointSource string `json:"enterPointSource"` + TradeSide string `json:"tradeSide"` + PositionMode string `json:"posMode"` + OrderType string `json:"orderType"` + OrderSource string `json:"orderSource"` + CreationTime UnixTimestamp `json:"cTime"` + UpdateTime UnixTimestamp `json:"uTime"` + PresetStopSurplusPrice types.Number `json:"presetStopSurplusPrice"` + PresetStopLossPrice types.Number `json:"presetStopLossPrice"` } // FuturesOrdResp contains information on futures orders type FuturesOrdResp struct { - EntrustedList []struct { - Symbol string `json:"symbol"` - Size float64 `json:"size,string"` - OrderID int64 `json:"orderId,string"` - ClientOrderID string `json:"clientOid"` - BaseVolume float64 `json:"baseVolume,string"` - Fee types.Number `json:"fee"` - Price types.Number `json:"price"` - PriceAverage types.Number `json:"priceAvg"` - Status string `json:"status"` - Side string `json:"side"` - Force string `json:"force"` - TotalProfits float64 `json:"totalProfits,string"` - PositionSide string `json:"posSide"` - MarginCoin string `json:"marginCoin"` - QuoteVolume float64 `json:"quoteVolume,string"` - Leverage float64 `json:"leverage,string"` - MarginMode string `json:"marginMode"` - EnterPointSource string `json:"enterPointSource"` - TradeSide string `json:"tradeSide"` - PositionMode string `json:"posMode"` - OrderType string `json:"orderType"` - OrderSource string `json:"orderSource"` - CreationTime UnixTimestamp `json:"cTime"` - UpdateTime UnixTimestamp `json:"uTime"` - PresetStopSurplusPrice types.Number `json:"presetStopSurplusPrice"` - PresetStopLossPrice types.Number `json:"presetStopLossPrice"` - } `json:"entrustedList"` - EndID EmptyInt `json:"endId"` + EntrustedList []FuturesOrder `json:"entrustedList"` + EndID EmptyInt `json:"endId"` +} + +// PlanFuturesOrder is a sub-struct containing information on planned futures orders +type PlanFuturesOrder struct { + PlanType string `json:"planType"` + Symbol string `json:"symbol"` + Size float64 `json:"size,string"` + OrderID int64 `json:"orderId,string"` + ClientOrderID string `json:"clientOid"` + Price types.Number `json:"price"` + CallbackRatio types.Number `json:"callbackRatio"` + TriggerPrice float64 `json:"triggerPrice,string"` + TriggerType string `json:"triggerType"` + PlanStatus string `json:"planStatus"` + Side string `json:"side"` + PositionSide string `json:"posSide"` + MarginCoin string `json:"marginCoin"` + MarginMode string `json:"marginMode"` + EnterPointSource string `json:"enterPointSource"` + TradeSide string `json:"tradeSide"` + PositionMode string `json:"posMode"` + OrderType string `json:"orderType"` + OrderSource string `json:"orderSource"` + CreationTime UnixTimestamp `json:"cTime"` + UpdateTime UnixTimestamp `json:"uTime"` + PresetTakeProfitPrice types.Number `json:"presetStopSurplusPrice"` + TakeprofitTriggerPrice types.Number `json:"stopSurplusTriggerPrice"` + TakeProfitTriggerType string `json:"stopSurplusTriggerType"` + PresetStopLossPrice types.Number `json:"presetStopLossPrice"` + StopLossTriggerPrice types.Number `json:"stopLossTriggerPrice"` + StopLossTriggerType string `json:"stopLossTriggerType"` } // PlanFuturesOrdResp contains information on planned futures orders type PlanFuturesOrdResp struct { - EntrustedList []struct { - PlanType string `json:"planType"` - Symbol string `json:"symbol"` - Size float64 `json:"size,string"` - OrderID int64 `json:"orderId,string"` - ClientOrderID string `json:"clientOid"` - Price types.Number `json:"price"` - CallbackRatio types.Number `json:"callbackRatio"` - TriggerPrice float64 `json:"triggerPrice,string"` - TriggerType string `json:"triggerType"` - PlanStatus string `json:"planStatus"` - Side string `json:"side"` - PositionSide string `json:"posSide"` - MarginCoin string `json:"marginCoin"` - MarginMode string `json:"marginMode"` - EnterPointSource string `json:"enterPointSource"` - TradeSide string `json:"tradeSide"` - PositionMode string `json:"posMode"` - OrderType string `json:"orderType"` - OrderSource string `json:"orderSource"` - CreationTime UnixTimestamp `json:"cTime"` - UpdateTime UnixTimestamp `json:"uTime"` - PresetTakeProfitPrice types.Number `json:"presetStopSurplusPrice"` - TakeprofitTriggerPrice types.Number `json:"stopSurplusTriggerPrice"` - TakeProfitTriggerType string `json:"stopSurplusTriggerType"` - PresetStopLossPrice types.Number `json:"presetStopLossPrice"` - StopLossTriggerPrice types.Number `json:"stopLossTriggerPrice"` - StopLossTriggerType string `json:"stopLossTriggerType"` - } `json:"entrustedList"` - EndID EmptyInt `json:"endId"` + EntrustedList []PlanFuturesOrder `json:"entrustedList"` + EndID EmptyInt `json:"endId"` +} + +// HistTriggerFuturesOrd is a sub-struct containing information on historical trigger futures orders +type HistTriggerFuturesOrd struct { + PlanType string `json:"planType"` + Symbol string `json:"symbol"` + Size float64 `json:"size,string"` + OrderID int64 `json:"orderId,string"` + ExecuteOrderID int64 `json:"executeOrderId,string"` + ClientOrderID string `json:"clientOid"` + PlanStatus string `json:"planStatus"` + Price float64 `json:"price,string"` + PriceAverage float64 `json:"priceAvg,string"` + BaseVolume float64 `json:"baseVolume,string"` + CallbackRatio types.Number `json:"callbackRatio"` + TriggerPrice float64 `json:"triggerPrice,string"` + TriggerType string `json:"triggerType"` + Side string `json:"side"` + PositionSide string `json:"posSide"` + MarginCoin string `json:"marginCoin"` + MarginMode string `json:"marginMode"` + EnterPointSource string `json:"enterPointSource"` + TradeSide string `json:"tradeSide"` + PositionMode string `json:"posMode"` + OrderType string `json:"orderType"` + CreationTime UnixTimestamp `json:"cTime"` + UpdateTime UnixTimestamp `json:"uTime"` + PresetTakeProfitPrice types.Number `json:"presetStopSurplusPrice"` + TakeprofitTriggerPrice types.Number `json:"stopSurplusTriggerPrice"` + TakeProfitTriggerType string `json:"stopSurplusTriggerType"` + PresetStopLossPrice types.Number `json:"presetStopLossPrice"` + StopLossTriggerPrice types.Number `json:"stopLossTriggerPrice"` + StopLossTriggerType string `json:"stopLossTriggerType"` } // HistTriggerFuturesOrdResp contains information on historical trigger futures orders type HistTriggerFuturesOrdResp struct { - EntrustedList []struct { - PlanType string `json:"planType"` - Symbol string `json:"symbol"` - Size float64 `json:"size,string"` - OrderID int64 `json:"orderId,string"` - ExecuteOrderID int64 `json:"executeOrderId,string"` - ClientOrderID string `json:"clientOid"` - PlanStatus string `json:"planStatus"` - Price float64 `json:"price,string"` - PriceAverage float64 `json:"priceAvg,string"` - BaseVolume float64 `json:"baseVolume,string"` - CallbackRatio types.Number `json:"callbackRatio"` - TriggerPrice float64 `json:"triggerPrice,string"` - TriggerType string `json:"triggerType"` - Side string `json:"side"` - PositionSide string `json:"posSide"` - MarginCoin string `json:"marginCoin"` - MarginMode string `json:"marginMode"` - EnterPointSource string `json:"enterPointSource"` - TradeSide string `json:"tradeSide"` - PositionMode string `json:"posMode"` - OrderType string `json:"orderType"` - CreationTime UnixTimestamp `json:"cTime"` - UpdateTime UnixTimestamp `json:"uTime"` - PresetTakeProfitPrice types.Number `json:"presetStopSurplusPrice"` - TakeprofitTriggerPrice types.Number `json:"stopSurplusTriggerPrice"` - TakeProfitTriggerType string `json:"stopSurplusTriggerType"` - PresetStopLossPrice types.Number `json:"presetStopLossPrice"` - StopLossTriggerPrice types.Number `json:"stopLossTriggerPrice"` - StopLossTriggerType string `json:"stopLossTriggerType"` - } `json:"entrustedList"` - EndID EmptyInt `json:"endId"` + EntrustedList []HistTriggerFuturesOrd `json:"entrustedList"` + EndID EmptyInt `json:"endId"` } // SupCurrencyResp contains information on supported currencies @@ -1345,83 +1411,98 @@ type SupCurrencyResp struct { IsCrossBorrowable bool `json:"isCrossBorrowable"` } +// CrossBorrow is a sub-struct containing information on borrowing for cross margin +type CrossBorrow struct { + LoanID int64 `json:"loanId,string"` + Coin string `json:"coin"` + BorrowAmount float64 `json:"borrowAmount,string"` + BorrowType string `json:"borrowType"` + CreationTime UnixTimestamp `json:"cTime"` + UpdateTime UnixTimestamp `json:"uTime"` +} + // BorrowHistCross contains information on borrowing history for cross margin type BorrowHistCross struct { - ResultList []struct { - LoanID int64 `json:"loanId,string"` - Coin string `json:"coin"` - BorrowAmount float64 `json:"borrowAmount,string"` - BorrowType string `json:"borrowType"` - CreationTime UnixTimestamp `json:"cTime"` - UpdateTime UnixTimestamp `json:"uTime"` - } `json:"resultList"` - MaxID EmptyInt `json:"maxId"` - MinID EmptyInt `json:"minId"` + ResultList []CrossBorrow `json:"resultList"` + MaxID EmptyInt `json:"maxId"` + MinID EmptyInt `json:"minId"` +} + +// Repayment is a sub-struct containing information on repayment +type Repayment struct { + RepayID int64 `json:"repayId,string"` + Coin string `json:"coin"` + RepayAmount float64 `json:"repayAmount,string"` + RepayType string `json:"repayType"` + RepayInterest float64 `json:"repayInterest,string"` + RepayPrincipal float64 `json:"repayPrincipal,string"` + CreationTime UnixTimestamp `json:"cTime"` + UpdateTime UnixTimestamp `json:"uTime"` } // RepayHistResp contains information on repayment history type RepayHistResp struct { - ResultList []struct { - RepayID int64 `json:"repayId,string"` - Coin string `json:"coin"` - RepayAmount float64 `json:"repayAmount,string"` - RepayType string `json:"repayType"` - RepayInterest float64 `json:"repayInterest,string"` - RepayPrincipal float64 `json:"repayPrincipal,string"` - CreationTime UnixTimestamp `json:"cTime"` - UpdateTime UnixTimestamp `json:"uTime"` - } `json:"resultList"` - MaxID EmptyInt `json:"maxId"` - MinID EmptyInt `json:"minId"` + ResultList []Repayment `json:"resultList"` + MaxID EmptyInt `json:"maxId"` + MinID EmptyInt `json:"minId"` +} + +// CrossInterest is a sub-struct containing information on interest for cross margin +type CrossInterest struct { + InterestID int64 `json:"interestId,string"` + LoanCoin string `json:"loanCoin"` + InterestCoin string `json:"interestCoin"` + DailyInterestRate float64 `json:"dailyInterestRate,string"` + InterestAmount float64 `json:"interestAmount,string"` + InterestType string `json:"interstType"` // sic + CreationTime UnixTimestamp `json:"cTime"` + UpdateTime UnixTimestamp `json:"uTime"` } // InterHistCross contains information on interest history for cross margin type InterHistCross struct { - MinID EmptyInt `json:"minId"` - MaxID EmptyInt `json:"maxId"` - ResultList []struct { - InterestID int64 `json:"interestId,string"` - LoanCoin string `json:"loanCoin"` - InterestCoin string `json:"interestCoin"` - DailyInterestRate float64 `json:"dailyInterestRate,string"` - InterestAmount float64 `json:"interestAmount,string"` - InterestType string `json:"interstType"` // sic - CreationTime UnixTimestamp `json:"cTime"` - UpdateTime UnixTimestamp `json:"uTime"` - } `json:"resultList"` + MinID EmptyInt `json:"minId"` + MaxID EmptyInt `json:"maxId"` + ResultList []CrossInterest `json:"resultList"` +} + +// CrossLiquidation is a sub-struct containing information on liquidation for cross margin +type CrossLiquidation struct { + LiquidationID int64 `json:"liqId,string"` + LiquidationStartTime UnixTimestamp `json:"liqStartTime"` + LiquidationEndTime UnixTimestamp `json:"liqEndTime"` + LiquidationRiskRatio float64 `json:"liqRiskRatio,string"` + TotalAssets float64 `json:"totalAssets,string"` + TotalDebt float64 `json:"totalDebt,string"` + LiquidationFee float64 `json:"liqFee,string"` + UpdateTime UnixTimestamp `json:"uTime"` + CreationTime UnixTimestamp `json:"cTime"` } // LiquidHistCross contains information on liquidation history for cross margin type LiquidHistCross struct { - MinID EmptyInt `json:"minId"` - MaxID EmptyInt `json:"maxId"` - ResultList []struct { - LiquidationID int64 `json:"liqId,string"` - LiquidationStartTime UnixTimestamp `json:"liqStartTime"` - LiquidationEndTime UnixTimestamp `json:"liqEndTime"` - LiquidationRiskRatio float64 `json:"liqRiskRatio,string"` - TotalAssets float64 `json:"totalAssets,string"` - TotalDebt float64 `json:"totalDebt,string"` - LiquidationFee float64 `json:"liqFee,string"` - UpdateTime UnixTimestamp `json:"uTime"` - CreationTime UnixTimestamp `json:"cTime"` - } `json:"resultList"` -} - -// FinHistCross contains information on financial history for cross margin -type FinHistCross struct { - MinID EmptyInt `json:"minId"` - MaxID EmptyInt `json:"maxId"` - ResultList []struct { - MarginID int64 `json:"marginId,string"` - Amount float64 `json:"amount,string"` - Coin string `json:"coin"` - Balance float64 `json:"balance,string"` - Fee float64 `json:"fee,string"` - MarginType string `json:"marginType"` - UpdateTime UnixTimestamp `json:"uTime"` - CreationTime UnixTimestamp `json:"cTime"` - } `json:"resultList"` + MinID EmptyInt `json:"minId"` + MaxID EmptyInt `json:"maxId"` + ResultList []CrossLiquidation `json:"resultList"` +} + +// CrossFinHist is a sub-struct containing information on financial history for cross margin +type CrossFinHist struct { + MarginID int64 `json:"marginId,string"` + Amount float64 `json:"amount,string"` + Coin string `json:"coin"` + Balance float64 `json:"balance,string"` + Fee float64 `json:"fee,string"` + MarginType string `json:"marginType"` + UpdateTime UnixTimestamp `json:"uTime"` + CreationTime UnixTimestamp `json:"cTime"` +} + +// FinHistCrossResp contains information on financial history for cross margin +type FinHistCrossResp struct { + MinID EmptyInt `json:"minId"` + MaxID EmptyInt `json:"maxId"` + ResultList []CrossFinHist `json:"resultList"` } // CrossAssetResp contains information on assets being utilised in cross margin @@ -1465,23 +1546,26 @@ type MaxTransferCross struct { MaxTransferOutAmount float64 `json:"maxTransferOutAmount,string"` } +// VIPInfo is a sub-struct containing information on VIP levels +type VIPInfo struct { + Level int64 `json:"level,string"` + Limit float64 `json:"limit,string"` + DailyInterestRate float64 `json:"dailyInterestRate,string"` + AnnualInterestRate float64 `json:"annualInterestRate,string"` + DiscountRate float64 `json:"discountRate,string"` +} + // IntRateMaxBorrowCross contains information on the interest rate and the maximum amount that can be borrowed for // cross margin type IntRateMaxBorrowCross struct { - Transferable bool `json:"transferable"` - Leverage float64 `json:"leverage,string"` - Coin string `json:"coin"` - Borrowable bool `json:"borrowable"` - DailyInterestRate float64 `json:"dailyInterestRate,string"` - AnnualInterestRate float64 `json:"annualInterestRate,string"` - MaxBorrowableAmount float64 `json:"maxBorrowableAmount,string"` - VIPList []struct { - Level int64 `json:"level,string"` - Limit float64 `json:"limit,string"` - DailyInterestRate float64 `json:"dailyInterestRate,string"` - AnnualInterestRate float64 `json:"annualInterestRate,string"` - DiscountRate float64 `json:"discountRate,string"` - } `json:"vipList"` + Transferable bool `json:"transferable"` + Leverage float64 `json:"leverage,string"` + Coin string `json:"coin"` + Borrowable bool `json:"borrowable"` + DailyInterestRate float64 `json:"dailyInterestRate,string"` + AnnualInterestRate float64 `json:"annualInterestRate,string"` + MaxBorrowableAmount float64 `json:"maxBorrowableAmount,string"` + VIPList []VIPInfo `json:"vipList"` } // TierConfigCross contains information on tier configurations for cross margin @@ -1517,217 +1601,223 @@ type MarginOrderData struct { ClientOrderID string `json:"clientOid"` } +// MarginOrder is a sub-struct containing information on a margin order +type MarginOrder struct { + OrderID int64 `json:"orderId,string"` + Symbol string `json:"symbol"` + OrderType string `json:"orderType"` + EnterPointSource string `json:"enterPointSource"` + ClientOrderID string `json:"clientOid"` + LoanType string `json:"loanType"` + Price float64 `json:"price,string"` + Side string `json:"side"` + Status string `json:"status"` + BaseSize float64 `json:"baseSize,string"` + QuoteSize float64 `json:"quoteSize,string"` + Size float64 `json:"size,string"` + Amount float64 `json:"amount,string"` + Force string `json:"force"` + CreationTime UnixTimestamp `json:"cTime"` + UpdateTime UnixTimestamp `json:"uTime"` +} + // MarginOpenOrds contains information on open margin orders type MarginOpenOrds struct { - OrderList []struct { - OrderID int64 `json:"orderId,string"` - Symbol string `json:"symbol"` - OrderType string `json:"orderType"` - EnterPointSource string `json:"enterPointSource"` - ClientOrderID string `json:"clientOid"` - LoanType string `json:"loanType"` - Price float64 `json:"price,string"` - Side string `json:"side"` - Status string `json:"status"` - BaseSize float64 `json:"baseSize,string"` - QuoteSize float64 `json:"quoteSize,string"` - Size float64 `json:"size,string"` - Amount float64 `json:"amount,string"` - Force string `json:"force"` - CreationTime UnixTimestamp `json:"cTime"` - UpdateTime UnixTimestamp `json:"uTime"` - } `json:"orderList"` - MaxID EmptyInt `json:"maxId"` - MinID EmptyInt `json:"minId"` + OrderList []MarginOrder `json:"orderList"` + MaxID EmptyInt `json:"maxId"` + MinID EmptyInt `json:"minId"` +} + +// MarginOrdWithAveragePrice is a sub-struct containing information on a margin order with an average price +type MarginOrdWithAveragePrice struct { + OrderID int64 `json:"orderId,string"` + Symbol string `json:"symbol"` + OrderType string `json:"orderType"` + EnterPointSource string `json:"enterPointSource"` + ClientOrderID string `json:"clientOid"` + LoanType string `json:"loanType"` + Price float64 `json:"price,string"` + Side string `json:"side"` + Status string `json:"status"` + BaseSize float64 `json:"baseSize,string"` + QuoteSize float64 `json:"quoteSize,string"` + PriceAverage float64 `json:"priceAvg,string"` + Size float64 `json:"size,string"` + Amount float64 `json:"amount,string"` + Force string `json:"force"` + CreationTime UnixTimestamp `json:"cTime"` + UpdateTime UnixTimestamp `json:"uTime"` } // MarginHistOrds contains information on historical margin orders type MarginHistOrds struct { - OrderList []struct { - OrderID int64 `json:"orderId,string"` - Symbol string `json:"symbol"` - OrderType string `json:"orderType"` - EnterPointSource string `json:"enterPointSource"` - ClientOrderID string `json:"clientOid"` - LoanType string `json:"loanType"` - Price float64 `json:"price,string"` - Side string `json:"side"` - Status string `json:"status"` - BaseSize float64 `json:"baseSize,string"` - QuoteSize float64 `json:"quoteSize,string"` - PriceAverage float64 `json:"priceAvg,string"` - Size float64 `json:"size,string"` - Amount float64 `json:"amount,string"` - Force string `json:"force"` - CreationTime UnixTimestamp `json:"cTime"` - UpdateTime UnixTimestamp `json:"uTime"` - } `json:"orderList"` - MaxID EmptyInt `json:"maxId"` - MinID EmptyInt `json:"minId"` + OrderList []MarginOrdWithAveragePrice `json:"orderList"` + MaxID EmptyInt `json:"maxId"` + MinID EmptyInt `json:"minId"` +} + +// MarginFill is a sub-struct containing information on fulfilled margin orders +type MarginFill struct { + OrderID int64 `json:"orderId,string"` + TradeID int64 `json:"tradeId,string"` + OrderType string `json:"orderType"` + Side string `json:"side"` + PriceAverage float64 `json:"priceAvg,string"` + Size float64 `json:"size,string"` + Amount float64 `json:"amount,string"` + TradeScope string `json:"tradeScope"` + CreationTime UnixTimestamp `json:"cTime"` + UpdateTime UnixTimestamp `json:"uTime"` + FeeDetail AbridgedFeeDetail `json:"feeDetail"` } // MarginOrderFills contains information on fulfilled margin orders type MarginOrderFills struct { - Fills []struct { - OrderID int64 `json:"orderId,string"` - TradeID int64 `json:"tradeId,string"` - OrderType string `json:"orderType"` - Side string `json:"side"` - PriceAverage float64 `json:"priceAvg,string"` - Size float64 `json:"size,string"` - Amount float64 `json:"amount,string"` - TradeScope string `json:"tradeScope"` - CreationTime UnixTimestamp `json:"cTime"` - UpdateTime UnixTimestamp `json:"uTime"` - FeeDetail AbridgedFeeDetail `json:"feeDetail"` - } `json:"fills"` - MaxID EmptyInt `json:"maxId"` - MinID EmptyInt `json:"minId"` + Fills []MarginFill `json:"fills"` + MaxID EmptyInt `json:"maxId"` + MinID EmptyInt `json:"minId"` +} + +// LiquidationOrder is a sub-struct containing information on liquidation orders +type LiquidationOrder struct { + Symbol string `json:"symbol"` + OrderType string `json:"orderType"` + Side string `json:"side"` + PriceAverage float64 `json:"priceAvg,string"` + Price float64 `json:"price,string"` + FillSize float64 `json:"fillSize,string"` + Size float64 `json:"size,string"` + Amount float64 `json:"amount,string"` + OrderID int64 `json:"orderId,string"` + FromCoin string `json:"fromCoin"` + ToCoin string `json:"toCoin"` + FromSize types.Number `json:"fromSize"` + ToSize types.Number `json:"toSize"` + CreationTime UnixTimestamp `json:"cTime"` + UpdateTime UnixTimestamp `json:"uTime"` } // LiquidationResp contains information on liquidation orders type LiquidationResp struct { - Data struct { - ResultList []struct { - Symbol string `json:"symbol"` - OrderType string `json:"orderType"` - Side string `json:"side"` - PriceAverage float64 `json:"priceAvg,string"` - Price float64 `json:"price,string"` - FillSize float64 `json:"fillSize,string"` - Size float64 `json:"size,string"` - Amount float64 `json:"amount,string"` - OrderID int64 `json:"orderId,string"` - FromCoin string `json:"fromCoin"` - ToCoin string `json:"toCoin"` - FromSize types.Number `json:"fromSize"` - ToSize types.Number `json:"toSize"` - CreationTime UnixTimestamp `json:"cTime"` - UpdateTime UnixTimestamp `json:"uTime"` - } `json:"resultList"` - IDLessThan EmptyInt `json:"idLessThan"` - } `json:"data"` + ResultList []LiquidationOrder `json:"resultList"` + IDLessThan EmptyInt `json:"idLessThan"` +} + +// IsoBorrow is a sub-struct containing information on borrowing for isolated margin +type IsoBorrow struct { + LoanID int64 `json:"loanId,string"` + Coin string `json:"coin"` + BorrowAmount float64 `json:"borrowAmount,string"` + BorrowType string `json:"borrowType"` + Symbol string `json:"symbol"` + CreationTime UnixTimestamp `json:"cTime"` + UpdateTime UnixTimestamp `json:"uTime"` } // BorrowHistIso contains information on borrowing history for isolated margin type BorrowHistIso struct { - Data struct { - ResultList []struct { - LoanID int64 `json:"loanId,string"` - Coin string `json:"coin"` - BorrowAmount float64 `json:"borrowAmount,string"` - BorrowType string `json:"borrowType"` - Symbol string `json:"symbol"` - CreationTime UnixTimestamp `json:"cTime"` - UpdateTime UnixTimestamp `json:"uTime"` - } `json:"resultList"` - MaxID EmptyInt `json:"maxId"` - MinID EmptyInt `json:"minId"` - } `json:"data"` + ResultList []IsoBorrow `json:"resultList"` + MaxID EmptyInt `json:"maxId"` + MinID EmptyInt `json:"minId"` +} + +// IsoInterest is a sub-struct containing information on interest for isolated margin +type IsoInterest struct { + InterestID int64 `json:"interestId,string"` + LoanCoin string `json:"loanCoin"` + InterestCoin string `json:"interestCoin"` + DailyInterestRate float64 `json:"dailyInterestRate,string"` + InterestAmount float64 `json:"interestAmount,string"` + InterestType string `json:"interstType"` // sic + Symbol string `json:"symbol"` + CreationTime UnixTimestamp `json:"cTime"` + UpdateTime UnixTimestamp `json:"uTime"` } // InterHistIso contains information on interest history for isolated margin type InterHistIso struct { - Data struct { - MinID EmptyInt `json:"minId"` - MaxID EmptyInt `json:"maxId"` - ResultList []struct { - InterestID int64 `json:"interestId,string"` - LoanCoin string `json:"loanCoin"` - InterestCoin string `json:"interestCoin"` - DailyInterestRate float64 `json:"dailyInterestRate,string"` - InterestAmount float64 `json:"interestAmount,string"` - InterestType string `json:"interstType"` // sic - Symbol string `json:"symbol"` - CreationTime UnixTimestamp `json:"cTime"` - UpdateTime UnixTimestamp `json:"uTime"` - } `json:"resultList"` - } `json:"data"` + MinID EmptyInt `json:"minId"` + MaxID EmptyInt `json:"maxId"` + ResultList []IsoInterest `json:"resultList"` +} + +// IsoLiquidation is a sub-struct containing information on liquidation for isolated margin +type IsoLiquidation struct { + LiquidationID int64 `json:"liqId,string"` + Symbol string `json:"symbol"` + LiquidationStartTime UnixTimestamp `json:"liqStartTime"` + LiquidationEndTime UnixTimestamp `json:"liqEndTime"` + LiquidationRiskRatio float64 `json:"liqRiskRatio,string"` + TotalAssets float64 `json:"totalAssets,string"` + TotalDebt float64 `json:"totalDebt,string"` + LiquidationFee float64 `json:"liqFee,string"` + UpdateTime UnixTimestamp `json:"uTime"` + CreationTime UnixTimestamp `json:"cTime"` } // LiquidHistIso contains information on liquidation history for isolated margin type LiquidHistIso struct { - Data struct { - MinID EmptyInt `json:"minId"` - MaxID EmptyInt `json:"maxId"` - ResultList []struct { - LiquidationID int64 `json:"liqId,string"` - Symbol string `json:"symbol"` - LiquidationStartTime UnixTimestamp `json:"liqStartTime"` - LiquidationEndTime UnixTimestamp `json:"liqEndTime"` - LiquidationRiskRatio float64 `json:"liqRiskRatio,string"` - TotalAssets float64 `json:"totalAssets,string"` - TotalDebt float64 `json:"totalDebt,string"` - LiquidationFee float64 `json:"liqFee,string"` - UpdateTime UnixTimestamp `json:"uTime"` - CreationTime UnixTimestamp `json:"cTime"` - } `json:"resultList"` - } `json:"data"` -} - -// FinHistIso contains information on financial history for isolated margin -type FinHistIso struct { - Data struct { - MinID EmptyInt `json:"minId"` - MaxID EmptyInt `json:"maxId"` - ResultList []struct { - MarginID int64 `json:"marginId,string"` - Amount float64 `json:"amount,string"` - Coin string `json:"coin"` - Symbol string `json:"symbol"` - Balance float64 `json:"balance,string"` - Fee float64 `json:"fee,string"` - MarginType string `json:"marginType"` - UpdateTime UnixTimestamp `json:"uTime"` - CreationTime UnixTimestamp `json:"cTime"` - } `json:"resultList"` - } `json:"data"` + MinID EmptyInt `json:"minId"` + MaxID EmptyInt `json:"maxId"` + ResultList []IsoLiquidation `json:"resultList"` +} + +// IsoFinHist is a sub-struct containing information on financial history for isolated margin +type IsoFinHist struct { + MarginID int64 `json:"marginId,string"` + Amount float64 `json:"amount,string"` + Coin string `json:"coin"` + Symbol string `json:"symbol"` + Balance float64 `json:"balance,string"` + Fee float64 `json:"fee,string"` + MarginType string `json:"marginType"` + UpdateTime UnixTimestamp `json:"uTime"` + CreationTime UnixTimestamp `json:"cTime"` +} + +// FinHistIsoResp contains information on financial history for isolated margin +type FinHistIsoResp struct { + MinID EmptyInt `json:"minId"` + MaxID EmptyInt `json:"maxId"` + ResultList []IsoFinHist `json:"resultList"` } // IsoAssetResp contains information on assets being utilised in isolated margin type IsoAssetResp struct { - Data []struct { - Symbol string `json:"symbol"` - Coin string `json:"coin"` - TotalAmount float64 `json:"totalAmount,string"` - Available float64 `json:"available,string"` - Frozen float64 `json:"frozen,string"` - Borrow float64 `json:"borrow,string"` - Interest float64 `json:"interest,string"` - Net float64 `json:"net,string"` - CreationTime UnixTimestamp `json:"cTime"` - UpdateTime UnixTimestamp `json:"uTime"` - Coupon float64 `json:"coupon,string"` - } `json:"data"` + Symbol string `json:"symbol"` + Coin string `json:"coin"` + TotalAmount float64 `json:"totalAmount,string"` + Available float64 `json:"available,string"` + Frozen float64 `json:"frozen,string"` + Borrow float64 `json:"borrow,string"` + Interest float64 `json:"interest,string"` + Net float64 `json:"net,string"` + CreationTime UnixTimestamp `json:"cTime"` + UpdateTime UnixTimestamp `json:"uTime"` + Coupon float64 `json:"coupon,string"` } // BorrowIso contains information on borrowing for isolated margin type BorrowIso struct { - Data struct { - LoanID int64 `json:"loanId,string"` - Symbol string `json:"symbol"` - Coin string `json:"coin"` - BorrowAmount float64 `json:"borrowAmount,string"` - } `json:"data"` + LoanID int64 `json:"loanId,string"` + Symbol string `json:"symbol"` + Coin string `json:"coin"` + BorrowAmount float64 `json:"borrowAmount,string"` } // RepayIso contains information on repayment for isolated margin type RepayIso struct { - Data struct { - Coin string `json:"coin"` - Symbol string `json:"symbol"` - RepayID int64 `json:"repayId,string"` - RemainingDebtAmount float64 `json:"remainDebtAmount,string"` - RepayAmount float64 `json:"repayAmount,string"` - } `json:"data"` + Coin string `json:"coin"` + Symbol string `json:"symbol"` + RepayID int64 `json:"repayId,string"` + RemainingDebtAmount float64 `json:"remainDebtAmount,string"` + RepayAmount float64 `json:"repayAmount,string"` } // RiskRateIso contains information on the risk rate for isolated margin type RiskRateIso struct { - Data []struct { - Symbol string `json:"symbol"` - RiskRateRatio float64 `json:"riskRateRatio,string"` - } `json:"data"` + Symbol string `json:"symbol"` + RiskRateRatio float64 `json:"riskRateRatio,string"` } // IsoVIPList contains information on VIP lists for isolated margin @@ -1742,70 +1832,60 @@ type IsoVIPList struct { // IntRateMaxBorrowIso contains information on the interest rate and the maximum amount that can be borrowed for // isolated margin type IntRateMaxBorrowIso struct { - Data []struct { - Symbol string `json:"symbol"` - Leverage float64 `json:"leverage,string"` - BaseCoin string `json:"baseCoin"` - BaseTransferable bool `json:"baseTransferable"` - BaseBorrowable bool `json:"baseBorrowable"` - BaseDailyInterestRate float64 `json:"baseDailyInterestRate,string"` - BaseAnnualInterestRate float64 `json:"baseAnnuallyInterestRate,string"` // sic - BaseMaxBorrowableAmount float64 `json:"baseMaxBorrowableAmount,string"` - BaseVIPList []IsoVIPList `json:"baseVipList"` - QuoteCoin string `json:"quoteCoin"` - QuoteTransferable bool `json:"quoteTransferable"` - QuoteBorrowable bool `json:"quoteBorrowable"` - QuoteDailyInterestRate float64 `json:"quoteDailyInterestRate,string"` - QuoteAnnualInterestRate float64 `json:"quoteAnnuallyInterestRate,string"` // sic - QuoteMaxBorrowableAmount float64 `json:"quoteMaxBorrowableAmount,string"` - QuoteVIPList []IsoVIPList `json:"quoteList"` - } `json:"data"` + Symbol string `json:"symbol"` + Leverage float64 `json:"leverage,string"` + BaseCoin string `json:"baseCoin"` + BaseTransferable bool `json:"baseTransferable"` + BaseBorrowable bool `json:"baseBorrowable"` + BaseDailyInterestRate float64 `json:"baseDailyInterestRate,string"` + BaseAnnualInterestRate float64 `json:"baseAnnuallyInterestRate,string"` // sic + BaseMaxBorrowableAmount float64 `json:"baseMaxBorrowableAmount,string"` + BaseVIPList []IsoVIPList `json:"baseVipList"` + QuoteCoin string `json:"quoteCoin"` + QuoteTransferable bool `json:"quoteTransferable"` + QuoteBorrowable bool `json:"quoteBorrowable"` + QuoteDailyInterestRate float64 `json:"quoteDailyInterestRate,string"` + QuoteAnnualInterestRate float64 `json:"quoteAnnuallyInterestRate,string"` // sic + QuoteMaxBorrowableAmount float64 `json:"quoteMaxBorrowableAmount,string"` + QuoteVIPList []IsoVIPList `json:"quoteList"` } // TierConfigIso contains information on tier configurations for isolated margin type TierConfigIso struct { - Data []struct { - Tier int64 `json:"tier,string"` - Symbol string `json:"symbol"` - Leverage float64 `json:"leverage,string"` - BaseCoin string `json:"baseCoin"` - QuoteCoin string `json:"quoteCoin"` - BaseMaxBorrowableAmount float64 `json:"baseMaxBorrowableAmount,string"` - QuoteMaxBorrowableAmount float64 `json:"quoteMaxBorrowableAmount,string"` - MaintainMarginRate float64 `json:"maintainMarginRate,string"` - InitRate float64 `json:"initRate,string"` - } `json:"data"` + Tier int64 `json:"tier,string"` + Symbol string `json:"symbol"` + Leverage float64 `json:"leverage,string"` + BaseCoin string `json:"baseCoin"` + QuoteCoin string `json:"quoteCoin"` + BaseMaxBorrowableAmount float64 `json:"baseMaxBorrowableAmount,string"` + QuoteMaxBorrowableAmount float64 `json:"quoteMaxBorrowableAmount,string"` + MaintainMarginRate float64 `json:"maintainMarginRate,string"` + InitRate float64 `json:"initRate,string"` } // MaxBorrowIso contains information on the maximum amount that can be borrowed for isolated margin type MaxBorrowIso struct { - Data struct { - Symbol string `json:"symbol"` - BaseCoin string `json:"baseCoin"` - BaseCoinMaxBorrowableAmount float64 `json:"baseCoinmaxBorrowAmount,string"` - QuoteCoin string `json:"quoteCoin"` - QuoteCoinMaxBorrowableAmount float64 `json:"quoteCoinmaxBorrowAmount,string"` - } `json:"data"` + Symbol string `json:"symbol"` + BaseCoin string `json:"baseCoin"` + BaseCoinMaxBorrowableAmount float64 `json:"baseCoinmaxBorrowAmount,string"` + QuoteCoin string `json:"quoteCoin"` + QuoteCoinMaxBorrowableAmount float64 `json:"quoteCoinmaxBorrowAmount,string"` } // MaxTransferIso contains information on the maximum amount that can be transferred out of isolated margin type MaxTransferIso struct { - Data struct { - BaseCoin string `json:"baseCoin"` - Symbol string `json:"symbol"` - BaseCoinMaxTransferOutAmount float64 `json:"baseCoinMaxTransferOutAmount,string"` - QuoteCoin string `json:"quoteCoin"` - QuoteCoinMaxTransferOutAmount float64 `json:"quoteCoinMaxTransferOutAmount,string"` - } `json:"data"` + BaseCoin string `json:"baseCoin"` + Symbol string `json:"symbol"` + BaseCoinMaxTransferOutAmount float64 `json:"baseCoinMaxTransferOutAmount,string"` + QuoteCoin string `json:"quoteCoin"` + QuoteCoinMaxTransferOutAmount float64 `json:"quoteCoinMaxTransferOutAmount,string"` } // FlashRepayIso contains information on a flash repayment for isolated margin type FlashRepayIso struct { - Data []struct { - RepayID int64 `json:"repayId,string"` - Symbol string `json:"symbol"` - Result SuccessBool `json:"result"` - } `json:"data"` + RepayID int64 `json:"repayId,string"` + Symbol string `json:"symbol"` + Result SuccessBool `json:"result"` } type APY struct { @@ -1817,328 +1897,300 @@ type APY struct { // SavingsProductList contains information on savings products type SavingsProductList struct { - Data []struct { - ProductID int64 `json:"productId,string"` - Coin string `json:"coin"` - PeriodType string `json:"periodType"` - Period EmptyInt `json:"period"` - APYType string `json:"apyType"` - AdvanceRedeem YesNoBool `json:"advanceRedeem"` - SettleMethod string `json:"settleMethod"` - APYList []APY `json:"apyList"` - Status string `json:"status"` - ProductLevel string `json:"productLevel"` - } `json:"data"` + ProductID int64 `json:"productId,string"` + Coin string `json:"coin"` + PeriodType string `json:"periodType"` + Period EmptyInt `json:"period"` + APYType string `json:"apyType"` + AdvanceRedeem YesNoBool `json:"advanceRedeem"` + SettleMethod string `json:"settleMethod"` + APYList []APY `json:"apyList"` + Status string `json:"status"` + ProductLevel string `json:"productLevel"` } // SavingsBalance contains information on savings balances type SavingsBalance struct { - Data struct { - BTCAmount float64 `json:"btcAmount,string"` - USDTAmount float64 `json:"usdtAmount,string"` - BTC24HourEarnings float64 `json:"btc24HourEarning,string"` - USDT24HourEarnings float64 `json:"usdt24HourEarning,string"` - BTCTotalEarnings float64 `json:"btcTotalEarning,string"` - USDTTotalEarnings float64 `json:"usdtTotalEarning,string"` - } `json:"data"` -} - -// SavingsAssets contains information on savings assets -type SavingsAssets struct { - Data struct { - ResultList []struct { - ProductID int64 `json:"productId,string"` - OrderID int64 `json:"orderId,string"` // Docs are inconsistent, check whether this exists - ProductCoin string `json:"productCoin"` - InterestCoin string `json:"interestCoin"` - PeriodType string `json:"periodType"` - Period EmptyInt `json:"period"` - HoldAmount float64 `json:"holdAmount,string"` - LastProfit float64 `json:"lastProfit,string"` - TotalProfit float64 `json:"totalProfit,string"` - HoldDays EmptyInt `json:"holdDays"` - Status string `json:"status"` - AllowRedemption YesNoBool `json:"allowRedemption"` // Docs are inconsistent, check whether this exists - ProductLevel string `json:"productLevel"` - APY []APY `json:"apy"` - } `json:"resultList"` - EndID EmptyInt `json:"endId"` - } `json:"data"` + BTCAmount float64 `json:"btcAmount,string"` + USDTAmount float64 `json:"usdtAmount,string"` + BTC24HourEarnings float64 `json:"btc24HourEarning,string"` + USDT24HourEarnings float64 `json:"usdt24HourEarning,string"` + BTCTotalEarnings float64 `json:"btcTotalEarning,string"` + USDTTotalEarnings float64 `json:"usdtTotalEarning,string"` +} + +// SavingsAsset is a sub-struct containing information on savings assets +type SavingsAsset struct { + ProductID int64 `json:"productId,string"` + OrderID int64 `json:"orderId,string"` // Docs are inconsistent, check whether this exists + ProductCoin string `json:"productCoin"` + InterestCoin string `json:"interestCoin"` + PeriodType string `json:"periodType"` + Period EmptyInt `json:"period"` + HoldAmount float64 `json:"holdAmount,string"` + LastProfit float64 `json:"lastProfit,string"` + TotalProfit float64 `json:"totalProfit,string"` + HoldDays EmptyInt `json:"holdDays"` + Status string `json:"status"` + AllowRedemption YesNoBool `json:"allowRedemption"` // Docs are inconsistent, check whether this exists + ProductLevel string `json:"productLevel"` + APY []APY `json:"apy"` +} + +// SavingsAssetsResp contains information on savings assets +type SavingsAssetsResp struct { + ResultList []SavingsAsset `json:"resultList"` + EndID EmptyInt `json:"endId"` +} + +// SavingsTransaction is a sub-struct containing information on a savings transaction +type SavingsTransaction struct { + OrderID int64 `json:"orderId,string"` + CoinName string `json:"coinName"` + SettleCoinName string `json:"settleCoinName"` + ProductType string `json:"productType"` + Period EmptyInt `json:"period"` + ProductLevel string `json:"productLevel"` + Amount float64 `json:"amount,string"` + Timestamp UnixTimestamp `json:"ts"` + OrderType string `json:"orderType"` } // SavingsRecords contains information on previous transactions type SavingsRecords struct { - Data struct { - ResultList []struct { - OrderID int64 `json:"orderId,string"` - CoinName string `json:"coinName"` - SettleCoinName string `json:"settleCoinName"` - ProductType string `json:"productType"` - Period EmptyInt `json:"period"` - ProductLevel string `json:"productLevel"` - Amount float64 `json:"amount,string"` - Timestamp UnixTimestamp `json:"ts"` - OrderType string `json:"orderType"` - } `json:"resultList"` - EndID EmptyInt `json:"endId"` - } `json:"data"` + ResultList []SavingsTransaction `json:"resultList"` + EndID EmptyInt `json:"endId"` } // SavingsSubDetail contains information about a potential subscription type SavingsSubDetail struct { - Data struct { - SingleMinAmount float64 `json:"singleMinAmount,string"` - SingleMaxAmount float64 `json:"singleMaxAmount,string"` - RemainingAmount float64 `json:"remainingAmount,string"` - SubscribePrecision uint8 `json:"subscribePrecision,string"` - ProfitPrecision uint8 `json:"profitPrecision,string"` - SubscribeTime UnixTimestamp `json:"subscribeTime"` - InterestTime UnixTimestamp `json:"interestTime"` - SettleTime UnixTimestamp `json:"settleTime"` - ExpireTime UnixTimestamp `json:"expireTime"` - RedeemTime UnixTimestamp `json:"redeemTime"` - SettleMethod string `json:"settleMethod"` - APYList []APY `json:"apyList"` - RedeemDelay string `json:"redeemDelay"` - } `json:"data"` + SingleMinAmount float64 `json:"singleMinAmount,string"` + SingleMaxAmount float64 `json:"singleMaxAmount,string"` + RemainingAmount float64 `json:"remainingAmount,string"` + SubscribePrecision uint8 `json:"subscribePrecision,string"` + ProfitPrecision uint8 `json:"profitPrecision,string"` + SubscribeTime UnixTimestamp `json:"subscribeTime"` + InterestTime UnixTimestamp `json:"interestTime"` + SettleTime UnixTimestamp `json:"settleTime"` + ExpireTime UnixTimestamp `json:"expireTime"` + RedeemTime UnixTimestamp `json:"redeemTime"` + SettleMethod string `json:"settleMethod"` + APYList []APY `json:"apyList"` + RedeemDelay string `json:"redeemDelay"` } // SubResp contains information on a transaction involving a savings product type SaveResp struct { - Data struct { - OrderID int64 `json:"orderId,string"` - Status string `json:"status"` // Double-check, might be a float64 - } `json:"data"` + OrderID int64 `json:"orderId,string"` + Status string `json:"status"` // Double-check, might be a float64 } // SubResult contains information on the result of a transaction involving a savings product type SaveResult struct { - Data struct { - Result SuccessBool `json:"result"` - Message string `json:"msg"` - } `json:"data"` + Result SuccessBool `json:"result"` + Message string `json:"msg"` } // EarnAssets contains information on assets in the earn account type EarnAssets struct { - Data []struct { - Coin string `json:"coin"` - Amount float64 `json:"amount,string"` - } `json:"data"` -} - -// SharkFinProducts contains information on shark fin products -type SharkFinProducts struct { - Data struct { - ResultList []struct { - ProductID int64 `json:"productId,string"` - ProductName string `json:"productName"` - ProductCoin string `json:"productCoin"` - SubscribeCoin string `json:"subscribeCoin"` - FarmingStartTime UnixTimestamp `json:"farmingStartTime"` - FarmingEndTime UnixTimestamp `json:"farmingEndTime"` - LowerRate float64 `json:"lowerRate,string"` - DefaultRate float64 `json:"defaultRate,string"` - UpperRate float64 `json:"upperRate,string"` - Period EmptyInt `json:"period"` - InterestStartTime UnixTimestamp `json:"interestStartTime"` - Status string `json:"status"` - MinAmount float64 `json:"minAmount,string"` - LimitAmount float64 `json:"limitAmount,string"` - SoldAmount float64 `json:"soldAmount,string"` - EndTime UnixTimestamp `json:"endTime"` - StartTime UnixTimestamp `json:"startTime"` - } `json:"resultList"` - EndID EmptyInt `json:"endId"` - } `json:"data"` + Coin string `json:"coin"` + Amount float64 `json:"amount,string"` +} + +// SharkFinProduct is a sub-struct containing information on a shark fin product +type SharKFinProduct struct { + ProductID int64 `json:"productId,string"` + ProductName string `json:"productName"` + ProductCoin string `json:"productCoin"` + SubscribeCoin string `json:"subscribeCoin"` + FarmingStartTime UnixTimestamp `json:"farmingStartTime"` + FarmingEndTime UnixTimestamp `json:"farmingEndTime"` + LowerRate float64 `json:"lowerRate,string"` + DefaultRate float64 `json:"defaultRate,string"` + UpperRate float64 `json:"upperRate,string"` + Period EmptyInt `json:"period"` + InterestStartTime UnixTimestamp `json:"interestStartTime"` + Status string `json:"status"` + MinAmount float64 `json:"minAmount,string"` + LimitAmount float64 `json:"limitAmount,string"` + SoldAmount float64 `json:"soldAmount,string"` + EndTime UnixTimestamp `json:"endTime"` + StartTime UnixTimestamp `json:"startTime"` +} + +// SharkFinProductResp contains information on shark fin products +type SharkFinProductResp struct { + ResultList []SharKFinProduct `json:"resultList"` + EndID EmptyInt `json:"endId"` } // SharkFinBalance contains information on one's shark fin balance and amount earned type SharkFinBalance struct { - Data struct { - BTCSubscribeAmount float64 `json:"btcSubscribeAmount,string"` - USDTSubscribeAmount float64 `json:"usdtSubscribeAmount,string"` - BTCHistoricalAmount float64 `json:"btcHistoricalAmount,string"` - USDTHistoricalAmount float64 `json:"usdtHistoricalAmount,string"` - BTCTotalEarning float64 `json:"btcTotalEarning,string"` - USDTTotalEarning float64 `json:"usdtTotalEarning,string"` - } `json:"data"` -} - -// SharkFinAssets contains information on one's shark fin assets -type SharkFinAssets struct { - Data struct { - ResultList []struct { - ProductID int64 `json:"productId,string"` - InterestStartTime UnixTimestamp `json:"interestStartTime"` - InterestEndTime UnixTimestamp `json:"interestEndTime"` - ProductCoin string `json:"productCoin"` - SubscribeCoin string `json:"subscribeCoin"` - Trend string `json:"trend"` - SettleTime UnixTimestamp `json:"settleTime"` - InterestAmount types.Number `json:"interestAmount"` - ProductStatus string `json:"productStatus"` - } `json:"resultList"` - EndID EmptyInt `json:"endId"` - } `json:"data"` + BTCSubscribeAmount float64 `json:"btcSubscribeAmount,string"` + USDTSubscribeAmount float64 `json:"usdtSubscribeAmount,string"` + BTCHistoricalAmount float64 `json:"btcHistoricalAmount,string"` + USDTHistoricalAmount float64 `json:"usdtHistoricalAmount,string"` + BTCTotalEarning float64 `json:"btcTotalEarning,string"` + USDTTotalEarning float64 `json:"usdtTotalEarning,string"` +} + +// SharkFinAsset is a sub-struct containing information on a shark fin asset +type SharkFinAsset struct { + ProductID int64 `json:"productId,string"` + InterestStartTime UnixTimestamp `json:"interestStartTime"` + InterestEndTime UnixTimestamp `json:"interestEndTime"` + ProductCoin string `json:"productCoin"` + SubscribeCoin string `json:"subscribeCoin"` + Trend string `json:"trend"` + SettleTime UnixTimestamp `json:"settleTime"` + InterestAmount types.Number `json:"interestAmount"` + ProductStatus string `json:"productStatus"` +} + +// SharkFinAssetsResp contains information on one's shark fin assets +type SharkFinAssetsResp struct { + ResultList []SharkFinAsset `json:"resultList"` + EndID EmptyInt `json:"endId"` } // SharkFinRecords contains information on one's shark fin records type SharkFinRecords struct { - Data struct { - ResultList []struct { - OrderID int64 `json:"orderId,string"` - Product string `json:"product"` - Period EmptyInt `json:"period"` - Amount float64 `json:"amount,string"` - Timestamp UnixTimestamp `json:"ts"` - Type string `json:"type"` - } `json:"resultList"` - } `json:"data"` + OrderID int64 `json:"orderId,string"` + Product string `json:"product"` + Period EmptyInt `json:"period"` + Amount float64 `json:"amount,string"` + Timestamp UnixTimestamp `json:"ts"` + Type string `json:"type"` } // SharkFinSubDetail contains information useful when subscribing to a shark fin product type SharkFinSubDetail struct { - Data struct { - ProductCoin string `json:"productCoin"` - SubscribeCoin string `json:"subscribeCoin"` - InterestTime UnixTimestamp `json:"interestTime"` - ExpirationTime UnixTimestamp `json:"expirationTime"` - MinPrice float64 `json:"minPrice,string"` - CurrentPrice float64 `json:"currentPrice,string"` - MaxPrice float64 `json:"maxPrice,string"` - MinRate float64 `json:"minRate,string"` - DefaultRate float64 `json:"defaultRate,string"` - MaxRate float64 `json:"maxRate,string"` - Period EmptyInt `json:"period"` - ProductMinAmount float64 `json:"productMinAmount,string"` - AvailableBalance float64 `json:"availableBalance,string"` - UserAmount float64 `json:"userAmount,string"` - RemainingAmount float64 `json:"remainingAmount,string"` - ProfitPrecision uint8 `json:"profitPrecision,string"` - SubscribePrecision uint8 `json:"subscribePrecision,string"` - } `json:"data"` + ProductCoin string `json:"productCoin"` + SubscribeCoin string `json:"subscribeCoin"` + InterestTime UnixTimestamp `json:"interestTime"` + ExpirationTime UnixTimestamp `json:"expirationTime"` + MinPrice float64 `json:"minPrice,string"` + CurrentPrice float64 `json:"currentPrice,string"` + MaxPrice float64 `json:"maxPrice,string"` + MinRate float64 `json:"minRate,string"` + DefaultRate float64 `json:"defaultRate,string"` + MaxRate float64 `json:"maxRate,string"` + Period EmptyInt `json:"period"` + ProductMinAmount float64 `json:"productMinAmount,string"` + AvailableBalance float64 `json:"availableBalance,string"` + UserAmount float64 `json:"userAmount,string"` + RemainingAmount float64 `json:"remainingAmount,string"` + ProfitPrecision uint8 `json:"profitPrecision,string"` + SubscribePrecision uint8 `json:"subscribePrecision,string"` +} + +// LoanInfos is a sub-struct containing information on loans +type LoanInfos struct { + Coin string `json:"coin"` + HourlyRate7Day float64 `json:"hourRate7D,string"` + Rate7Day float64 `json:"rate7D,string"` + HourlyRate30Day float64 `json:"hourRate30D,string"` + Rate30Day float64 `json:"rate30D,string"` + MinUSDT float64 `json:"minUsdt,string"` + MaxUSDT float64 `json:"maxUsdt,string"` + Min float64 `json:"min,string"` + Max float64 `json:"max,string"` +} + +// PledgeInfos is a sub-struct containing information on pledges +type PledgeInfos struct { + Coin string `json:"coin"` + InitialRate float64 `json:"initRate,string"` + SupplementaryRate float64 `json:"supRate,string"` + ForceRate float64 `json:"forceRate,string"` + MinUSDT float64 `json:"minUsdt,string"` + MaxUSDT float64 `json:"maxUsdt,string"` } // LoanCurList contains information on currencies which can be loaned type LoanCurList struct { - Data struct { - LoanInfos []struct { - Coin string `json:"coin"` - HourlyRate7Day float64 `json:"hourRate7D,string"` - Rate7Day float64 `json:"rate7D,string"` - HourlyRate30Day float64 `json:"hourRate30D,string"` - Rate30Day float64 `json:"rate30D,string"` - MinUSDT float64 `json:"minUsdt,string"` - MaxUSDT float64 `json:"maxUsdt,string"` - Min float64 `json:"min,string"` - Max float64 `json:"max,string"` - } `json:"loanInfos"` - PledgeInfos []struct { - Coin string `json:"coin"` - InitialRate float64 `json:"initRate,string"` - SupplementaryRate float64 `json:"supRate,string"` - ForceRate float64 `json:"forceRate,string"` - MinUSDT float64 `json:"minUsdt,string"` - MaxUSDT float64 `json:"maxUsdt,string"` - } `json:"pledgeInfos"` - } `json:"data"` + LoanInfos []LoanInfos `json:"loanInfos"` + PledgeInfos []PledgeInfos `json:"pledgeInfos"` } // EstimateInterest contains information on estimated interest payments and borrowable amounts type EstimateInterest struct { - Data struct { - HourInterest float64 `json:"hourInterest,string"` - LoanAmount float64 `json:"loanAmount,string"` - } `json:"data"` + HourInterest float64 `json:"hourInterest,string"` + LoanAmount float64 `json:"loanAmount,string"` } // BorrowResp contains information on a loan type BorrowResp struct { - Data struct { - OrderID int64 `json:"orderId,string"` - } `json:"data"` + OrderID int64 `json:"orderId,string"` } // OngoingLoans contains information on ongoing loans type OngoingLoans struct { - Data []struct { - OrderID int64 `json:"orderId,string"` - LoanCoin string `json:"loanCoin"` - LoanAmount float64 `json:"loanAmount,string"` - InterestAmount float64 `json:"interestAmount,string"` - HourInterestRate float64 `json:"hourInterestRate,string"` - PledgeCoin string `json:"pledgeCoin"` - PledgeAmount float64 `json:"pledgeAmount,string"` - SupplementaryRate float64 `json:"supRate,string"` - ForceRate float64 `json:"forceRate,string"` - BorrowTime UnixTimestamp `json:"borrowTime"` - ExpireTime UnixTimestamp `json:"expireTime"` - } `json:"data"` + OrderID int64 `json:"orderId,string"` + LoanCoin string `json:"loanCoin"` + LoanAmount float64 `json:"loanAmount,string"` + InterestAmount float64 `json:"interestAmount,string"` + HourInterestRate float64 `json:"hourInterestRate,string"` + PledgeCoin string `json:"pledgeCoin"` + PledgeAmount float64 `json:"pledgeAmount,string"` + SupplementaryRate float64 `json:"supRate,string"` + ForceRate float64 `json:"forceRate,string"` + BorrowTime UnixTimestamp `json:"borrowTime"` + ExpireTime UnixTimestamp `json:"expireTime"` } // RepayResp contains information on a repayment type RepayResp struct { - Data struct { - LoanCoin string `json:"loanCoin"` - PledgeCoin string `json:"pledgeCoin"` - RepayAmount float64 `json:"repayAmount,string"` - PayInterest float64 `json:"payInterest,string"` - RepayLoanAmount float64 `json:"repayLoanAmount,string"` - RepayUnlockAmount float64 `json:"repayUnlockAmount,string"` - } `json:"data"` + LoanCoin string `json:"loanCoin"` + PledgeCoin string `json:"pledgeCoin"` + RepayAmount float64 `json:"repayAmount,string"` + PayInterest float64 `json:"payInterest,string"` + RepayLoanAmount float64 `json:"repayLoanAmount,string"` + RepayUnlockAmount float64 `json:"repayUnlockAmount,string"` } // RepayRecords contains information on repayment records type RepayRecords struct { - Data []struct { - OrderID int64 `json:"orderId,string"` - LoanCoin string `json:"loanCoin"` - PledgeCoin string `json:"pledgeCoin"` - RepayAmount float64 `json:"repayAmount,string"` - PayInterest float64 `json:"payInterest,string"` - RepayLoanAmount float64 `json:"repayLoanAmount,string"` - RepayUnlockAmount float64 `json:"repayUnlockAmount,string"` - RepayTime UnixTimestamp `json:"repayTime"` - } `json:"data"` + OrderID int64 `json:"orderId,string"` + LoanCoin string `json:"loanCoin"` + PledgeCoin string `json:"pledgeCoin"` + RepayAmount float64 `json:"repayAmount,string"` + PayInterest float64 `json:"payInterest,string"` + RepayLoanAmount float64 `json:"repayLoanAmount,string"` + RepayUnlockAmount float64 `json:"repayUnlockAmount,string"` + RepayTime UnixTimestamp `json:"repayTime"` } // ModPledgeResp contains information on a pledge modification type ModPledgeResp struct { - Data struct { - LoanCoin string `json:"loanCoin"` - PledgeCoin string `json:"pledgeCoin"` - AfterPledgeRate float64 `json:"afterPledgeRate,string"` - } `json:"data"` + LoanCoin string `json:"loanCoin"` + PledgeCoin string `json:"pledgeCoin"` + AfterPledgeRate float64 `json:"afterPledgeRate,string"` } // PledgeRateHist contains information on historical pledge rates type PledgeRateHist struct { - Data []struct { - LoanCoin string `json:"loanCoin"` - PledgeCoin string `json:"pledgeCoin"` - OrderID int64 `json:"orderId,string"` - ReviseTime UnixTimestamp `json:"reviseTime"` - ReviseSide string `json:"reviseSide"` - ReviseAmount float64 `json:"reviseAmount,string"` - AfterPledgeRate float64 `json:"afterPledgeRate,string"` - BeforePledgeRate float64 `json:"beforePledgeRate,string"` - } `json:"data"` + LoanCoin string `json:"loanCoin"` + PledgeCoin string `json:"pledgeCoin"` + OrderID int64 `json:"orderId,string"` + ReviseTime UnixTimestamp `json:"reviseTime"` + ReviseSide string `json:"reviseSide"` + ReviseAmount float64 `json:"reviseAmount,string"` + AfterPledgeRate float64 `json:"afterPledgeRate,string"` + BeforePledgeRate float64 `json:"beforePledgeRate,string"` } // LoanHistory contains information on loans type LoanHistory struct { - Data []struct { - OrderID int64 `json:"orderId,string"` - LoanCoin string `json:"loanCoin"` - PledgeCoin string `json:"pledgeCoin"` - InitialPledgeAmount float64 `json:"initPledgeAmount,string"` - InitialLoanAmount float64 `json:"initLoanAmount,string"` - HourlyRate float64 `json:"hourRate,string"` - Daily float64 `json:"daily,string"` - BorrowTime UnixTimestamp `json:"borrowTime"` - Status string `json:"status"` - } `json:"data"` + OrderID int64 `json:"orderId,string"` + LoanCoin string `json:"loanCoin"` + PledgeCoin string `json:"pledgeCoin"` + InitialPledgeAmount float64 `json:"initPledgeAmount,string"` + InitialLoanAmount float64 `json:"initLoanAmount,string"` + HourlyRate float64 `json:"hourRate,string"` + Daily float64 `json:"daily,string"` + BorrowTime UnixTimestamp `json:"borrowTime"` + Status string `json:"status"` } // CoinAm includes fields for coins, amounts, and amount-equivalents in USDT @@ -2150,46 +2202,38 @@ type CoinAm struct { // DebtsResp contains information on debts type DebtsResp struct { - Data struct { - PledgeInfos []CoinAm `json:"pledgeInfos"` - LoanInfos []CoinAm `json:"loanInfos"` - } `json:"data"` + PledgeInfos []CoinAm `json:"pledgeInfos"` + LoanInfos []CoinAm `json:"loanInfos"` } // LiquidRecs contains information on liquidation records type LiquidRecs struct { - Data []struct { - OrderID int64 `json:"orderId,string"` - LoanCoin string `json:"loanCoin"` - PledgeCoin string `json:"pledgeCoin"` - ReduceTime UnixTimestamp `json:"reduceTime"` - PledgeRate float64 `json:"pledgeRate,string"` - PledgePrice float64 `json:"pledgePrice,string"` - Status string `json:"status"` - PledgeAmount float64 `json:"pledgeAmount,string"` - ReduceFee string `json:"reduceFee"` - ResidueAmount float64 `json:"residueAmount,string"` - RunlockAmount float64 `json:"runlockAmount,string"` - RepayLoanAmount float64 `json:"repayLoanAmount,string"` - } `json:"data"` + OrderID int64 `json:"orderId,string"` + LoanCoin string `json:"loanCoin"` + PledgeCoin string `json:"pledgeCoin"` + ReduceTime UnixTimestamp `json:"reduceTime"` + PledgeRate float64 `json:"pledgeRate,string"` + PledgePrice float64 `json:"pledgePrice,string"` + Status string `json:"status"` + PledgeAmount float64 `json:"pledgeAmount,string"` + ReduceFee string `json:"reduceFee"` + ResidueAmount float64 `json:"residueAmount,string"` + RunlockAmount float64 `json:"runlockAmount,string"` + RepayLoanAmount float64 `json:"repayLoanAmount,string"` } // WsResponse contains information on a websocket response type WsResponse struct { - Event string `json:"event"` - Code int `json:"code"` - Message string `json:"msg"` - Arg struct { - InstrumentType string `json:"instType"` - Channel string `json:"channel"` - InstrumentID string `json:"instId"` - } `json:"arg"` + Event string `json:"event"` + Code int `json:"code"` + Message string `json:"msg"` + Arg WsArgument `json:"arg"` Action string `json:"action"` Data json.RawMessage `json:"data"` Timestamp UnixTimestampNumber `json:"ts"` } -// WsArgument contains information used in a websocket request +// WsArgument contains information used in a websocket request and response type WsArgument struct { InstrumentType string `json:"instType"` Channel string `json:"channel"` @@ -2263,8 +2307,8 @@ type WsOrderBookResponse struct { Checksum int32 `json:"checksum"` } -// WsFillResponse contains information on a fill response -type WsFillResponse struct { +// WsFillSpotResponse contains information on a fill response for spot trading +type WsFillSpotResponse struct { OrderID int64 `json:"orderId,string"` TradeID int64 `json:"tradeId,string"` Symbol string `json:"symbol"` @@ -2279,8 +2323,8 @@ type WsFillResponse struct { UpdateTime UnixTimestamp `json:"uTime"` } -// WsOrderResponse contains information on an order response -type WsOrderResponse struct { +// WsOrderSpotResponse contains information on an order response for spot trading +type WsOrderSpotResponse struct { InstrumentID string `json:"instId"` OrderID int64 `json:"orderId,string"` ClientOrderID string `json:"clientOid"` @@ -2308,8 +2352,8 @@ type WsOrderResponse struct { EnterPointSource string `json:"enterPointSource"` } -// WsTriggerOrderResponse contains information on a trigger order response -type WsTriggerOrderResponse struct { +// WsTriggerOrderSpotResponse contains information on a trigger order response for spot trading +type WsTriggerOrderSpotResponse struct { InstrumentID string `json:"instId"` OrderID int64 `json:"orderId,string"` ClientOrderID string `json:"clientOid"` @@ -2339,3 +2383,143 @@ type WsAccountFuturesResponse struct { Equity float64 `json:"equity,string"` USDTEquity float64 `json:"usdtEquity,string"` } + +// WsPositionResponse contains information on a position response +type WsPositionResponse struct { + PositionID int64 `json:"posId,string"` + InstrumentID string `json:"instId"` + MarginCoin string `json:"marginCoin"` + MarginSize float64 `json:"marginSize,string"` + MarginMode string `json:"marginMode"` + HoldSide string `json:"holdSide"` + PositionMode string `json:"posMode"` + Total float64 `json:"total,string"` + Available float64 `json:"available,string"` + Frozen float64 `json:"frozen,string"` + OpenPriceAverage float64 `json:"openPriceAvg,string"` + Leverage float64 `json:"leverage,string"` + AchievedProfits float64 `json:"achievedProfits,string"` + UnrealizedProfitLoss float64 `json:"unrealizedPL,string"` + UnrealizedProfitLossRate float64 `json:"unrealizedPLR,string"` + LiquidationPrice float64 `json:"liquidationPrice,string"` + KeepMarginRate float64 `json:"keepMarginRate,string"` + MarginRate float64 `json:"marginRate,string"` + CreationTime UnixTimestamp `json:"cTime"` + BreakEvenPrice float64 `json:"breakEvenPrice,string"` + TotalFee float64 `json:"totalFee,string"` + DeductedFee float64 `json:"deductedFee,string"` + UpdateTime UnixTimestamp `json:"uTime"` + AutoMargin string `json:"autoMargin"` +} + +// WsFillFuturesResponse contains information on a fill response for futures trading +type WsFillFuturesResponse struct { + OrderID int64 `json:"orderId,string"` + TradeID int64 `json:"tradeId,string"` + Symbol string `json:"symbol"` + Side string `json:"side"` + OrderType string `json:"orderType"` + PosMode string `json:"posMode"` + Price float64 `json:"price,string"` + BaseVolume float64 `json:"baseVolume,string"` + QuoteVolume float64 `json:"quoteVolume,string"` + Profit float64 `json:"profit,string"` + TradeSide string `json:"tradeSide"` + TradeScope string `json:"tradeScope"` + FeeDetail AbridgedFeeDetail `json:"feeDetail"` + CreationTime UnixTimestamp `json:"cTime"` + UpdateTime UnixTimestamp `json:"uTime"` +} + +// WsOrderFuturesResponse contains information on an order response for futures trading +type WsOrderFuturesResponse struct { + FilledQuantity float64 `json:"accBaseVolume,string"` + CreationTime UnixTimestamp `json:"cTime"` + ClientOrderID string `json:"clientOid"` + FeeDetail FeeAndCoin `json:"feeDetail"` + FillFee float64 `json:"fillFee,string"` + FillFeeCoin string `json:"fillFeeCoin"` + FillNotionalUSD float64 `json:"fillNotionalUsd,string"` + FillPrice float64 `json:"fillPrice,string"` + BaseVolume float64 `json:"baseVolume,string"` + FillTime UnixTimestamp `json:"fillTime"` + Force string `json:"force"` + InstrumentID string `json:"instId"` + Leverage float64 `json:"leverage,string"` + MarginCoin string `json:"marginCoin"` + MarginMode string `json:"marginMode"` + NotionalUSD float64 `json:"notionalUsd,string"` + OrderID int64 `json:"orderId,string"` + OrderType string `json:"orderType"` + ProfitAndLoss float64 `json:"pnl,string"` + PositionMode string `json:"posMode"` + PositionSide string `json:"posSide"` + Price float64 `json:"price,string"` + PriceAverage float64 `json:"priceAvg,string"` + ReduceOnly YesNoBool + STPMode string `json:"stpMode"` + Side string `json:"side"` + Size float64 `json:"size,string"` + EnterPointSource string `json:"enterPointSource"` + Status string `json:"status"` + TradeScope string `json:"tradeScope"` + TradeID int64 `json:"tradeId,string"` + TradeSide string `json:"tradeSide"` + UpdateTime UnixTimestamp `json:"uTime"` +} + +// WsTriggerOrderFuturesResponse contains information on a trigger order response for futures trading +type WsTriggerOrderFuturesResponse struct { + InstrumentID string `json:"instId"` + OrderID int64 `json:"orderId,string"` + ClientOrderID string `json:"clientOid"` + TriggerPrice float64 `json:"triggerPrice,string"` + TriggerType string `json:"triggerType"` + TriggerTime UnixTimestamp `json:"triggerTime"` + PlanType string `json:"planType"` + Price float64 `json:"price,string"` + Size float64 `json:"size,string"` + ActualSize float64 `json:"actualSize,string"` + OrderType string `json:"orderType"` + Side string `json:"side"` + TradeSide string `json:"tradeSide"` + PositionSide string `json:"posSide"` + MarginCoin string `json:"marginCoin"` + Status string `json:"status"` + PositionMode string `json:"posMode"` + EnterPointSource string `json:"enterPointSource"` + StopSurplusTriggerType string `json:"stopSurplusTriggerType"` + StopLossTriggerType string `json:"stopLossTriggerType"` + STPMode string `json:"stpMode"` + CreationTime UnixTimestamp `json:"cTime"` + UpdateTime UnixTimestamp `json:"uTime"` +} + +// WsPositionHistoryResponse contains information on a position history response +type WsPositionHistoryResponse struct { + PositionID int64 `json:"posId,string"` + InstrumentID string `json:"instId"` + MarginCoin string `json:"marginCoin"` + MarginMode string `json:"marginMode"` + HoldSide string `json:"holdSide"` + PositionMode string `json:"posMode"` + OpenPriceAverage float64 `json:"openPriceAvg,string"` + ClosePriceAverage float64 `json:"closePriceAvg,string"` + OpenSize float64 `json:"openSize,string"` + CloseSize float64 `json:"closeSize,string"` + AchievedProfits float64 `json:"achievedProfits,string"` + SettleFee float64 `json:"settleFee,string"` + OpenFee float64 `json:"openFee,string"` + CloseFee float64 `json:"closeFee,string"` + CreationTime UnixTimestamp `json:"cTime"` + UpdateTime UnixTimestamp `json:"uTime"` +} + +// WsIndexPriceResponse contains information on an index price response +type WsIndexPriceResponse struct { + Symbol string `json:"symbol"` + BaseCoin string `json:"baseCoin"` + QuoteCoin string `json:"quoteCoin"` + IndexPrice float64 `json:"indexPrice,string"` + Timestamp UnixTimestamp `json:"ts"` +} diff --git a/exchanges/bitget/bitget_websocket.go b/exchanges/bitget/bitget_websocket.go index 9ac3dc8b737..eb30afc92a9 100644 --- a/exchanges/bitget/bitget_websocket.go +++ b/exchanges/bitget/bitget_websocket.go @@ -33,15 +33,35 @@ const ( bitgetPrivateWSURL = "wss://ws.bitget.com/v2/ws/private" ) -var subscriptionNames = map[string]string{ - subscription.TickerChannel: bitgetTicker, - subscription.CandlesChannel: bitgetCandleDailyChannel, - subscription.AllOrdersChannel: bitgetTrade, - subscription.OrderbookChannel: bitgetBookFullChannel, - subscription.AllTradesChannel: bitgetFillChannel, - subscription.MyOrdersChannel: bitgetOrdersChannel, - "myTriggerOrders": bitgetOrdersAlgoChannel, - "account": bitgetAccount, +var subscriptionNames = map[asset.Item]map[string]string{ + asset.Spot: { + subscription.TickerChannel: bitgetTicker, + subscription.CandlesChannel: bitgetCandleDailyChannel, + subscription.AllOrdersChannel: bitgetTrade, + subscription.OrderbookChannel: bitgetBookFullChannel, + subscription.MyTradesChannel: bitgetFillChannel, + subscription.MyOrdersChannel: bitgetOrdersChannel, + "myTriggerOrders": bitgetOrdersAlgoChannel, + "account": bitgetAccount, + }, + asset.Futures: { + subscription.TickerChannel: bitgetTicker, + subscription.CandlesChannel: bitgetCandleDailyChannel, + subscription.AllOrdersChannel: bitgetTrade, + subscription.OrderbookChannel: bitgetBookFullChannel, + subscription.MyTradesChannel: bitgetFillChannel, + subscription.MyOrdersChannel: bitgetOrdersChannel, + "myTriggerOrders": bitgetOrdersAlgoChannel, + "account": bitgetAccount, + "positions": bitgetPositionsChannel, + "positionsHistory": bitgetPositionsHistoryChannel, + }, + asset.Margin: { + "indexPrice": bitgetIndexPriceChannel, + }, + asset.CrossMargin: { + "indexPrice": bitgetIndexPriceChannel, + }, } var defaultSubscriptions = subscription.List{ @@ -53,11 +73,17 @@ var defaultSubscriptions = subscription.List{ {Enabled: false, Channel: subscription.AllOrdersChannel, Asset: asset.Futures}, {Enabled: false, Channel: subscription.OrderbookChannel, Asset: asset.Spot}, {Enabled: false, Channel: subscription.OrderbookChannel, Asset: asset.Futures}, - {Enabled: false, Channel: subscription.AllTradesChannel, Authenticated: true, Asset: asset.Spot}, + {Enabled: false, Channel: subscription.MyTradesChannel, Authenticated: true, Asset: asset.Spot}, + {Enabled: false, Channel: subscription.MyTradesChannel, Authenticated: true, Asset: asset.Futures}, {Enabled: false, Channel: subscription.MyOrdersChannel, Authenticated: true, Asset: asset.Spot}, + {Enabled: false, Channel: subscription.MyOrdersChannel, Authenticated: true, Asset: asset.Futures}, {Enabled: false, Channel: "myTriggerOrders", Authenticated: true, Asset: asset.Spot}, + {Enabled: false, Channel: "myTriggerOrders", Authenticated: true, Asset: asset.Futures}, {Enabled: false, Channel: "account", Authenticated: true, Asset: asset.Spot}, - {Enabled: true, Channel: "account", Authenticated: true, Asset: asset.Futures}, + {Enabled: false, Channel: "account", Authenticated: true, Asset: asset.Futures}, + {Enabled: false, Channel: "positions", Authenticated: true, Asset: asset.Futures}, + {Enabled: false, Channel: "positionsHistory", Authenticated: true, Asset: asset.Futures}, + {Enabled: true, Channel: "indexPrice", Asset: asset.Margin}, } // WsConnect connects to a websocket feed @@ -135,6 +161,8 @@ func (bi *Bitget) WsAuth(ctx context.Context, dialer *websocket.Dialer) error { if err != nil { return err } + // Without this, the exchange will sometimes process a subscription message before it finishes processing the login message. Might be able to reduce the duration + time.Sleep(time.Second) return nil } @@ -172,8 +200,7 @@ func (bi *Bitget) wsHandleData(respRaw []byte) error { switch toCheck { case "subscribe": if bi.Verbose { - log.Debugf(log.ExchangeSys, "%v - Websocket %v succeeded for %v\n", bi.Name, wsResponse.Event, - wsResponse.Arg) + log.Debugf(log.ExchangeSys, "%v - Websocket %v succeeded for %v\n", bi.Name, wsResponse.Event, wsResponse.Arg) } case "error": return fmt.Errorf("%v - Websocket error, code: %v message: %v", bi.Name, wsResponse.Code, wsResponse.Message) @@ -314,117 +341,297 @@ func (bi *Bitget) wsHandleData(respRaw []byte) error { } } default: - bi.Websocket.DataHandler <- stream.UnhandledMessageWarning{Message: bi.Name + stream.UnhandledMessage + - string(respRaw)} + bi.Websocket.DataHandler <- stream.UnhandledMessageWarning{Message: bi.Name + stream.UnhandledMessage + string(respRaw)} } // Plan to add handling of account.Holdings on websocketDataHandler side in a later PR bi.Websocket.DataHandler <- hold case bitgetFillChannel: - var fil []WsFillResponse - err := json.Unmarshal(wsResponse.Data, &fil) - if err != nil { - return err - } - resp := make([]fill.Data, len(fil)) - for i := range fil { - pair, err := pairFromStringHelper(fil[i].Symbol) + respAsset := itemDecoder(wsResponse.Arg.InstrumentType) + switch respAsset { + case asset.Spot: + var fil []WsFillSpotResponse + err := json.Unmarshal(wsResponse.Data, &fil) if err != nil { return err } - resp[i] = fill.Data{ - ID: strconv.FormatInt(fil[i].TradeID, 10), - Timestamp: fil[i].CreationTime.Time(), - Exchange: bi.Name, - AssetType: asset.Spot, - CurrencyPair: pair, - Side: sideDecoder(fil[i].Side), - OrderID: strconv.FormatInt(fil[i].OrderID, 10), - TradeID: strconv.FormatInt(fil[i].TradeID, 10), - Price: fil[i].PriceAverage, - Amount: fil[i].Size, + resp := make([]fill.Data, len(fil)) + for i := range fil { + pair, err := pairFromStringHelper(fil[i].Symbol) + if err != nil { + return err + } + resp[i] = fill.Data{ + ID: strconv.FormatInt(fil[i].TradeID, 10), + Timestamp: fil[i].CreationTime.Time(), + Exchange: bi.Name, + AssetType: asset.Spot, + CurrencyPair: pair, + Side: sideDecoder(fil[i].Side), + OrderID: strconv.FormatInt(fil[i].OrderID, 10), + TradeID: strconv.FormatInt(fil[i].TradeID, 10), + Price: fil[i].PriceAverage, + Amount: fil[i].Size, + } } + bi.Websocket.DataHandler <- resp + case asset.Futures: + var fil []WsFillFuturesResponse + err := json.Unmarshal(wsResponse.Data, &fil) + if err != nil { + return err + } + resp := make([]fill.Data, len(fil)) + for i := range fil { + pair, err := pairFromStringHelper(fil[i].Symbol) + if err != nil { + return err + } + resp[i] = fill.Data{ + Exchange: bi.Name, + CurrencyPair: pair, + OrderID: strconv.FormatInt(fil[i].OrderID, 10), + TradeID: strconv.FormatInt(fil[i].TradeID, 10), + Side: sideDecoder(fil[i].Side), + Price: fil[i].Price, + Amount: fil[i].BaseVolume, + Timestamp: fil[i].CreationTime.Time(), + } + } + bi.Websocket.DataHandler <- resp + default: + bi.Websocket.DataHandler <- stream.UnhandledMessageWarning{Message: bi.Name + stream.UnhandledMessage + string(respRaw)} } - bi.Websocket.DataHandler <- resp case bitgetOrdersChannel: - var orders []WsOrderResponse - err := json.Unmarshal(wsResponse.Data, &orders) - if err != nil { - return err + respAsset := itemDecoder(wsResponse.Arg.InstrumentType) + switch respAsset { + case asset.Spot: + var orders []WsOrderSpotResponse + err := json.Unmarshal(wsResponse.Data, &orders) + if err != nil { + return err + } + resp := make([]order.Detail, len(orders)) + for i := range orders { + pair, err := pairFromStringHelper(orders[i].InstrumentID) + if err != nil { + return err + } + ioc, fok, po := strategyDecoder(orders[i].Force) + var baseAmount, quoteAmount float64 + side := sideDecoder(orders[i].Side) + if side == order.Buy { + quoteAmount = orders[i].Size + } + if side == order.Sell { + baseAmount = orders[i].Size + } + orderType := typeDecoder(orders[i].OrderType) + if orderType == order.Limit { + baseAmount = orders[i].NewSize + } + resp[i] = order.Detail{ + Exchange: bi.Name, + AssetType: asset.Spot, + Pair: pair, + OrderID: strconv.FormatInt(orders[i].OrderID, 10), + ClientOrderID: orders[i].ClientOrderID, + Price: orders[i].Price, + Amount: baseAmount, + QuoteAmount: quoteAmount, + Type: orderType, + ImmediateOrCancel: ioc, + FillOrKill: fok, + PostOnly: po, + Side: side, + Fee: orders[i].FillFee, + FeeAsset: currency.NewCode(orders[i].FillFeeCoin), + AverageExecutedPrice: orders[i].PriceAverage, + Status: statusDecoder(orders[i].Status), + Date: orders[i].CreationTime.Time(), + LastUpdated: orders[i].UpdateTime.Time(), + } + } + bi.Websocket.DataHandler <- resp + case asset.Futures: + var orders []WsOrderFuturesResponse + err := json.Unmarshal(wsResponse.Data, &orders) + if err != nil { + return err + } + resp := make([]order.Detail, len(orders)) + for i := range orders { + pair, err := pairFromStringHelper(orders[i].InstrumentID) + if err != nil { + return err + } + ioc, fok, po := strategyDecoder(orders[i].Force) + var baseAmount, quoteAmount float64 + side := sideDecoder(orders[i].Side) + if side == order.Buy { + quoteAmount = orders[i].Size + } + if side == order.Sell { + baseAmount = orders[i].Size + } + orderType := typeDecoder(orders[i].OrderType) + if orderType == order.Limit { + baseAmount = orders[i].BaseVolume + } + resp[i] = order.Detail{ + Exchange: bi.Name, + AssetType: asset.Futures, + Pair: pair, + Amount: baseAmount, + QuoteAmount: quoteAmount, + Type: orderType, + ImmediateOrCancel: ioc, + FillOrKill: fok, + PostOnly: po, + Side: side, + ExecutedAmount: orders[i].FilledQuantity, + Date: orders[i].CreationTime.Time(), + ClientOrderID: orders[i].ClientOrderID, + Fee: orders[i].FillFee, + FeeAsset: currency.NewCode(orders[i].FillFeeCoin), + Leverage: orders[i].Leverage, + MarginType: marginDecoder(orders[i].MarginMode), + OrderID: strconv.FormatInt(orders[i].OrderID, 10), + Price: orders[i].Price, + AverageExecutedPrice: orders[i].PriceAverage, + ReduceOnly: bool(orders[i].ReduceOnly), + Status: statusDecoder(orders[i].Status), + LastUpdated: orders[i].UpdateTime.Time(), + } + } + bi.Websocket.DataHandler <- resp + default: + bi.Websocket.DataHandler <- stream.UnhandledMessageWarning{Message: bi.Name + stream.UnhandledMessage + string(respRaw)} } - resp := make([]order.Detail, len(orders)) - for i := range orders { - pair, err := pairFromStringHelper(orders[i].InstrumentID) + case bitgetOrdersAlgoChannel: + respAsset := itemDecoder(wsResponse.Arg.InstrumentType) + switch respAsset { + case asset.Spot: + var orders []WsTriggerOrderSpotResponse + err := json.Unmarshal(wsResponse.Data, &orders) if err != nil { return err } - ioc, fok, po := strategyDecoder(orders[i].Force) - var baseAmount, quoteAmount float64 - side := sideDecoder(orders[i].Side) - if side == order.Buy { - quoteAmount = orders[i].Size + resp := make([]order.Detail, len(orders)) + for i := range orders { + pair, err := pairFromStringHelper(orders[i].InstrumentID) + if err != nil { + return err + } + resp[i] = order.Detail{ + Exchange: bi.Name, + AssetType: asset.Spot, + Pair: pair, + OrderID: strconv.FormatInt(orders[i].OrderID, 10), + ClientOrderID: orders[i].ClientOrderID, + TriggerPrice: orders[i].TriggerPrice, + Price: orders[i].Price, + Amount: orders[i].Size, + Type: typeDecoder(orders[i].OrderType), + Side: sideDecoder(orders[i].Side), + Status: statusDecoder(orders[i].Status), + Date: orders[i].CreationTime.Time(), + LastUpdated: orders[i].UpdateTime.Time(), + } } - if side == order.Sell { - baseAmount = orders[i].Size + bi.Websocket.DataHandler <- resp + case asset.Futures: + var orders []WsTriggerOrderFuturesResponse + err := json.Unmarshal(wsResponse.Data, &orders) + if err != nil { + return err } - orderType := typeDecoder(orders[i].OrderType) - if orderType == order.Limit { - baseAmount = orders[i].NewSize + resp := make([]order.Detail, len(orders)) + for i := range orders { + pair, err := pairFromStringHelper(orders[i].InstrumentID) + if err != nil { + return err + } + resp[i] = order.Detail{ + Exchange: bi.Name, + AssetType: asset.Futures, + Pair: pair, + OrderID: strconv.FormatInt(orders[i].OrderID, 10), + ClientOrderID: orders[i].ClientOrderID, + TriggerPrice: orders[i].TriggerPrice, + Price: orders[i].Price, + Amount: orders[i].Size, + Type: typeDecoder(orders[i].OrderType), + Side: sideDecoder(orders[i].Side), + Status: statusDecoder(orders[i].Status), + Date: orders[i].CreationTime.Time(), + LastUpdated: orders[i].UpdateTime.Time(), + } + } + bi.Websocket.DataHandler <- resp + default: + bi.Websocket.DataHandler <- stream.UnhandledMessageWarning{Message: bi.Name + stream.UnhandledMessage + string(respRaw)} + } + case bitgetPositionsChannel: + var positions []WsPositionResponse + err := json.Unmarshal(wsResponse.Data, &positions) + if err != nil { + return err + } + resp := make([]order.Detail, len(positions)) + for i := range positions { + pair, err := pairFromStringHelper(positions[i].InstrumentID) + if err != nil { + return err } resp[i] = order.Detail{ Exchange: bi.Name, - AssetType: asset.Spot, + AssetType: asset.Futures, Pair: pair, - OrderID: strconv.FormatInt(orders[i].OrderID, 10), - ClientOrderID: orders[i].ClientOrderID, - Price: orders[i].Price, - Amount: baseAmount, - QuoteAmount: quoteAmount, - Type: orderType, - ImmediateOrCancel: ioc, - FillOrKill: fok, - PostOnly: po, - Side: side, - Fee: orders[i].FillFee, - FeeAsset: currency.NewCode(orders[i].FillFeeCoin), - AverageExecutedPrice: orders[i].PriceAverage, - Status: statusDecoder(orders[i].Status), - Date: orders[i].CreationTime.Time(), - LastUpdated: orders[i].UpdateTime.Time(), + OrderID: strconv.FormatInt(positions[i].PositionID, 10), + MarginType: marginDecoder(positions[i].MarginMode), + Side: sideDecoder(positions[i].HoldSide), + Amount: positions[i].Total, + AverageExecutedPrice: positions[i].OpenPriceAverage, + Leverage: positions[i].Leverage, + Date: positions[i].CreationTime.Time(), + Fee: positions[i].TotalFee, + LastUpdated: positions[i].UpdateTime.Time(), } } bi.Websocket.DataHandler <- resp - case bitgetOrdersAlgoChannel: - var orders []WsTriggerOrderResponse - err := json.Unmarshal(wsResponse.Data, &orders) + case bitgetPositionsHistoryChannel: + var positions []WsPositionHistoryResponse + err := json.Unmarshal(wsResponse.Data, &positions) if err != nil { return err } - resp := make([]order.Detail, len(orders)) - for i := range orders { - pair, err := pairFromStringHelper(orders[i].InstrumentID) + resp := make([]order.Detail, len(positions)) + for i := range positions { + pair, err := pairFromStringHelper(positions[i].InstrumentID) if err != nil { return err } resp[i] = order.Detail{ - Exchange: bi.Name, - AssetType: asset.Spot, - Pair: pair, - OrderID: strconv.FormatInt(orders[i].OrderID, 10), - ClientOrderID: orders[i].ClientOrderID, - TriggerPrice: orders[i].TriggerPrice, - Price: orders[i].Price, - Amount: orders[i].Size, - Type: typeDecoder(orders[i].OrderType), - Side: sideDecoder(orders[i].Side), - Status: statusDecoder(orders[i].Status), - Date: orders[i].CreationTime.Time(), - LastUpdated: orders[i].UpdateTime.Time(), + Exchange: bi.Name, + AssetType: asset.Futures, + Pair: pair, + OrderID: strconv.FormatInt(positions[i].PositionID, 10), + MarginType: marginDecoder(positions[i].MarginMode), + Side: sideDecoder(positions[i].HoldSide), + AverageExecutedPrice: positions[i].OpenPriceAverage, + Date: positions[i].CreationTime.Time(), + LastUpdated: positions[i].UpdateTime.Time(), } } bi.Websocket.DataHandler <- resp + case bitgetIndexPriceChannel: + // var indexPrice []WsIndexPriceResponse + // err := json.Unmarshal(wsResponse.Data, &indexPrice) + // if err != nil { + // return err + // } default: - bi.Websocket.DataHandler <- stream.UnhandledMessageWarning{Message: bi.Name + stream.UnhandledMessage + - string(respRaw)} + bi.Websocket.DataHandler <- stream.UnhandledMessageWarning{Message: bi.Name + stream.UnhandledMessage + string(respRaw)} } case "update": switch wsResponse.Arg.Channel { @@ -526,16 +733,13 @@ func (bi *Bitget) wsHandleData(respRaw []byte) error { } bi.Websocket.DataHandler <- resp default: - bi.Websocket.DataHandler <- stream.UnhandledMessageWarning{Message: bi.Name + stream.UnhandledMessage + - string(respRaw)} + bi.Websocket.DataHandler <- stream.UnhandledMessageWarning{Message: bi.Name + stream.UnhandledMessage + string(respRaw)} } default: - bi.Websocket.DataHandler <- stream.UnhandledMessageWarning{Message: bi.Name + stream.UnhandledMessage + - string(respRaw)} + bi.Websocket.DataHandler <- stream.UnhandledMessageWarning{Message: bi.Name + stream.UnhandledMessage + string(respRaw)} } default: - bi.Websocket.DataHandler <- stream.UnhandledMessageWarning{Message: bi.Name + stream.UnhandledMessage + - string(respRaw)} + bi.Websocket.DataHandler <- stream.UnhandledMessageWarning{Message: bi.Name + stream.UnhandledMessage + string(respRaw)} } return nil } @@ -676,9 +880,9 @@ func (bi *Bitget) generateDefaultSubscriptions() (subscription.List, error) { } subs = subs[:len(subs):len(subs)] for i := range subs { - subs[i].Channel = subscriptionNames[subs[i].Channel] + subs[i].Channel = subscriptionNames[subs[i].Asset][subs[i].Channel] switch subs[i].Channel { - case bitgetAccount, bitgetFillChannel: + case bitgetAccount, bitgetFillChannel, bitgetPositionsChannel, bitgetPositionsHistoryChannel: default: subs[i].Pairs = enabledPairs } @@ -722,6 +926,28 @@ func (bi *Bitget) reqBuilder(req *WsRequest, sub *subscription.Subscription) { InstrumentID: sub.Pairs[i].String(), }) } + if len(sub.Pairs) == 0 { + req.Arguments = append(req.Arguments, WsArgument{ + Channel: sub.Channel, + InstrumentType: itemEncoder(sub.Asset, currency.Pair{}), + Coin: "default", + InstrumentID: "default", + }) + if sub.Asset == asset.Futures { + req.Arguments = append(req.Arguments, WsArgument{ + Channel: sub.Channel, + InstrumentType: "USDT-FUTURES", + Coin: "default", + InstrumentID: "default", + }) + req.Arguments = append(req.Arguments, WsArgument{ + Channel: sub.Channel, + InstrumentType: "USDC-FUTURES", + Coin: "default", + InstrumentID: "default", + }) + } + } } // websocketMessage sends a websocket message @@ -732,29 +958,7 @@ func (bi *Bitget) websocketMessage(subs subscription.List, op string) error { authBase := &WsRequest{ Operation: op, } -forloop: for _, s := range subs { - switch s.Channel { - case bitgetAccount, bitgetFillChannel: - authBase.Arguments = append(authBase.Arguments, WsArgument{ - Channel: s.Channel, - InstrumentType: itemEncoder(s.Asset, currency.Pair{}), - Coin: "default", - }) - if s.Asset == asset.Futures { - authBase.Arguments = append(authBase.Arguments, WsArgument{ - Channel: s.Channel, - InstrumentType: "USDT-FUTURES", - Coin: "default", - }) - authBase.Arguments = append(authBase.Arguments, WsArgument{ - Channel: s.Channel, - InstrumentType: "USDC-FUTURES", - Coin: "default", - }) - } - continue forloop // Could be removed, and this case turned into an if statement, if no other channels have special cases - } if s.Authenticated { bi.reqBuilder(authBase, s) } else { @@ -805,6 +1009,8 @@ func itemEncoder(a asset.Item, pair currency.Pair) string { return "SPOT" case asset.Futures: return getProductType(pair) + case asset.Margin, asset.CrossMargin: + return "MARGIN" } return "" } @@ -815,7 +1021,7 @@ func (bi *Bitget) GetSubscriptionTemplate(_ *subscription.Subscription) (*templa } func channelName(s *subscription.Subscription) string { - if n, ok := subscriptionNames[s.Channel]; ok { + if n, ok := subscriptionNames[s.Asset][s.Channel]; ok { return n } // Replace error with subscription.ErrNotSupported after merge diff --git a/exchanges/bitget/bitget_wrapper.go b/exchanges/bitget/bitget_wrapper.go index a2ef7ed16d6..745e1f51bbe 100644 --- a/exchanges/bitget/bitget_wrapper.go +++ b/exchanges/bitget/bitget_wrapper.go @@ -118,9 +118,7 @@ func (bi *Bitget) SetDefaults() { }, } // NOTE: SET THE EXCHANGES RATE LIMIT HERE - bi.Requester, err = request.New(bi.Name, - common.NewHTTPClientWithTimeout(exchange.DefaultHTTPTimeout), - request.WithLimiter(GetRateLimits())) + bi.Requester, err = request.New(bi.Name, common.NewHTTPClientWithTimeout(exchange.DefaultHTTPTimeout), request.WithLimiter(GetRateLimits())) if err != nil { log.Errorln(log.ExchangeSys, err) } @@ -488,8 +486,7 @@ func (bi *Bitget) UpdateAccountInfo(ctx context.Context, assetType asset.Item) ( acc.Accounts[0].Currencies = make([]account.Balance, len(resp)) for x := range resp { acc.Accounts[0].Currencies[x].Currency = currency.NewCode(resp[x].Coin) - acc.Accounts[0].Currencies[x].Hold = resp[x].Frozen + resp[x].Locked + - resp[x].LimitAvailable + acc.Accounts[0].Currencies[x].Hold = resp[x].Frozen + resp[x].Locked + resp[x].LimitAvailable acc.Accounts[0].Currencies[x].Total = resp[x].Available + acc.Accounts[0].Currencies[x].Hold acc.Accounts[0].Currencies[x].Free = resp[x].Available } @@ -514,13 +511,13 @@ func (bi *Bitget) UpdateAccountInfo(ctx context.Context, assetType asset.Item) ( return acc, err } acc.Accounts = make([]account.SubAccount, 1) - acc.Accounts[0].Currencies = make([]account.Balance, len(resp.Data)) - for x := range resp.Data { - acc.Accounts[0].Currencies[x].Currency = currency.NewCode(resp.Data[x].Coin) - acc.Accounts[0].Currencies[x].Hold = resp.Data[x].Frozen - acc.Accounts[0].Currencies[x].Total = resp.Data[x].TotalAmount - acc.Accounts[0].Currencies[x].Free = resp.Data[x].Available - acc.Accounts[0].Currencies[x].Borrowed = resp.Data[x].Borrow + acc.Accounts[0].Currencies = make([]account.Balance, len(resp)) + for x := range resp { + acc.Accounts[0].Currencies[x].Currency = currency.NewCode(resp[x].Coin) + acc.Accounts[0].Currencies[x].Hold = resp[x].Frozen + acc.Accounts[0].Currencies[x].Total = resp[x].TotalAmount + acc.Accounts[0].Currencies[x].Free = resp[x].Available + acc.Accounts[0].Currencies[x].Borrowed = resp[x].Borrow } case asset.CrossMargin: resp, err := bi.GetCrossAccountAssets(ctx, "") @@ -723,8 +720,7 @@ func (bi *Bitget) GetHistoricTrades(ctx context.Context, p currency.Pair, assetT } return trades, nil case asset.Futures: - resp, err := bi.GetFuturesMarketTrades(ctx, p.String(), getProductType(p), 1000, 0, timestampStart, - timestampEnd) + resp, err := bi.GetFuturesMarketTrades(ctx, p.String(), getProductType(p), 1000, 0, timestampStart, timestampEnd) if err != nil { return nil, err } @@ -769,23 +765,18 @@ func (bi *Bitget) SubmitOrder(ctx context.Context, s *order.Submit) (*order.Subm } switch s.AssetType { case asset.Spot: - IDs, err = bi.PlaceSpotOrder(ctx, s.Pair.String(), s.Side.String(), s.Type.Lower(), strat, cID.String(), - s.Price, s.Amount, false) + IDs, err = bi.PlaceSpotOrder(ctx, s.Pair.String(), s.Side.String(), s.Type.Lower(), strat, cID.String(), s.Price, s.Amount, false) case asset.Futures: - IDs, err = bi.PlaceFuturesOrder(ctx, s.Pair.String(), getProductType(s.Pair), marginStringer(s.MarginType), - s.Pair.Quote.String(), sideEncoder(s.Side, false), "", s.Type.Lower(), strat, cID.String(), 0, 0, - s.Amount, s.Price, s.ReduceOnly, false) + IDs, err = bi.PlaceFuturesOrder(ctx, s.Pair.String(), getProductType(s.Pair), marginStringer(s.MarginType), s.Pair.Quote.String(), sideEncoder(s.Side, false), "", s.Type.Lower(), strat, cID.String(), 0, 0, s.Amount, s.Price, s.ReduceOnly, false) case asset.Margin, asset.CrossMargin: loanType := "normal" if s.AutoBorrow { loanType = "autoLoan" } if s.AssetType == asset.Margin { - IDs, err = bi.PlaceIsolatedOrder(ctx, s.Pair.String(), s.Type.Lower(), loanType, strat, - cID.String(), s.Side.String(), s.Price, s.Amount, s.QuoteAmount) + IDs, err = bi.PlaceIsolatedOrder(ctx, s.Pair.String(), s.Type.Lower(), loanType, strat, cID.String(), s.Side.String(), s.Price, s.Amount, s.QuoteAmount) } else { - IDs, err = bi.PlaceCrossOrder(ctx, s.Pair.String(), s.Type.Lower(), loanType, strat, cID.String(), - s.Side.String(), s.Price, s.Amount, s.QuoteAmount) + IDs, err = bi.PlaceCrossOrder(ctx, s.Pair.String(), s.Type.Lower(), loanType, strat, cID.String(), s.Side.String(), s.Price, s.Amount, s.QuoteAmount) } default: return nil, asset.ErrNotSupported @@ -793,7 +784,7 @@ func (bi *Bitget) SubmitOrder(ctx context.Context, s *order.Submit) (*order.Subm if err != nil { return nil, err } - resp, err := s.DeriveSubmitResponse(strconv.FormatInt(IDs.Data.OrderID, 10)) + resp, err := s.DeriveSubmitResponse(strconv.FormatInt(int64(IDs.Data.OrderID), 10)) if err != nil { return nil, err } @@ -815,16 +806,14 @@ func (bi *Bitget) ModifyOrder(ctx context.Context, action *order.Modify) (*order } switch action.AssetType { case asset.Spot: - IDs, err = bi.ModifyPlanSpotOrder(ctx, originalID, action.ClientOrderID, action.Type.String(), - action.TriggerPrice, action.Price, action.Amount) + IDs, err = bi.ModifyPlanSpotOrder(ctx, originalID, action.ClientOrderID, action.Type.String(), action.TriggerPrice, action.Price, action.Amount) case asset.Futures: var cID uuid.UUID cID, err = uuid.DefaultGenerator.NewV4() if err != nil { return nil, err } - IDs, err = bi.ModifyFuturesOrder(ctx, originalID, action.ClientOrderID, action.Pair.String(), - getProductType(action.Pair), cID.String(), action.Amount, action.Price, 0, 0) + IDs, err = bi.ModifyFuturesOrder(ctx, originalID, action.ClientOrderID, action.Pair.String(), getProductType(action.Pair), cID.String(), action.Amount, action.Price, 0, 0) fmt.Printf("Error: %v\n", err) default: return nil, asset.ErrNotSupported @@ -836,7 +825,7 @@ func (bi *Bitget) ModifyOrder(ctx context.Context, action *order.Modify) (*order if err != nil { return nil, err } - resp.OrderID = strconv.FormatInt(IDs.Data.OrderID, 10) + resp.OrderID = strconv.FormatInt(int64(IDs.Data.OrderID), 10) resp.ClientOrderID = IDs.Data.ClientOrderID return resp, nil } @@ -855,8 +844,7 @@ func (bi *Bitget) CancelOrder(ctx context.Context, ord *order.Cancel) error { case asset.Spot: _, err = bi.CancelSpotOrderByID(ctx, ord.Pair.String(), ord.ClientOrderID, originalID) case asset.Futures: - _, err = bi.CancelFuturesOrder(ctx, ord.Pair.String(), getProductType(ord.Pair), ord.Pair.Quote.String(), - ord.ClientOrderID, originalID) + _, err = bi.CancelFuturesOrder(ctx, ord.Pair.String(), getProductType(ord.Pair), ord.Pair.Quote.String(), ord.ClientOrderID, originalID) case asset.Margin: _, err = bi.CancelIsolatedOrder(ctx, ord.Pair.String(), ord.ClientOrderID, originalID) case asset.CrossMargin: @@ -889,8 +877,7 @@ func (bi *Bitget) CancelBatchOrders(ctx context.Context, orders []order.Cancel) case asset.Spot: status, err = bi.BatchCancelOrders(ctx, pair.String(), batch) case asset.Futures: - status, err = bi.BatchCancelFuturesOrders(ctx, batch, pair.String(), getProductType(pair), - pair.Quote.String()) + status, err = bi.BatchCancelFuturesOrders(ctx, batch, pair.String(), getProductType(pair), pair.Quote.String()) case asset.Margin: status, err = bi.BatchCancelIsolatedOrders(ctx, pair.String(), batch) case asset.CrossMargin: @@ -933,8 +920,7 @@ func (bi *Bitget) CancelAllOrders(ctx context.Context, orderCancellation *order. } for i := range resp2.FailureList { resp.Status[resp2.FailureList[i].ClientOrderID] = resp2.FailureList[i].ErrorMessage - resp.Status[strconv.FormatInt(int64(resp2.FailureList[i].OrderID), 10)] = - resp2.FailureList[i].ErrorMessage + resp.Status[strconv.FormatInt(int64(resp2.FailureList[i].OrderID), 10)] = resp2.FailureList[i].ErrorMessage } default: return resp, asset.ErrNotSupported @@ -1021,8 +1007,7 @@ func (bi *Bitget) GetOrderInfo(ctx context.Context, orderID string, pair currenc resp.ReduceOnly = bool(ordInfo.ReduceOnly) resp.Date = ordInfo.CreationTime.Time() resp.LastUpdated = ordInfo.UpdateTime.Time() - fillInfo, err := bi.GetFuturesFills(ctx, ordID, 0, 100, pair.String(), getProductType(pair), time.Time{}, - time.Time{}) + fillInfo, err := bi.GetFuturesFills(ctx, ordID, 0, 100, pair.String(), getProductType(pair), time.Time{}, time.Time{}) if err != nil { return nil, err } @@ -1051,15 +1036,13 @@ func (bi *Bitget) GetOrderInfo(ctx context.Context, orderID string, pair currenc if err != nil { return nil, err } - fillInfo, err = bi.GetIsolatedOrderFills(ctx, pair.String(), ordID, 0, 500, - time.Now().Add(-time.Hour*24*90), time.Now()) + fillInfo, err = bi.GetIsolatedOrderFills(ctx, pair.String(), ordID, 0, 500, time.Now().Add(-time.Hour*24*90), time.Now()) } else { ordInfo, err = bi.GetCrossOpenOrders(ctx, pair.String(), "", ordID, 2, 0, time.Time{}, time.Time{}) if err != nil { return nil, err } - fillInfo, err = bi.GetCrossOrderFills(ctx, pair.String(), ordID, 0, 500, - time.Now().Add(-time.Hour*24*90), time.Now()) + fillInfo, err = bi.GetCrossOrderFills(ctx, pair.String(), ordID, 0, 500, time.Now().Add(-time.Hour*24*90), time.Now()) } if err != nil { return nil, err @@ -1117,14 +1100,12 @@ func (bi *Bitget) WithdrawCryptocurrencyFunds(ctx context.Context, withdrawReque if err != nil { return nil, err } - resp, err := bi.WithdrawFunds(ctx, withdrawRequest.Currency.String(), "on_chain", - withdrawRequest.Crypto.Address, withdrawRequest.Crypto.Chain, "", "", withdrawRequest.Crypto.AddressTag, - withdrawRequest.Description, "", withdrawRequest.Amount) + resp, err := bi.WithdrawFunds(ctx, withdrawRequest.Currency.String(), "on_chain", withdrawRequest.Crypto.Address, withdrawRequest.Crypto.Chain, "", "", withdrawRequest.Crypto.AddressTag, withdrawRequest.Description, "", withdrawRequest.Amount) if err != nil { return nil, err } ret := &withdraw.ExchangeResponse{ - ID: strconv.FormatInt(resp.Data.OrderID, 10), + ID: strconv.FormatInt(int64(resp.Data.OrderID), 10), } return ret, nil } @@ -1224,8 +1205,7 @@ func (bi *Bitget) GetActiveOrders(ctx context.Context, getOrdersRequest *order.M } case asset.Futures: if pairs[x] != "" { - resp, err = bi.activeFuturesOrderHelper(ctx, pairs[x], getProductType(getOrdersRequest.Pairs[x]), - getOrdersRequest.Pairs[x], resp) + resp, err = bi.activeFuturesOrderHelper(ctx, pairs[x], getProductType(getOrdersRequest.Pairs[x]), getOrdersRequest.Pairs[x], resp) if err != nil { return nil, err } @@ -1242,11 +1222,9 @@ func (bi *Bitget) GetActiveOrders(ctx context.Context, getOrdersRequest *order.M var genOrds *MarginOpenOrds for { if getOrdersRequest.AssetType == asset.Margin { - genOrds, err = bi.GetIsolatedOpenOrders(ctx, pairs[x], "", 0, 500, pagination, - time.Now().Add(-time.Hour*24*90), time.Time{}) + genOrds, err = bi.GetIsolatedOpenOrders(ctx, pairs[x], "", 0, 500, pagination, time.Now().Add(-time.Hour*24*90), time.Time{}) } else { - genOrds, err = bi.GetCrossOpenOrders(ctx, pairs[x], "", 0, 500, pagination, - time.Now().Add(-time.Hour*24*90), time.Time{}) + genOrds, err = bi.GetCrossOpenOrders(ctx, pairs[x], "", 0, 500, pagination, time.Now().Add(-time.Hour*24*90), time.Time{}) } if err != nil { return nil, err @@ -1279,8 +1257,7 @@ func (bi *Bitget) GetActiveOrders(ctx context.Context, getOrdersRequest *order.M return nil, err } } - tempOrds[i].ImmediateOrCancel, tempOrds[i].FillOrKill, tempOrds[i].PostOnly = - strategyDecoder(genOrds.OrderList[i].Force) + tempOrds[i].ImmediateOrCancel, tempOrds[i].FillOrKill, tempOrds[i].PostOnly = strategyDecoder(genOrds.OrderList[i].Force) } resp = append(resp, tempOrds...) } @@ -1334,21 +1311,18 @@ func (bi *Bitget) GetOrderHistory(ctx context.Context, getOrdersRequest *order.M if err != nil { return nil, err } - resp, err = bi.spotHistoricPlanOrdersHelper(ctx, callStr.String(), newPairs[y], resp, - fillMap) + resp, err = bi.spotHistoricPlanOrdersHelper(ctx, callStr.String(), newPairs[y], resp, fillMap) if err != nil { return nil, err } } } for { - genOrds, err := bi.GetHistoricalSpotOrders(ctx, pairs[x], time.Time{}, time.Time{}, 100, pagination, - 0) + genOrds, err := bi.GetHistoricalSpotOrders(ctx, pairs[x], time.Time{}, time.Time{}, 100, pagination, 0) if err != nil { return nil, err } - if len(genOrds) == 0 || - pagination == int64(genOrds[len(genOrds)-1].OrderID) { + if len(genOrds) == 0 || pagination == int64(genOrds[len(genOrds)-1].OrderID) { break } pagination = int64(genOrds[len(genOrds)-1].OrderID) @@ -1390,8 +1364,7 @@ func (bi *Bitget) GetOrderHistory(ctx context.Context, getOrdersRequest *order.M } case asset.Futures: if pairs[x] != "" { - resp, err = bi.historicalFuturesOrderHelper(ctx, pairs[x], - getProductType(getOrdersRequest.Pairs[x]), getOrdersRequest.Pairs[x], resp) + resp, err = bi.historicalFuturesOrderHelper(ctx, pairs[x], getProductType(getOrdersRequest.Pairs[x]), getOrdersRequest.Pairs[x], resp) if err != nil { return nil, err } @@ -1409,11 +1382,9 @@ func (bi *Bitget) GetOrderHistory(ctx context.Context, getOrdersRequest *order.M fillMap := make(map[int64][]order.TradeHistory) for { if getOrdersRequest.AssetType == asset.Margin { - genFills, err = bi.GetIsolatedOrderFills(ctx, pairs[x], 0, pagination, 500, - time.Now().Add(-time.Hour*24*90), time.Now()) + genFills, err = bi.GetIsolatedOrderFills(ctx, pairs[x], 0, pagination, 500, time.Now().Add(-time.Hour*24*90), time.Now()) } else { - genFills, err = bi.GetCrossOrderFills(ctx, pairs[x], 0, pagination, 500, - time.Now().Add(-time.Hour*24*90), time.Now()) + genFills, err = bi.GetCrossOrderFills(ctx, pairs[x], 0, pagination, 500, time.Now().Add(-time.Hour*24*90), time.Now()) } if err != nil { return nil, err @@ -1423,28 +1394,25 @@ func (bi *Bitget) GetOrderHistory(ctx context.Context, getOrdersRequest *order.M } pagination = int64(genFills.MaxID) for i := range genFills.Fills { - fillMap[genFills.Fills[i].TradeID] = append(fillMap[genFills.Fills[i].TradeID], - order.TradeHistory{ - TID: strconv.FormatInt(genFills.Fills[i].TradeID, 10), - Type: typeDecoder(genFills.Fills[i].OrderType), - Side: sideDecoder(genFills.Fills[i].Side), - Price: genFills.Fills[i].PriceAverage, - Amount: genFills.Fills[i].Size, - Timestamp: genFills.Fills[i].CreationTime.Time(), - Fee: genFills.Fills[i].FeeDetail.TotalFee, - FeeAsset: genFills.Fills[i].FeeDetail.FeeCoin, - }) + fillMap[genFills.Fills[i].TradeID] = append(fillMap[genFills.Fills[i].TradeID], order.TradeHistory{ + TID: strconv.FormatInt(genFills.Fills[i].TradeID, 10), + Type: typeDecoder(genFills.Fills[i].OrderType), + Side: sideDecoder(genFills.Fills[i].Side), + Price: genFills.Fills[i].PriceAverage, + Amount: genFills.Fills[i].Size, + Timestamp: genFills.Fills[i].CreationTime.Time(), + Fee: genFills.Fills[i].FeeDetail.TotalFee, + FeeAsset: genFills.Fills[i].FeeDetail.FeeCoin, + }) } } pagination = 0 var genOrds *MarginHistOrds for { if getOrdersRequest.AssetType == asset.Margin { - genOrds, err = bi.GetIsolatedHistoricalOrders(ctx, pairs[x], "", "", 0, 500, pagination, - time.Now().Add(-time.Hour*24*90), time.Time{}) + genOrds, err = bi.GetIsolatedHistoricalOrders(ctx, pairs[x], "", "", 0, 500, pagination, time.Now().Add(-time.Hour*24*90), time.Time{}) } else { - genOrds, err = bi.GetCrossHistoricalOrders(ctx, pairs[x], "", "", 0, 500, pagination, - time.Now().Add(-time.Hour*24*90), time.Time{}) + genOrds, err = bi.GetCrossHistoricalOrders(ctx, pairs[x], "", "", 0, 500, pagination, time.Now().Add(-time.Hour*24*90), time.Time{}) } if err != nil { return nil, err @@ -1478,8 +1446,7 @@ func (bi *Bitget) GetOrderHistory(ctx context.Context, getOrdersRequest *order.M return nil, err } } - tempOrds[i].ImmediateOrCancel, tempOrds[i].FillOrKill, tempOrds[i].PostOnly = - strategyDecoder(genOrds.OrderList[i].Force) + tempOrds[i].ImmediateOrCancel, tempOrds[i].FillOrKill, tempOrds[i].PostOnly = strategyDecoder(genOrds.OrderList[i].Force) if len(fillMap[int64(genOrds.OrderList[i].OrderID)]) > 0 { tempOrds[i].Trades = fillMap[int64(genOrds.OrderList[i].OrderID)] } @@ -1523,8 +1490,7 @@ func (bi *Bitget) GetHistoricCandles(ctx context.Context, pair currency.Pair, a var resp []kline.Candle switch a { case asset.Spot, asset.Margin, asset.CrossMargin: - cndl, err := bi.GetSpotCandlestickData(ctx, req.RequestFormatted.String(), - formatExchangeKlineIntervalSpot(req.ExchangeInterval), req.Start, req.End, 200, true) + cndl, err := bi.GetSpotCandlestickData(ctx, req.RequestFormatted.String(), formatExchangeKlineIntervalSpot(req.ExchangeInterval), req.Start, req.End, 200, true) if err != nil { return nil, err } @@ -1540,8 +1506,7 @@ func (bi *Bitget) GetHistoricCandles(ctx context.Context, pair currency.Pair, a } } case asset.Futures: - cndl, err := bi.GetFuturesCandlestickData(ctx, req.RequestFormatted.String(), getProductType(pair), - formatExchangeKlineIntervalFutures(req.ExchangeInterval), req.Start, req.End, 200, CallModeHistory) + cndl, err := bi.GetFuturesCandlestickData(ctx, req.RequestFormatted.String(), getProductType(pair), formatExchangeKlineIntervalFutures(req.ExchangeInterval), req.Start, req.End, 200, CallModeHistory) if err != nil { return nil, err } @@ -1572,9 +1537,7 @@ func (bi *Bitget) GetHistoricCandlesExtended(ctx context.Context, pair currency. for x := range req.RangeHolder.Ranges { switch a { case asset.Spot, asset.Margin, asset.CrossMargin: - cndl, err := bi.GetSpotCandlestickData(ctx, req.RequestFormatted.String(), - formatExchangeKlineIntervalSpot(req.ExchangeInterval), req.RangeHolder.Ranges[x].Start.Time, - req.RangeHolder.Ranges[x].End.Time, 200, true) + cndl, err := bi.GetSpotCandlestickData(ctx, req.RequestFormatted.String(), formatExchangeKlineIntervalSpot(req.ExchangeInterval), req.RangeHolder.Ranges[x].Start.Time, req.RangeHolder.Ranges[x].End.Time, 200, true) if err != nil { return nil, err } @@ -1591,9 +1554,7 @@ func (bi *Bitget) GetHistoricCandlesExtended(ctx context.Context, pair currency. } resp = append(resp, temp...) case asset.Futures: - cndl, err := bi.GetFuturesCandlestickData(ctx, req.RequestFormatted.String(), getProductType(pair), - formatExchangeKlineIntervalFutures(req.ExchangeInterval), req.RangeHolder.Ranges[x].Start.Time, - req.RangeHolder.Ranges[x].End.Time, 200, CallModeHistory) + cndl, err := bi.GetFuturesCandlestickData(ctx, req.RequestFormatted.String(), getProductType(pair), formatExchangeKlineIntervalFutures(req.ExchangeInterval), req.RangeHolder.Ranges[x].Start.Time, req.RangeHolder.Ranges[x].End.Time, 200, CallModeHistory) if err != nil { return nil, err } @@ -1627,9 +1588,8 @@ func (bi *Bitget) GetFuturesContractDetails(ctx context.Context, _ asset.Item) ( temp := make([]futures.Contract, len(resp)) for x := range resp { temp[x] = futures.Contract{ - Exchange: bi.Name, - Name: currency.NewPair(currency.NewCode(resp[x].BaseCoin), - currency.NewCode(resp[x].QuoteCoin)), + Exchange: bi.Name, + Name: currency.NewPair(currency.NewCode(resp[x].BaseCoin), currency.NewCode(resp[x].QuoteCoin)), Multiplier: resp[x].SizeMultiplier, Asset: itemDecoder(resp[x].SymbolType), Type: contractTypeDecoder(resp[x].SymbolType), @@ -1690,9 +1650,8 @@ func (bi *Bitget) UpdateOrderExecutionLimits(ctx context.Context, a asset.Item) limits = make([]order.MinMaxLevel, len(resp)) for i := range resp { limits[i] = order.MinMaxLevel{ - Asset: a, - Pair: currency.NewPair(currency.NewCode(resp[i].BaseCoin), - currency.NewCode(resp[i].QuoteCoin)), + Asset: a, + Pair: currency.NewPair(currency.NewCode(resp[i].BaseCoin), currency.NewCode(resp[i].QuoteCoin)), PriceStepIncrementSize: float64(resp[i].PricePrecision), AmountStepIncrementSize: float64(resp[i].QuantityPrecision), QuoteStepIncrementSize: float64(resp[i].QuotePrecision), @@ -1710,9 +1669,8 @@ func (bi *Bitget) UpdateOrderExecutionLimits(ctx context.Context, a asset.Item) tempResp := make([]order.MinMaxLevel, len(resp)) for x := range resp { tempResp[x] = order.MinMaxLevel{ - Asset: a, - Pair: currency.NewPair(currency.NewCode(resp[x].BaseCoin), - currency.NewCode(resp[x].QuoteCoin)), + Asset: a, + Pair: currency.NewPair(currency.NewCode(resp[x].BaseCoin), currency.NewCode(resp[x].QuoteCoin)), MinNotional: resp[x].MinTradeUSDT, MaxTotalOrders: resp[x].MaxSymbolOpenOrderNum, } @@ -1727,9 +1685,8 @@ func (bi *Bitget) UpdateOrderExecutionLimits(ctx context.Context, a asset.Item) limits = make([]order.MinMaxLevel, len(resp)) for i := range resp { limits[i] = order.MinMaxLevel{ - Asset: a, - Pair: currency.NewPair(currency.NewCode(resp[i].BaseCoin), - currency.NewCode(resp[i].QuoteCoin)), + Asset: a, + Pair: currency.NewPair(currency.NewCode(resp[i].BaseCoin), currency.NewCode(resp[i].QuoteCoin)), MinNotional: resp[i].MinTradeUSDT, MarketMinQty: resp[i].MinTradeAmount, MarketMaxQty: resp[i].MaxTradeAmount, @@ -1805,24 +1762,22 @@ loop: for { switch req.Asset { case asset.Margin: - resp, err := bi.GetIsolatedInterestHistory(ctx, req.Pair.String(), req.Currency.String(), - req.StartDate, req.EndDate, 500, pagination) + resp, err := bi.GetIsolatedInterestHistory(ctx, req.Pair.String(), req.Currency.String(), req.StartDate, req.EndDate, 500, pagination) if err != nil { return nil, err } - if resp == nil || len(resp.Data.ResultList) == 0 || pagination == int64(resp.Data.MaxID) { + if resp == nil || len(resp.ResultList) == 0 || pagination == int64(resp.MaxID) { break loop } - pagination = int64(resp.Data.MaxID) - for i := range resp.Data.ResultList { + pagination = int64(resp.MaxID) + for i := range resp.ResultList { rates.Rates = append(rates.Rates, margin.Rate{ - DailyBorrowRate: decimal.NewFromFloat(resp.Data.ResultList[i].DailyInterestRate), - Time: resp.Data.ResultList[i].CreationTime.Time(), + DailyBorrowRate: decimal.NewFromFloat(resp.ResultList[i].DailyInterestRate), + Time: resp.ResultList[i].CreationTime.Time(), }) } case asset.CrossMargin: - resp, err := bi.GetCrossInterestHistory(ctx, req.Currency.String(), req.StartDate, req.EndDate, 500, - pagination) + resp, err := bi.GetCrossInterestHistory(ctx, req.Currency.String(), req.StartDate, req.EndDate, 500, pagination) if err != nil { return nil, err } @@ -2063,10 +2018,10 @@ func (bi *Bitget) GetLeverage(ctx context.Context, a asset.Item, p currency.Pair if err != nil { return lev, err } - if len(resp.Data) == 0 { + if len(resp) == 0 { return lev, errReturnEmpty } - lev = resp.Data[0].Leverage + lev = resp[0].Leverage case asset.CrossMargin: resp, err := bi.GetCrossInterestRateAndMaxBorrowable(ctx, p.Quote.String()) if err != nil { @@ -2150,7 +2105,9 @@ func strategyTruthTable(ioc, fok, po bool) (string, error) { // ClientIDGenerator is a helper function that generates a unique client ID func clientIDGenerator() string { + // Making the bits corresponding to smaller timescales more significant, to cheaply increase uniqueness across small timeframes i := time.Now().UnixNano()>>29 + time.Now().UnixNano()<<35 + // ClientID supports alphanumeric characters, so use the largest prime bases that fit within 50 characters to minimize chance of collisions cID := strconv.FormatInt(i, 31) + strconv.FormatInt(i, 29) + strconv.FormatInt(i, 23) + strconv.FormatInt(i, 19) if len(cID) > 50 { cID = cID[:50] @@ -2196,7 +2153,7 @@ func pairBatcher(orders []order.Cancel) (map[currency.Pair][]OrderIDStruct, erro } batchByPair[orders[i].Pair] = append(batchByPair[orders[i].Pair], OrderIDStruct{ ClientOrderID: orders[i].ClientOrderID, - OrderID: originalID, + OrderID: EmptyInt(originalID), }) } return batchByPair, nil @@ -2210,8 +2167,7 @@ func addStatuses(status *BatchOrderResp, resp *order.CancelBatchResponse) { } for i := range status.FailureList { resp.Status[status.FailureList[i].ClientOrderID] = status.FailureList[i].ErrorMessage - resp.Status[strconv.FormatInt(int64(status.FailureList[i].OrderID), 10)] = - status.FailureList[i].ErrorMessage + resp.Status[strconv.FormatInt(int64(status.FailureList[i].OrderID), 10)] = status.FailureList[i].ErrorMessage } } @@ -2263,8 +2219,7 @@ func (bi *Bitget) withdrawalHistGrabber(ctx context.Context, currency string) ([ var allData []WithdrawRecordsResp var pagination int64 for { - resp, err := bi.GetWithdrawalRecords(ctx, currency, "", time.Now().Add(-time.Hour*24*90), time.Now(), - pagination, 0, 100) + resp, err := bi.GetWithdrawalRecords(ctx, currency, "", time.Now().Add(-time.Hour*24*90), time.Now(), pagination, 0, 100) if err != nil { return nil, err } @@ -2277,8 +2232,6 @@ func (bi *Bitget) withdrawalHistGrabber(ctx context.Context, currency string) ([ return allData, nil } -var printOnce bool - // PairFromStringHelper is a helper function that does some checks to help with common ambiguous cases in this // exchange func pairFromStringHelper(s string) (currency.Pair, error) { @@ -2295,11 +2248,6 @@ func pairFromStringHelper(s string) (currency.Pair, error) { return pair, err } pair = pair.Format(currency.PairFormat{Uppercase: true, Delimiter: ""}) - if !printOnce && pair.Base == currency.TRX { - fmt.Printf("Pair %v has been formatted to %v. Base: %v. Quote: %v. Delimiter: %v. String: %v", s, pair, - pair.Base, pair.Quote, pair.Delimiter, pair.String()) - printOnce = true - } return pair, nil } @@ -2346,7 +2294,7 @@ func marginDecoder(s string) margin.Type { switch s { case "isolated": return margin.Isolated - case "cross": + case "cross", "crossed": return margin.Multi } return margin.Unknown @@ -2357,8 +2305,7 @@ func marginDecoder(s string) margin.Type { func (bi *Bitget) activeFuturesOrderHelper(ctx context.Context, pairStr, productType string, pairCan currency.Pair, resp []order.Detail) ([]order.Detail, error) { var pagination int64 for { - genOrds, err := bi.GetPendingFuturesOrders(ctx, 0, pagination, 100, "", pairStr, productType, "", - time.Time{}, time.Time{}) + genOrds, err := bi.GetPendingFuturesOrders(ctx, 0, pagination, 100, "", pairStr, productType, "", time.Time{}, time.Time{}) if err != nil { return nil, err } @@ -2397,16 +2344,14 @@ func (bi *Bitget) activeFuturesOrderHelper(ctx context.Context, pairStr, product return nil, err } } - tempOrds[i].ImmediateOrCancel, tempOrds[i].FillOrKill, tempOrds[i].PostOnly = - strategyDecoder(genOrds.EntrustedList[i].Force) + tempOrds[i].ImmediateOrCancel, tempOrds[i].FillOrKill, tempOrds[i].PostOnly = strategyDecoder(genOrds.EntrustedList[i].Force) } resp = append(resp, tempOrds...) } for y := range planTypes { pagination = 0 for { - genOrds, err := bi.GetPendingTriggerFuturesOrders(ctx, 0, pagination, 100, "", pairStr, planTypes[y], - productType, time.Time{}, time.Time{}) + genOrds, err := bi.GetPendingTriggerFuturesOrders(ctx, 0, pagination, 100, "", pairStr, planTypes[y], productType, time.Time{}, time.Time{}) if err != nil { return nil, err } @@ -2417,11 +2362,10 @@ func (bi *Bitget) activeFuturesOrderHelper(ctx context.Context, pairStr, product tempOrds := make([]order.Detail, len(genOrds.EntrustedList)) for i := range genOrds.EntrustedList { tempOrds[i] = order.Detail{ - Exchange: bi.Name, - AssetType: asset.Futures, - Amount: genOrds.EntrustedList[i].Size, - OrderID: strconv.FormatInt(int64(genOrds.EntrustedList[i].OrderID), - 10), + Exchange: bi.Name, + AssetType: asset.Futures, + Amount: genOrds.EntrustedList[i].Size, + OrderID: strconv.FormatInt(int64(genOrds.EntrustedList[i].OrderID), 10), ClientOrderID: genOrds.EntrustedList[i].ClientOrderID, Price: float64(genOrds.EntrustedList[i].Price), TriggerPrice: float64(genOrds.EntrustedList[i].TriggerPrice), @@ -2455,8 +2399,7 @@ func (bi *Bitget) activeFuturesOrderHelper(ctx context.Context, pairStr, product func (bi *Bitget) spotHistoricPlanOrdersHelper(ctx context.Context, pairStr string, pairCan currency.Pair, resp []order.Detail, fillMap map[int64][]order.TradeHistory) ([]order.Detail, error) { var pagination int64 for { - genOrds, err := bi.GetSpotPlanOrderHistory(ctx, pairStr, time.Now().Add(-time.Hour*24*90), time.Now(), 100, - pagination) + genOrds, err := bi.GetSpotPlanOrderHistory(ctx, pairStr, time.Now().Add(-time.Hour*24*90), time.Now(), 100, pagination) if err != nil { return nil, err } @@ -2519,14 +2462,12 @@ func (bi *Bitget) historicalFuturesOrderHelper(ctx context.Context, pairStr, pro tempFill.Fee += fillOrds.FillList[i].FeeDetail[y].TotalFee tempFill.FeeAsset = fillOrds.FillList[i].FeeDetail[y].FeeCoin } - fillMap[fillOrds.FillList[i].OrderID] = append(fillMap[fillOrds.FillList[i].OrderID], - tempFill) + fillMap[fillOrds.FillList[i].OrderID] = append(fillMap[fillOrds.FillList[i].OrderID], tempFill) } } pagination = 0 for { - genOrds, err := bi.GetHistoricalFuturesOrders(ctx, 0, pagination, 100, "", pairStr, productType, - time.Time{}, time.Time{}) + genOrds, err := bi.GetHistoricalFuturesOrders(ctx, 0, pagination, 100, "", pairStr, productType, time.Time{}, time.Time{}) if err != nil { return nil, err } @@ -2565,8 +2506,7 @@ func (bi *Bitget) historicalFuturesOrderHelper(ctx context.Context, pairStr, pro return nil, err } } - tempOrds[i].ImmediateOrCancel, tempOrds[i].FillOrKill, tempOrds[i].PostOnly = - strategyDecoder(genOrds.EntrustedList[i].Force) + tempOrds[i].ImmediateOrCancel, tempOrds[i].FillOrKill, tempOrds[i].PostOnly = strategyDecoder(genOrds.EntrustedList[i].Force) if len(fillMap[int64(genOrds.EntrustedList[i].OrderID)]) > 0 { tempOrds[i].Trades = fillMap[int64(genOrds.EntrustedList[i].OrderID)] } @@ -2576,8 +2516,7 @@ func (bi *Bitget) historicalFuturesOrderHelper(ctx context.Context, pairStr, pro for y := range planTypes { pagination = 0 for { - genOrds, err := bi.GetHistoricalTriggerFuturesOrders(ctx, 0, pagination, 100, "", planTypes[y], "", - pairStr, productType, time.Time{}, time.Time{}) + genOrds, err := bi.GetHistoricalTriggerFuturesOrders(ctx, 0, pagination, 100, "", planTypes[y], "", pairStr, productType, time.Time{}, time.Time{}) if err != nil { return nil, err } @@ -2588,11 +2527,10 @@ func (bi *Bitget) historicalFuturesOrderHelper(ctx context.Context, pairStr, pro tempOrds := make([]order.Detail, len(genOrds.EntrustedList)) for i := range genOrds.EntrustedList { tempOrds[i] = order.Detail{ - Exchange: bi.Name, - AssetType: asset.Futures, - Amount: genOrds.EntrustedList[i].Size, - OrderID: strconv.FormatInt(int64(genOrds.EntrustedList[i].OrderID), - 10), + Exchange: bi.Name, + AssetType: asset.Futures, + Amount: genOrds.EntrustedList[i].Size, + OrderID: strconv.FormatInt(int64(genOrds.EntrustedList[i].OrderID), 10), ClientOrderID: genOrds.EntrustedList[i].ClientOrderID, Status: statusDecoder(genOrds.EntrustedList[i].PlanStatus), Price: float64(genOrds.EntrustedList[i].Price), @@ -2760,19 +2698,19 @@ func (bi *Bitget) allFuturesOrderHelper(ctx context.Context, pairStr, productTyp var genOrds *FuturesOrdResp var err error if !breakbool1 { - genOrds, err = bi.GetPendingFuturesOrders(ctx, 0, pagination1, 100, "", pairStr, productType, "", - time.Time{}, time.Time{}) + genOrds, err = bi.GetPendingFuturesOrders(ctx, 0, pagination1, 100, "", pairStr, productType, "", time.Time{}, time.Time{}) if err != nil { return nil, err } if genOrds == nil || len(genOrds.EntrustedList) == 0 || pagination1 == int64(genOrds.EndID) { breakbool1 = true + genOrds = nil + } else { + pagination1 = int64(genOrds.EndID) } - pagination1 = int64(genOrds.EndID) } if !breakbool2 { - genOrds2, err := bi.GetHistoricalFuturesOrders(ctx, 0, pagination2, 100, "", pairStr, productType, - time.Time{}, time.Time{}) + genOrds2, err := bi.GetHistoricalFuturesOrders(ctx, 0, pagination2, 100, "", pairStr, productType, time.Time{}, time.Time{}) if err != nil { return nil, err } @@ -2783,8 +2721,8 @@ func (bi *Bitget) allFuturesOrderHelper(ctx context.Context, pairStr, productTyp genOrds = new(FuturesOrdResp) } genOrds.EntrustedList = append(genOrds.EntrustedList, genOrds2.EntrustedList...) + pagination2 = int64(genOrds2.EndID) } - pagination2 = int64(genOrds.EndID) } if breakbool1 && breakbool2 { break @@ -2830,8 +2768,7 @@ func (bi *Bitget) allFuturesOrderHelper(ctx context.Context, pairStr, productTyp for y := range planTypes { pagination1 = 0 for { - genOrds, err := bi.GetPendingTriggerFuturesOrders(ctx, 0, pagination1, 100, "", pairStr, planTypes[y], - productType, time.Time{}, time.Time{}) + genOrds, err := bi.GetPendingTriggerFuturesOrders(ctx, 0, pagination1, 100, "", pairStr, planTypes[y], productType, time.Time{}, time.Time{}) if err != nil { return nil, err } @@ -2872,8 +2809,7 @@ func (bi *Bitget) allFuturesOrderHelper(ctx context.Context, pairStr, productTyp } pagination1 = 0 for { - genOrds, err := bi.GetHistoricalTriggerFuturesOrders(ctx, 0, pagination1, 100, "", planTypes[y], "", - pairStr, productType, time.Time{}, time.Time{}) + genOrds, err := bi.GetHistoricalTriggerFuturesOrders(ctx, 0, pagination1, 100, "", planTypes[y], "", pairStr, productType, time.Time{}, time.Time{}) if err != nil { return nil, err }