mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-07 23:16:53 +00:00
Feature: Implement funding rates, futures and coin margin (exchange API coverage) (#530)
* ALMOST THERE * more api wips * more api thingz * testing n more api wipz * more apiz * more wips * what is goin on * more wips * whip n testing * testing * testing no keys * remove log * kraken is broken ugh * still broken * fixing auth funcs + usdtm api docs * wip * api stuffs * whip * more wips * whip * more wip * api wip n testing * wip * wip * unsaved * wip n testing * wip * wip * wip * wip * wip * wip * wip * wip * wip * whip * wrapper authenticated functions * adding asset type and fixing dependencies * wip * binance auth wrapper start * wrapper functionality * wip * wip * wip * wrapper cancel functions * order submission for wrappers * wip * more error fixing and nits * websocket beginning n error fix * wip * WOW * glorious n shazzy nits * useless nits * wip * fixing things * merge stuffs * crapveyor * crapveyor rebuild * probably broke more things than he fixed * rm lns n other thangs * hope * please * stop it * done * ofcourse * rm vb * fix lbank * appveyor please * float lev * DONT ASK RYAN FOR HELP EVER * wip * wip * endpoint upgrades continued * path upgrade * NeeeNeeeNeeeNeeeNING * fix stuffs * fixing time issue * fixing broken funcs * glorious nits * shaz changes * fixing errors for fundmon * more error fixing for fundmon * test running past 30s * basic changes * THX AGAIN SHAZBERT * path system upgrade * config upgrade * unsaved stuffs * broken wip config upgrade * path system upgrade contd. * path system upgrade contd * path upgrade ready for review * testing verbose removed * linter stuffs * appveyor stuffs * appveyor stuff * fixed? * bugfix * wip * broken stuff * fix test * wierd hack fix * appveyor pls stop * error found * more useless nits * bitmex err * broken wip * broken wip path upgrade change to uint32 * changed url lookups to uint * WOW * ready4review * config fixed HOPEFULLY * config fix and glorious changes * efficient way of getting orders and open orders * binance wrapper logic fixing * testing, adding tests and fixing lot of errrrrs * merge master * appveyor stuffs * appveyor stuffs * fmt * test * octalLiteral issue fix? * octalLiteral fix? * rm vb * prnt ln to restart * adding testz * test fixzzz * READY FOR REVIEW * Actually ready now * FORMATTING * addressing shazzy n glorious nits * crapveyor * rm vb * small change * fixing err * shazbert nits * review changes * requested changes * more requested changes * noo * last nit fixes * restart appveyor * improving test cov * Update .golangci.yml * shazbert changes * moving pair formatting * format pair update wip * path upgrade complete * error fix * appveyor linters * more linters * remove testexch * more formatting changes * changes * shazbert changes * checking older requested changes to ensure completion * wip * fixing broken code * error fix * all fixed * additional changes * more changes * remove commented code * ftx margin api * appveyor fixes * more appveyor issues + test addition * more appveyor issues + test addition * remove unnecessary * testing * testing, fixing okex api, error fix * git merge fix * go sum * glorious changes and error fix * rm vb * more glorious changes and go mod tidy * fixed now * okex testing upgrade * old config migration and batch fetching fix * added test * glorious requested changes WIP * tested and fixed * go fmted * go fmt and test fix * additional funcs and tests for fundingRates * OKEX tested and fixed * appveyor fixes * ineff assign * 1 glorious change * error fix * typo * shazbert changes * glorious code changes and path fixing huobi WIP * adding assetType to accountinfo functions * fixing panic * panic fix and updating account info wrappers WIP * updateaccountinfo updated * testing WIP binance USDT n Coin Margined and Kraken Futures * auth functions tested and fixed * added test * config reverted * shazbert and glorious changes * shazbert and glorious changes * latest changes and portfolio update * go fmt change: * remove commented codes * improved error checking * index out of range fix * rm ln * critical nit * glorious latest changes * appveyor changes * shazbert change * easier readability * latest glorious changes * shadow dec * assetstore updated * last change * another last change * merge changes * go mod tidy * thrasher requested changes wip * improving struct layouts * appveyor go fmt * remove unnecessary code * shazbert changes * small change * oopsie * tidy * configtest reverted * error fix * oopsie * for what * test patch fix * insecurities * fixing tests * fix config
This commit is contained in:
@@ -80,8 +80,8 @@ func (c *Coinbene) GetAllPairs() ([]PairData, error) {
|
||||
resp := struct {
|
||||
Data []PairData `json:"data"`
|
||||
}{}
|
||||
path := c.API.Endpoints.URL + coinbeneAPIVersion + coinbeneGetAllPairs
|
||||
return resp.Data, c.SendHTTPRequest(path, spotPairs, &resp)
|
||||
path := coinbeneAPIVersion + coinbeneGetAllPairs
|
||||
return resp.Data, c.SendHTTPRequest(exchange.RestSpot, path, spotPairs, &resp)
|
||||
}
|
||||
|
||||
// GetPairInfo gets info about a single pair
|
||||
@@ -91,8 +91,8 @@ func (c *Coinbene) GetPairInfo(symbol string) (PairData, error) {
|
||||
}{}
|
||||
params := url.Values{}
|
||||
params.Set("symbol", symbol)
|
||||
path := common.EncodeURLValues(c.API.Endpoints.URL+coinbeneAPIVersion+coinbenePairInfo, params)
|
||||
return resp.Data, c.SendHTTPRequest(path, spotPairInfo, &resp)
|
||||
path := common.EncodeURLValues(coinbeneAPIVersion+coinbenePairInfo, params)
|
||||
return resp.Data, c.SendHTTPRequest(exchange.RestSpot, path, spotPairInfo, &resp)
|
||||
}
|
||||
|
||||
// GetOrderbook gets and stores orderbook data for given pair
|
||||
@@ -108,8 +108,8 @@ func (c *Coinbene) GetOrderbook(symbol string, size int64) (Orderbook, error) {
|
||||
params := url.Values{}
|
||||
params.Set("symbol", symbol)
|
||||
params.Set("depth", strconv.FormatInt(size, 10))
|
||||
path := common.EncodeURLValues(c.API.Endpoints.URL+coinbeneAPIVersion+coinbeneGetOrderBook, params)
|
||||
err := c.SendHTTPRequest(path, spotOrderbook, &resp)
|
||||
path := common.EncodeURLValues(coinbeneAPIVersion+coinbeneGetOrderBook, params)
|
||||
err := c.SendHTTPRequest(exchange.RestSpot, path, spotOrderbook, &resp)
|
||||
if err != nil {
|
||||
return Orderbook{}, err
|
||||
}
|
||||
@@ -154,8 +154,8 @@ func (c *Coinbene) GetTicker(symbol string) (TickerData, error) {
|
||||
}{}
|
||||
params := url.Values{}
|
||||
params.Set("symbol", symbol)
|
||||
path := common.EncodeURLValues(c.API.Endpoints.URL+coinbeneAPIVersion+coinbeneGetTicker, params)
|
||||
return resp.TickerData, c.SendHTTPRequest(path, spotSpecificTicker, &resp)
|
||||
path := common.EncodeURLValues(coinbeneAPIVersion+coinbeneGetTicker, params)
|
||||
return resp.TickerData, c.SendHTTPRequest(exchange.RestSpot, path, spotSpecificTicker, &resp)
|
||||
}
|
||||
|
||||
// GetTickers gets and all spot tickers supported by the exchange
|
||||
@@ -164,8 +164,8 @@ func (c *Coinbene) GetTickers() ([]TickerData, error) {
|
||||
TickerData []TickerData `json:"data"`
|
||||
}{}
|
||||
|
||||
path := c.API.Endpoints.URL + coinbeneAPIVersion + coinbeneGetTickersSpot
|
||||
return resp.TickerData, c.SendHTTPRequest(path, spotTickerList, &resp)
|
||||
path := coinbeneAPIVersion + coinbeneGetTickersSpot
|
||||
return resp.TickerData, c.SendHTTPRequest(exchange.RestSpot, path, spotTickerList, &resp)
|
||||
}
|
||||
|
||||
// GetTrades gets recent trades from the exchange
|
||||
@@ -177,8 +177,8 @@ func (c *Coinbene) GetTrades(symbol string, limit int64) (Trades, error) {
|
||||
params := url.Values{}
|
||||
params.Set("symbol", symbol)
|
||||
params.Set("limit", strconv.FormatInt(limit, 10))
|
||||
path := common.EncodeURLValues(c.API.Endpoints.URL+coinbeneAPIVersion+coinbeneGetTrades, params)
|
||||
err := c.SendHTTPRequest(path, spotMarketTrades, &resp)
|
||||
path := common.EncodeURLValues(coinbeneAPIVersion+coinbeneGetTrades, params)
|
||||
err := c.SendHTTPRequest(exchange.RestSpot, path, spotMarketTrades, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -213,8 +213,8 @@ func (c *Coinbene) GetAccountBalances() ([]UserBalanceData, error) {
|
||||
resp := struct {
|
||||
Data []UserBalanceData `json:"data"`
|
||||
}{}
|
||||
path := c.API.Endpoints.URL + coinbeneAPIVersion + coinbeneGetUserBalance
|
||||
err := c.SendAuthHTTPRequest(http.MethodGet,
|
||||
path := coinbeneAPIVersion + coinbeneGetUserBalance
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSpot, http.MethodGet,
|
||||
path,
|
||||
coinbeneGetUserBalance,
|
||||
false,
|
||||
@@ -234,8 +234,8 @@ func (c *Coinbene) GetAccountAssetBalance(symbol string) (UserBalanceData, error
|
||||
resp := struct {
|
||||
Data UserBalanceData `json:"data"`
|
||||
}{}
|
||||
path := c.API.Endpoints.URL + coinbeneAPIVersion + coinbeneAccountBalanceOne
|
||||
err := c.SendAuthHTTPRequest(http.MethodGet,
|
||||
path := coinbeneAPIVersion + coinbeneAccountBalanceOne
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSpot, http.MethodGet,
|
||||
path,
|
||||
coinbeneAccountBalanceOne,
|
||||
false,
|
||||
@@ -289,8 +289,8 @@ func (c *Coinbene) PlaceSpotOrder(price, quantity float64, symbol, direction,
|
||||
if notional != 0 {
|
||||
params.Set("notional", strconv.Itoa(notional))
|
||||
}
|
||||
path := c.API.Endpoints.URL + coinbeneAPIVersion + coinbenePlaceOrder
|
||||
err := c.SendAuthHTTPRequest(http.MethodPost,
|
||||
path := coinbeneAPIVersion + coinbenePlaceOrder
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSpot, http.MethodPost,
|
||||
path,
|
||||
coinbenePlaceOrder,
|
||||
false,
|
||||
@@ -359,8 +359,8 @@ func (c *Coinbene) PlaceSpotOrders(orders []PlaceOrderRequest) ([]OrderPlacement
|
||||
resp := struct {
|
||||
Data []OrderPlacementResponse `json:"data"`
|
||||
}{}
|
||||
path := c.API.Endpoints.URL + coinbeneAPIVersion + coinbeneBatchPlaceOrder
|
||||
err := c.SendAuthHTTPRequest(http.MethodPost,
|
||||
path := coinbeneAPIVersion + coinbeneBatchPlaceOrder
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSpot, http.MethodPost,
|
||||
path,
|
||||
coinbeneBatchPlaceOrder,
|
||||
false,
|
||||
@@ -377,14 +377,14 @@ func (c *Coinbene) PlaceSpotOrders(orders []PlaceOrderRequest) ([]OrderPlacement
|
||||
func (c *Coinbene) FetchOpenSpotOrders(symbol string) (OrdersInfo, error) {
|
||||
params := url.Values{}
|
||||
params.Set("symbol", symbol)
|
||||
path := c.API.Endpoints.URL + coinbeneAPIVersion + coinbeneOpenOrders
|
||||
path := coinbeneAPIVersion + coinbeneOpenOrders
|
||||
var orders OrdersInfo
|
||||
for i := int64(1); ; i++ {
|
||||
temp := struct {
|
||||
Data OrdersInfo `json:"data"`
|
||||
}{}
|
||||
params.Set("pageNum", strconv.FormatInt(i, 10))
|
||||
err := c.SendAuthHTTPRequest(http.MethodGet,
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSpot, http.MethodGet,
|
||||
path,
|
||||
coinbeneOpenOrders,
|
||||
false,
|
||||
@@ -410,14 +410,14 @@ func (c *Coinbene) FetchClosedOrders(symbol, latestID string) (OrdersInfo, error
|
||||
params := url.Values{}
|
||||
params.Set("symbol", symbol)
|
||||
params.Set("latestOrderId", latestID)
|
||||
path := c.API.Endpoints.URL + coinbeneAPIVersion + coinbeneClosedOrders
|
||||
path := coinbeneAPIVersion + coinbeneClosedOrders
|
||||
var orders OrdersInfo
|
||||
for i := int64(1); ; i++ {
|
||||
temp := struct {
|
||||
Data OrdersInfo `json:"data"`
|
||||
}{}
|
||||
params.Set("pageNum", strconv.FormatInt(i, 10))
|
||||
err := c.SendAuthHTTPRequest(http.MethodGet,
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSpot, http.MethodGet,
|
||||
path,
|
||||
coinbeneClosedOrders,
|
||||
false,
|
||||
@@ -444,8 +444,8 @@ func (c *Coinbene) FetchSpotOrderInfo(orderID string) (OrderInfo, error) {
|
||||
}{}
|
||||
params := url.Values{}
|
||||
params.Set("orderId", orderID)
|
||||
path := c.API.Endpoints.URL + coinbeneAPIVersion + coinbeneOrderInfo
|
||||
err := c.SendAuthHTTPRequest(http.MethodGet,
|
||||
path := coinbeneAPIVersion + coinbeneOrderInfo
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSpot, http.MethodGet,
|
||||
path,
|
||||
coinbeneOrderInfo,
|
||||
false,
|
||||
@@ -469,8 +469,8 @@ func (c *Coinbene) GetSpotOrderFills(orderID string) ([]OrderFills, error) {
|
||||
}{}
|
||||
params := url.Values{}
|
||||
params.Set("orderId", orderID)
|
||||
path := c.API.Endpoints.URL + coinbeneAPIVersion + coinbeneTradeFills
|
||||
err := c.SendAuthHTTPRequest(http.MethodGet,
|
||||
path := coinbeneAPIVersion + coinbeneTradeFills
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSpot, http.MethodGet,
|
||||
path,
|
||||
coinbeneTradeFills,
|
||||
false,
|
||||
@@ -490,8 +490,8 @@ func (c *Coinbene) CancelSpotOrder(orderID string) (string, error) {
|
||||
}{}
|
||||
req := make(map[string]interface{})
|
||||
req["orderId"] = orderID
|
||||
path := c.API.Endpoints.URL + coinbeneAPIVersion + coinbeneCancelOrder
|
||||
err := c.SendAuthHTTPRequest(http.MethodPost,
|
||||
path := coinbeneAPIVersion + coinbeneCancelOrder
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSpot, http.MethodPost,
|
||||
path,
|
||||
coinbeneCancelOrder,
|
||||
false,
|
||||
@@ -513,8 +513,8 @@ func (c *Coinbene) CancelSpotOrders(orderIDs []string) ([]OrderCancellationRespo
|
||||
}
|
||||
|
||||
var r resp
|
||||
path := c.API.Endpoints.URL + coinbeneAPIVersion + coinbeneBatchCancel
|
||||
err := c.SendAuthHTTPRequest(http.MethodPost,
|
||||
path := coinbeneAPIVersion + coinbeneBatchCancel
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSpot, http.MethodPost,
|
||||
path,
|
||||
coinbeneBatchCancel,
|
||||
false,
|
||||
@@ -533,8 +533,8 @@ func (c *Coinbene) GetSwapTickers() (SwapTickers, error) {
|
||||
Data SwapTickers `json:"data"`
|
||||
}
|
||||
var r resp
|
||||
path := coinbeneSwapAPIURL + coinbeneAPIVersion + coinbeneGetTickers
|
||||
err := c.SendHTTPRequest(path, contractTickers, &r)
|
||||
path := coinbeneAPIVersion + coinbeneGetTickers
|
||||
err := c.SendHTTPRequest(exchange.RestSwap, path, contractTickers, &r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -578,8 +578,8 @@ func (c *Coinbene) GetSwapOrderbook(symbol string, size int64) (Orderbook, error
|
||||
}
|
||||
|
||||
var r resp
|
||||
path := common.EncodeURLValues(coinbeneSwapAPIURL+coinbeneAPIVersion+coinbeneGetOrderBook, v)
|
||||
err := c.SendHTTPRequest(path, contractOrderbook, &r)
|
||||
path := common.EncodeURLValues(coinbeneAPIVersion+coinbeneGetOrderBook, v)
|
||||
err := c.SendHTTPRequest(exchange.RestSwap, path, contractOrderbook, &r)
|
||||
if err != nil {
|
||||
return s, err
|
||||
}
|
||||
@@ -634,8 +634,8 @@ func (c *Coinbene) GetKlines(pair string, start, end time.Time, period string) (
|
||||
}
|
||||
v.Add("period", period)
|
||||
|
||||
path := common.EncodeURLValues(coinbeneAPIURL+coinbeneAPIVersion+coinbeneSpotKlines, v)
|
||||
if err = c.SendHTTPRequest(path, contractKline, &resp); err != nil {
|
||||
path := common.EncodeURLValues(coinbeneAPIVersion+coinbeneSpotKlines, v)
|
||||
if err = c.SendHTTPRequest(exchange.RestSpot, path, contractKline, &resp); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -658,8 +658,8 @@ func (c *Coinbene) GetSwapKlines(symbol string, start, end time.Time, resolution
|
||||
}
|
||||
v.Set("resolution", resolution)
|
||||
|
||||
path := common.EncodeURLValues(coinbeneSwapAPIURL+coinbeneAPIVersion+coinbeneGetKlines, v)
|
||||
if err = c.SendHTTPRequest(path, contractKline, &resp); err != nil {
|
||||
path := common.EncodeURLValues(coinbeneAPIVersion+coinbeneGetKlines, v)
|
||||
if err = c.SendHTTPRequest(exchange.RestSwap, path, contractKline, &resp); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -677,8 +677,8 @@ func (c *Coinbene) GetSwapTrades(symbol string, limit int) (SwapTrades, error) {
|
||||
Data [][]string `json:"data"`
|
||||
}
|
||||
var r resp
|
||||
path := common.EncodeURLValues(coinbeneSwapAPIURL+coinbeneAPIVersion+coinbeneGetTrades, v)
|
||||
if err := c.SendHTTPRequest(path, contractTrades, &r); err != nil {
|
||||
path := common.EncodeURLValues(coinbeneAPIVersion+coinbeneGetTrades, v)
|
||||
if err := c.SendHTTPRequest(exchange.RestSwap, path, contractTrades, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -716,8 +716,8 @@ func (c *Coinbene) GetSwapAccountInfo() (SwapAccountInfo, error) {
|
||||
Data SwapAccountInfo `json:"data"`
|
||||
}
|
||||
var r resp
|
||||
path := coinbeneSwapAPIURL + coinbeneAPIVersion + coinbeneAccountInfo
|
||||
err := c.SendAuthHTTPRequest(http.MethodGet,
|
||||
path := coinbeneAPIVersion + coinbeneAccountInfo
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSwap, http.MethodGet,
|
||||
path,
|
||||
coinbeneAccountInfo,
|
||||
true,
|
||||
@@ -738,8 +738,8 @@ func (c *Coinbene) GetSwapPositions(symbol string) (SwapPositions, error) {
|
||||
Data SwapPositions `json:"data"`
|
||||
}
|
||||
var r resp
|
||||
path := coinbeneSwapAPIURL + coinbeneAPIVersion + coinbeneListSwapPositions
|
||||
err := c.SendAuthHTTPRequest(http.MethodGet,
|
||||
path := coinbeneAPIVersion + coinbeneListSwapPositions
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSwap, http.MethodGet,
|
||||
path,
|
||||
coinbeneListSwapPositions,
|
||||
true,
|
||||
@@ -793,8 +793,8 @@ func (c *Coinbene) PlaceSwapOrder(symbol, direction, orderType, marginMode,
|
||||
Data SwapPlaceOrderResponse `json:"data"`
|
||||
}
|
||||
var r resp
|
||||
path := coinbeneSwapAPIURL + coinbeneAPIVersion + coinbenePlaceOrder
|
||||
err := c.SendAuthHTTPRequest(http.MethodPost,
|
||||
path := coinbeneAPIVersion + coinbenePlaceOrder
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSwap, http.MethodPost,
|
||||
path,
|
||||
coinbenePlaceOrder,
|
||||
true,
|
||||
@@ -815,8 +815,8 @@ func (c *Coinbene) CancelSwapOrder(orderID string) (string, error) {
|
||||
Data string `json:"data"`
|
||||
}
|
||||
var r resp
|
||||
path := coinbeneSwapAPIURL + coinbeneAPIVersion + coinbeneCancelOrder
|
||||
err := c.SendAuthHTTPRequest(http.MethodPost,
|
||||
path := coinbeneAPIVersion + coinbeneCancelOrder
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSwap, http.MethodPost,
|
||||
path,
|
||||
coinbeneCancelOrder,
|
||||
true,
|
||||
@@ -843,8 +843,8 @@ func (c *Coinbene) GetSwapOpenOrders(symbol string, pageNum, pageSize int) (Swap
|
||||
Data SwapOrders `json:"data"`
|
||||
}
|
||||
var r resp
|
||||
path := coinbeneSwapAPIURL + coinbeneAPIVersion + coinbeneOpenOrders
|
||||
err := c.SendAuthHTTPRequest(http.MethodGet,
|
||||
path := coinbeneAPIVersion + coinbeneOpenOrders
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSwap, http.MethodGet,
|
||||
path,
|
||||
coinbeneOpenOrders,
|
||||
true,
|
||||
@@ -870,8 +870,8 @@ func (c *Coinbene) GetSwapOpenOrdersByPage(symbol string, latestOrderID int64) (
|
||||
Data SwapOrders `json:"data"`
|
||||
}
|
||||
var r resp
|
||||
path := coinbeneSwapAPIURL + coinbeneAPIVersion + coinbeneOpenOrdersByPage
|
||||
err := c.SendAuthHTTPRequest(http.MethodGet,
|
||||
path := coinbeneAPIVersion + coinbeneOpenOrdersByPage
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSwap, http.MethodGet,
|
||||
path,
|
||||
coinbeneOpenOrdersByPage,
|
||||
true,
|
||||
@@ -892,8 +892,8 @@ func (c *Coinbene) GetSwapOrderInfo(orderID string) (SwapOrder, error) {
|
||||
Data SwapOrder `json:"data"`
|
||||
}
|
||||
var r resp
|
||||
path := coinbeneSwapAPIURL + coinbeneAPIVersion + coinbeneOrderInfo
|
||||
err := c.SendAuthHTTPRequest(http.MethodGet,
|
||||
path := coinbeneAPIVersion + coinbeneOrderInfo
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSwap, http.MethodGet,
|
||||
path,
|
||||
coinbeneOrderInfo,
|
||||
true,
|
||||
@@ -935,8 +935,8 @@ func (c *Coinbene) GetSwapOrderHistory(beginTime, endTime, symbol string, pageNu
|
||||
}
|
||||
|
||||
var r resp
|
||||
path := coinbeneSwapAPIURL + coinbeneAPIVersion + coinbeneClosedOrders
|
||||
err := c.SendAuthHTTPRequest(http.MethodGet,
|
||||
path := coinbeneAPIVersion + coinbeneClosedOrders
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSwap, http.MethodGet,
|
||||
path,
|
||||
coinbeneClosedOrders,
|
||||
true,
|
||||
@@ -973,8 +973,8 @@ func (c *Coinbene) GetSwapOrderHistoryByOrderID(beginTime, endTime, symbol, stat
|
||||
}
|
||||
|
||||
var r resp
|
||||
path := coinbeneSwapAPIURL + coinbeneAPIVersion + coinbeneClosedOrdersByPage
|
||||
err := c.SendAuthHTTPRequest(http.MethodGet,
|
||||
path := coinbeneAPIVersion + coinbeneClosedOrdersByPage
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSwap, http.MethodGet,
|
||||
path,
|
||||
coinbeneClosedOrdersByPage,
|
||||
true,
|
||||
@@ -999,8 +999,8 @@ func (c *Coinbene) CancelSwapOrders(orderIDs []string) ([]OrderCancellationRespo
|
||||
}
|
||||
|
||||
var r resp
|
||||
path := coinbeneSwapAPIURL + coinbeneAPIVersion + coinbeneBatchCancel
|
||||
err := c.SendAuthHTTPRequest(http.MethodPost,
|
||||
path := coinbeneAPIVersion + coinbeneBatchCancel
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSwap, http.MethodPost,
|
||||
path,
|
||||
coinbeneBatchCancel,
|
||||
true,
|
||||
@@ -1030,8 +1030,8 @@ func (c *Coinbene) GetSwapOrderFills(symbol, orderID string, lastTradeID int64)
|
||||
}
|
||||
|
||||
var r resp
|
||||
path := coinbeneSwapAPIURL + coinbeneAPIVersion + coinbeneOrderFills
|
||||
err := c.SendAuthHTTPRequest(http.MethodGet,
|
||||
path := coinbeneAPIVersion + coinbeneOrderFills
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSwap, http.MethodGet,
|
||||
path,
|
||||
coinbeneOrderFills,
|
||||
true,
|
||||
@@ -1058,8 +1058,8 @@ func (c *Coinbene) GetSwapFundingRates(pageNum, pageSize int) ([]SwapFundingRate
|
||||
}
|
||||
|
||||
var r resp
|
||||
path := coinbeneSwapAPIURL + coinbeneAPIVersion + coinbenePositionFeeRate
|
||||
err := c.SendAuthHTTPRequest(http.MethodGet,
|
||||
path := coinbeneAPIVersion + coinbenePositionFeeRate
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSwap, http.MethodGet,
|
||||
path,
|
||||
coinbenePositionFeeRate,
|
||||
true,
|
||||
@@ -1073,7 +1073,11 @@ func (c *Coinbene) GetSwapFundingRates(pageNum, pageSize int) ([]SwapFundingRate
|
||||
}
|
||||
|
||||
// SendHTTPRequest sends an unauthenticated HTTP request
|
||||
func (c *Coinbene) SendHTTPRequest(path string, f request.EndpointLimit, result interface{}) error {
|
||||
func (c *Coinbene) SendHTTPRequest(ep exchange.URL, path string, f request.EndpointLimit, result interface{}) error {
|
||||
endpoint, err := c.API.Endpoints.GetURL(ep)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var resp json.RawMessage
|
||||
errCap := struct {
|
||||
Code int `json:"code"`
|
||||
@@ -1082,7 +1086,7 @@ func (c *Coinbene) SendHTTPRequest(path string, f request.EndpointLimit, result
|
||||
|
||||
if err := c.SendPayload(context.Background(), &request.Item{
|
||||
Method: http.MethodGet,
|
||||
Path: path,
|
||||
Path: endpoint + path,
|
||||
Result: &resp,
|
||||
Verbose: c.Verbose,
|
||||
HTTPDebugging: c.HTTPDebugging,
|
||||
@@ -1101,13 +1105,16 @@ func (c *Coinbene) SendHTTPRequest(path string, f request.EndpointLimit, result
|
||||
}
|
||||
|
||||
// SendAuthHTTPRequest sends an authenticated HTTP request
|
||||
func (c *Coinbene) SendAuthHTTPRequest(method, path, epPath string, isSwap bool,
|
||||
func (c *Coinbene) SendAuthHTTPRequest(ep exchange.URL, method, path, epPath string, isSwap bool,
|
||||
params, result interface{}, f request.EndpointLimit) error {
|
||||
if !c.AllowAuthenticatedRequest() {
|
||||
return fmt.Errorf(exchange.WarningAuthenticatedRequestWithoutCredentialsSet,
|
||||
c.Name)
|
||||
}
|
||||
|
||||
endpoint, err := c.API.Endpoints.GetURL(ep)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
authPath := coinbeneAuthPath
|
||||
if isSwap {
|
||||
authPath = coinbeneSwapAuthPath
|
||||
@@ -1165,7 +1172,7 @@ func (c *Coinbene) SendAuthHTTPRequest(method, path, epPath string, isSwap bool,
|
||||
defer cancel()
|
||||
if err := c.SendPayload(ctx, &request.Item{
|
||||
Method: method,
|
||||
Path: path,
|
||||
Path: endpoint + path,
|
||||
Headers: headers,
|
||||
Body: finalBody,
|
||||
Result: &resp,
|
||||
|
||||
@@ -242,7 +242,7 @@ func TestGetAccountInfo(t *testing.T) {
|
||||
if !areTestAPIKeysSet() {
|
||||
t.Skip("API keys required but not set, skipping test")
|
||||
}
|
||||
_, err := c.UpdateAccountInfo()
|
||||
_, err := c.UpdateAccountInfo(asset.Spot)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@@ -400,7 +400,7 @@ func (c *Coinbene) wsHandleData(respRaw []byte) error {
|
||||
Status: oStatus,
|
||||
AssetType: assetType,
|
||||
Date: orders.Data[i].OrderTime,
|
||||
Leverage: strconv.FormatInt(orders.Data[i].Leverage, 10),
|
||||
Leverage: float64(orders.Data[i].Leverage),
|
||||
Pair: newPair,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,10 +146,15 @@ func (c *Coinbene) SetDefaults() {
|
||||
c.Requester = request.New(c.Name,
|
||||
common.NewHTTPClientWithTimeout(exchange.DefaultHTTPTimeout),
|
||||
request.WithLimiter(SetRateLimit()))
|
||||
|
||||
c.API.Endpoints.URLDefault = coinbeneAPIURL
|
||||
c.API.Endpoints.URL = c.API.Endpoints.URLDefault
|
||||
c.API.Endpoints.WebsocketURL = wsContractURL
|
||||
c.API.Endpoints = c.NewEndpoints()
|
||||
err = c.API.Endpoints.SetDefaultEndpoints(map[exchange.URL]string{
|
||||
exchange.RestSpot: coinbeneAPIURL,
|
||||
exchange.RestSwap: coinbeneSwapAPIURL,
|
||||
exchange.WebsocketSpot: wsContractURL,
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorln(log.ExchangeSys, err)
|
||||
}
|
||||
c.Websocket = stream.New()
|
||||
c.WebsocketResponseMaxLimit = exchange.DefaultWebsocketResponseMaxLimit
|
||||
c.WebsocketResponseCheckTimeout = exchange.DefaultWebsocketResponseCheckTimeout
|
||||
@@ -168,6 +173,11 @@ func (c *Coinbene) Setup(exch *config.ExchangeConfig) error {
|
||||
return err
|
||||
}
|
||||
|
||||
wsRunningURL, err := c.API.Endpoints.GetURL(exchange.WebsocketSpot)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = c.Websocket.Setup(&stream.WebsocketSetup{
|
||||
Enabled: exch.Features.Enabled.Websocket,
|
||||
Verbose: exch.Verbose,
|
||||
@@ -175,7 +185,7 @@ func (c *Coinbene) Setup(exch *config.ExchangeConfig) error {
|
||||
WebsocketTimeout: exch.WebsocketTrafficTimeout,
|
||||
DefaultURL: wsContractURL,
|
||||
ExchangeName: exch.Name,
|
||||
RunningURL: exch.API.Endpoints.WebsocketURL,
|
||||
RunningURL: wsRunningURL,
|
||||
Connector: c.WsConnect,
|
||||
Subscriber: c.Subscribe,
|
||||
UnSubscriber: c.Unsubscribe,
|
||||
@@ -464,7 +474,7 @@ func (c *Coinbene) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*orde
|
||||
|
||||
// UpdateAccountInfo retrieves balances for all enabled currencies for the
|
||||
// Coinbene exchange
|
||||
func (c *Coinbene) UpdateAccountInfo() (account.Holdings, error) {
|
||||
func (c *Coinbene) UpdateAccountInfo(assetType asset.Item) (account.Holdings, error) {
|
||||
var info account.Holdings
|
||||
balance, err := c.GetAccountBalances()
|
||||
if err != nil {
|
||||
@@ -494,10 +504,10 @@ func (c *Coinbene) UpdateAccountInfo() (account.Holdings, error) {
|
||||
}
|
||||
|
||||
// FetchAccountInfo retrieves balances for all enabled currencies
|
||||
func (c *Coinbene) FetchAccountInfo() (account.Holdings, error) {
|
||||
acc, err := account.GetHoldings(c.Name)
|
||||
func (c *Coinbene) FetchAccountInfo(assetType asset.Item) (account.Holdings, error) {
|
||||
acc, err := account.GetHoldings(c.Name, assetType)
|
||||
if err != nil {
|
||||
return c.UpdateAccountInfo()
|
||||
return c.UpdateAccountInfo(assetType)
|
||||
}
|
||||
|
||||
return acc, nil
|
||||
@@ -820,8 +830,8 @@ func (c *Coinbene) AuthenticateWebsocket() error {
|
||||
|
||||
// ValidateCredentials validates current credentials used for wrapper
|
||||
// functionality
|
||||
func (c *Coinbene) ValidateCredentials() error {
|
||||
_, err := c.UpdateAccountInfo()
|
||||
func (c *Coinbene) ValidateCredentials(assetType asset.Item) error {
|
||||
_, err := c.UpdateAccountInfo(assetType)
|
||||
return c.CheckTransientError(err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user