mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-08 07:26:48 +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:
@@ -74,7 +74,7 @@ func (c *COINUT) GetInstruments() (Instruments, error) {
|
||||
var result Instruments
|
||||
params := make(map[string]interface{})
|
||||
params["sec_type"] = strings.ToUpper(asset.Spot.String())
|
||||
return result, c.SendHTTPRequest(coinutInstruments, params, false, &result)
|
||||
return result, c.SendHTTPRequest(exchange.RestSpot, coinutInstruments, params, false, &result)
|
||||
}
|
||||
|
||||
// GetInstrumentTicker returns a ticker for a specific instrument
|
||||
@@ -82,7 +82,7 @@ func (c *COINUT) GetInstrumentTicker(instrumentID int64) (Ticker, error) {
|
||||
var result Ticker
|
||||
params := make(map[string]interface{})
|
||||
params["inst_id"] = instrumentID
|
||||
return result, c.SendHTTPRequest(coinutTicker, params, false, &result)
|
||||
return result, c.SendHTTPRequest(exchange.RestSpot, coinutTicker, params, false, &result)
|
||||
}
|
||||
|
||||
// GetInstrumentOrderbook returns the orderbooks for a specific instrument
|
||||
@@ -94,7 +94,7 @@ func (c *COINUT) GetInstrumentOrderbook(instrumentID, limit int64) (Orderbook, e
|
||||
params["top_n"] = limit
|
||||
}
|
||||
|
||||
return result, c.SendHTTPRequest(coinutOrderbook, params, false, &result)
|
||||
return result, c.SendHTTPRequest(exchange.RestSpot, coinutOrderbook, params, false, &result)
|
||||
}
|
||||
|
||||
// GetTrades returns trade information
|
||||
@@ -103,13 +103,13 @@ func (c *COINUT) GetTrades(instrumentID int64) (Trades, error) {
|
||||
params := make(map[string]interface{})
|
||||
params["inst_id"] = instrumentID
|
||||
|
||||
return result, c.SendHTTPRequest(coinutTrades, params, false, &result)
|
||||
return result, c.SendHTTPRequest(exchange.RestSpot, coinutTrades, params, false, &result)
|
||||
}
|
||||
|
||||
// GetUserBalance returns the full user balance
|
||||
func (c *COINUT) GetUserBalance() (*UserBalance, error) {
|
||||
var result *UserBalance
|
||||
return result, c.SendHTTPRequest(coinutBalance, nil, true, &result)
|
||||
return result, c.SendHTTPRequest(exchange.RestSpot, coinutBalance, nil, true, &result)
|
||||
}
|
||||
|
||||
// NewOrder places a new order on the exchange
|
||||
@@ -127,7 +127,7 @@ func (c *COINUT) NewOrder(instrumentID int64, quantity, price float64, buy bool,
|
||||
}
|
||||
params["client_ord_id"] = orderID
|
||||
|
||||
return result, c.SendHTTPRequest(coinutOrder, params, true, &result)
|
||||
return result, c.SendHTTPRequest(exchange.RestSpot, coinutOrder, params, true, &result)
|
||||
}
|
||||
|
||||
// NewOrders places multiple orders on the exchange
|
||||
@@ -136,7 +136,7 @@ func (c *COINUT) NewOrders(orders []Order) ([]OrdersBase, error) {
|
||||
params := make(map[string]interface{})
|
||||
params["orders"] = orders
|
||||
|
||||
return result.Data, c.SendHTTPRequest(coinutOrders, params, true, &result.Data)
|
||||
return result.Data, c.SendHTTPRequest(exchange.RestSpot, coinutOrders, params, true, &result.Data)
|
||||
}
|
||||
|
||||
// GetOpenOrders returns a list of open order and relevant information
|
||||
@@ -144,7 +144,7 @@ func (c *COINUT) GetOpenOrders(instrumentID int64) (GetOpenOrdersResponse, error
|
||||
var result GetOpenOrdersResponse
|
||||
params := make(map[string]interface{})
|
||||
params["inst_id"] = instrumentID
|
||||
return result, c.SendHTTPRequest(coinutOrdersOpen, params, true, &result)
|
||||
return result, c.SendHTTPRequest(exchange.RestSpot, coinutOrdersOpen, params, true, &result)
|
||||
}
|
||||
|
||||
// CancelExistingOrder cancels a specific order and returns if it was actioned
|
||||
@@ -164,7 +164,7 @@ func (c *COINUT) CancelExistingOrder(instrumentID, orderID int64) (bool, error)
|
||||
entries := []Request{entry}
|
||||
params["entries"] = entries
|
||||
|
||||
err := c.SendHTTPRequest(coinutOrdersCancel, params, true, &result)
|
||||
err := c.SendHTTPRequest(exchange.RestSpot, coinutOrdersCancel, params, true, &result)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -184,7 +184,7 @@ func (c *COINUT) CancelOrders(orders []CancelOrders) (CancelOrdersResponse, erro
|
||||
entries = append(entries, orders...)
|
||||
params["entries"] = entries
|
||||
|
||||
return result, c.SendHTTPRequest(coinutOrdersCancel, params, true, &result)
|
||||
return result, c.SendHTTPRequest(exchange.RestSpot, coinutOrdersCancel, params, true, &result)
|
||||
}
|
||||
|
||||
// GetTradeHistory returns trade history for a specific instrument.
|
||||
@@ -199,7 +199,7 @@ func (c *COINUT) GetTradeHistory(instrumentID, start, limit int64) (TradeHistory
|
||||
params["limit"] = limit
|
||||
}
|
||||
|
||||
return result, c.SendHTTPRequest(coinutTradeHistory, params, true, &result)
|
||||
return result, c.SendHTTPRequest(exchange.RestSpot, coinutTradeHistory, params, true, &result)
|
||||
}
|
||||
|
||||
// GetIndexTicker returns the index ticker for an asset
|
||||
@@ -208,7 +208,7 @@ func (c *COINUT) GetIndexTicker(asset string) (IndexTicker, error) {
|
||||
params := make(map[string]interface{})
|
||||
params["asset"] = asset
|
||||
|
||||
return result, c.SendHTTPRequest(coinutIndexTicker, params, false, &result)
|
||||
return result, c.SendHTTPRequest(exchange.RestSpot, coinutIndexTicker, params, false, &result)
|
||||
}
|
||||
|
||||
// GetDerivativeInstruments returns a list of derivative instruments
|
||||
@@ -217,7 +217,7 @@ func (c *COINUT) GetDerivativeInstruments(secType string) (interface{}, error) {
|
||||
params := make(map[string]interface{})
|
||||
params["sec_type"] = secType
|
||||
|
||||
return result, c.SendHTTPRequest(coinutInstruments, params, false, &result)
|
||||
return result, c.SendHTTPRequest(exchange.RestSpot, coinutInstruments, params, false, &result)
|
||||
}
|
||||
|
||||
// GetOptionChain returns option chain
|
||||
@@ -227,7 +227,7 @@ func (c *COINUT) GetOptionChain(asset, secType string) (OptionChainResponse, err
|
||||
params["asset"] = asset
|
||||
params["sec_type"] = secType
|
||||
|
||||
return result, c.SendHTTPRequest(coinutOptionChain, params, false, &result)
|
||||
return result, c.SendHTTPRequest(exchange.RestSpot, coinutOptionChain, params, false, &result)
|
||||
}
|
||||
|
||||
// GetPositionHistory returns position history
|
||||
@@ -242,7 +242,7 @@ func (c *COINUT) GetPositionHistory(secType string, start, limit int) (PositionH
|
||||
params["limit"] = limit
|
||||
}
|
||||
|
||||
return result, c.SendHTTPRequest(coinutPositionHistory, params, true, &result)
|
||||
return result, c.SendHTTPRequest(exchange.RestSpot, coinutPositionHistory, params, true, &result)
|
||||
}
|
||||
|
||||
// GetOpenPositions returns all your current opened positions
|
||||
@@ -255,17 +255,22 @@ func (c *COINUT) GetOpenPositions(instrumentID int) ([]OpenPosition, error) {
|
||||
params["inst_id"] = instrumentID
|
||||
|
||||
return result.Positions,
|
||||
c.SendHTTPRequest(coinutPositionOpen, params, true, &result)
|
||||
c.SendHTTPRequest(exchange.RestSpot, coinutPositionOpen, params, true, &result)
|
||||
}
|
||||
|
||||
// to-do: user position update via websocket
|
||||
|
||||
// SendHTTPRequest sends either an authenticated or unauthenticated HTTP request
|
||||
func (c *COINUT) SendHTTPRequest(apiRequest string, params map[string]interface{}, authenticated bool, result interface{}) (err error) {
|
||||
func (c *COINUT) SendHTTPRequest(ep exchange.URL, apiRequest string, params map[string]interface{}, authenticated bool, result interface{}) (err error) {
|
||||
if !c.API.AuthenticatedSupport && authenticated {
|
||||
return fmt.Errorf(exchange.WarningAuthenticatedRequestWithoutCredentialsSet, c.Name)
|
||||
}
|
||||
|
||||
endpoint, err := c.API.Endpoints.GetURL(ep)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if params == nil {
|
||||
params = map[string]interface{}{}
|
||||
}
|
||||
@@ -293,7 +298,7 @@ func (c *COINUT) SendHTTPRequest(apiRequest string, params map[string]interface{
|
||||
var rawMsg json.RawMessage
|
||||
err = c.SendPayload(context.Background(), &request.Item{
|
||||
Method: http.MethodPost,
|
||||
Path: c.API.Endpoints.URL,
|
||||
Path: endpoint,
|
||||
Headers: headers,
|
||||
Body: bytes.NewBuffer(payload),
|
||||
Result: &rawMsg,
|
||||
|
||||
@@ -253,7 +253,8 @@ func TestFormatWithdrawPermissions(t *testing.T) {
|
||||
|
||||
func TestGetActiveOrders(t *testing.T) {
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
Type: order.AnyType,
|
||||
Type: order.AnyType,
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
_, err := c.GetActiveOrders(&getOrdersRequest)
|
||||
if areTestAPIKeysSet() && err != nil {
|
||||
@@ -264,7 +265,8 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
func TestGetOrderHistoryWrapper(t *testing.T) {
|
||||
setupWSTestAuth(t)
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
Type: order.AnyType,
|
||||
Type: order.AnyType,
|
||||
AssetType: asset.Spot,
|
||||
Pairs: []currency.Pair{currency.NewPair(currency.BTC,
|
||||
currency.USD)},
|
||||
}
|
||||
@@ -358,12 +360,12 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
|
||||
func TestGetAccountInfo(t *testing.T) {
|
||||
if apiKey != "" || clientID != "" {
|
||||
_, err := c.UpdateAccountInfo()
|
||||
_, err := c.UpdateAccountInfo(asset.Spot)
|
||||
if err != nil {
|
||||
t.Error("GetAccountInfo() error", err)
|
||||
}
|
||||
} else {
|
||||
_, err := c.UpdateAccountInfo()
|
||||
_, err := c.UpdateAccountInfo(asset.Spot)
|
||||
if err == nil {
|
||||
t.Error("GetAccountInfo() Expected error")
|
||||
}
|
||||
|
||||
@@ -113,10 +113,14 @@ func (c *COINUT) SetDefaults() {
|
||||
|
||||
c.Requester = request.New(c.Name,
|
||||
common.NewHTTPClientWithTimeout(exchange.DefaultHTTPTimeout))
|
||||
|
||||
c.API.Endpoints.URLDefault = coinutAPIURL
|
||||
c.API.Endpoints.URL = c.API.Endpoints.URLDefault
|
||||
c.API.Endpoints.WebsocketURL = coinutWebsocketURL
|
||||
c.API.Endpoints = c.NewEndpoints()
|
||||
err = c.API.Endpoints.SetDefaultEndpoints(map[exchange.URL]string{
|
||||
exchange.RestSpot: coinutAPIURL,
|
||||
exchange.WebsocketSpot: coinutWebsocketURL,
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorln(log.ExchangeSys, err)
|
||||
}
|
||||
c.Websocket = stream.New()
|
||||
c.WebsocketResponseMaxLimit = exchange.DefaultWebsocketResponseMaxLimit
|
||||
c.WebsocketResponseCheckTimeout = exchange.DefaultWebsocketResponseCheckTimeout
|
||||
@@ -136,6 +140,11 @@ func (c *COINUT) 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,
|
||||
@@ -143,7 +152,7 @@ func (c *COINUT) Setup(exch *config.ExchangeConfig) error {
|
||||
WebsocketTimeout: exch.WebsocketTrafficTimeout,
|
||||
DefaultURL: coinutWebsocketURL,
|
||||
ExchangeName: exch.Name,
|
||||
RunningURL: exch.API.Endpoints.WebsocketURL,
|
||||
RunningURL: wsRunningURL,
|
||||
Connector: c.WsConnect,
|
||||
Subscriber: c.Subscribe,
|
||||
UnSubscriber: c.Unsubscribe,
|
||||
@@ -294,7 +303,7 @@ func (c *COINUT) UpdateTradablePairs(forceUpdate bool) error {
|
||||
|
||||
// UpdateAccountInfo retrieves balances for all enabled currencies for the
|
||||
// COINUT exchange
|
||||
func (c *COINUT) UpdateAccountInfo() (account.Holdings, error) {
|
||||
func (c *COINUT) UpdateAccountInfo(assetType asset.Item) (account.Holdings, error) {
|
||||
var info account.Holdings
|
||||
var bal *UserBalance
|
||||
var err error
|
||||
@@ -384,10 +393,10 @@ func (c *COINUT) UpdateAccountInfo() (account.Holdings, error) {
|
||||
}
|
||||
|
||||
// FetchAccountInfo retrieves balances for all enabled currencies
|
||||
func (c *COINUT) FetchAccountInfo() (account.Holdings, error) {
|
||||
acc, err := account.GetHoldings(c.Name)
|
||||
func (c *COINUT) 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
|
||||
@@ -1054,8 +1063,8 @@ func (c *COINUT) loadInstrumentsIfNotLoaded() error {
|
||||
|
||||
// ValidateCredentials validates current credentials used for wrapper
|
||||
// functionality
|
||||
func (c *COINUT) ValidateCredentials() error {
|
||||
_, err := c.UpdateAccountInfo()
|
||||
func (c *COINUT) ValidateCredentials(assetType asset.Item) error {
|
||||
_, err := c.UpdateAccountInfo(assetType)
|
||||
return c.CheckTransientError(err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user