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:
Adam
2021-02-12 16:19:18 +11:00
committed by GitHub
parent e9bd2ad4d8
commit 504c2fad6d
169 changed files with 227754 additions and 31776 deletions

View File

@@ -57,8 +57,8 @@ func (e *EXMO) GetTrades(symbol string) (map[string][]Trades, error) {
v := url.Values{}
v.Set("pair", symbol)
result := make(map[string][]Trades)
urlPath := fmt.Sprintf("%s/v%s/%s", e.API.Endpoints.URL, exmoAPIVersion, exmoTrades)
return result, e.SendHTTPRequest(common.EncodeURLValues(urlPath, v), &result)
urlPath := fmt.Sprintf("/v%s/%s", exmoAPIVersion, exmoTrades)
return result, e.SendHTTPRequest(exchange.RestSpot, common.EncodeURLValues(urlPath, v), &result)
}
// GetOrderbook returns the orderbook for a symbol or symbols
@@ -66,36 +66,36 @@ func (e *EXMO) GetOrderbook(symbol string) (map[string]Orderbook, error) {
v := url.Values{}
v.Set("pair", symbol)
result := make(map[string]Orderbook)
urlPath := fmt.Sprintf("%s/v%s/%s", e.API.Endpoints.URL, exmoAPIVersion, exmoOrderbook)
return result, e.SendHTTPRequest(common.EncodeURLValues(urlPath, v), &result)
urlPath := fmt.Sprintf("/v%s/%s", exmoAPIVersion, exmoOrderbook)
return result, e.SendHTTPRequest(exchange.RestSpot, common.EncodeURLValues(urlPath, v), &result)
}
// GetTicker returns the ticker for a symbol or symbols
func (e *EXMO) GetTicker() (map[string]Ticker, error) {
v := url.Values{}
result := make(map[string]Ticker)
urlPath := fmt.Sprintf("%s/v%s/%s", e.API.Endpoints.URL, exmoAPIVersion, exmoTicker)
return result, e.SendHTTPRequest(common.EncodeURLValues(urlPath, v), &result)
urlPath := fmt.Sprintf("/v%s/%s", exmoAPIVersion, exmoTicker)
return result, e.SendHTTPRequest(exchange.RestSpot, common.EncodeURLValues(urlPath, v), &result)
}
// GetPairSettings returns the pair settings for a symbol or symbols
func (e *EXMO) GetPairSettings() (map[string]PairSettings, error) {
result := make(map[string]PairSettings)
urlPath := fmt.Sprintf("%s/v%s/%s", e.API.Endpoints.URL, exmoAPIVersion, exmoPairSettings)
return result, e.SendHTTPRequest(urlPath, &result)
urlPath := fmt.Sprintf("/v%s/%s", exmoAPIVersion, exmoPairSettings)
return result, e.SendHTTPRequest(exchange.RestSpot, urlPath, &result)
}
// GetCurrency returns a list of currencies
func (e *EXMO) GetCurrency() ([]string, error) {
var result []string
urlPath := fmt.Sprintf("%s/v%s/%s", e.API.Endpoints.URL, exmoAPIVersion, exmoCurrency)
return result, e.SendHTTPRequest(urlPath, &result)
urlPath := fmt.Sprintf("/v%s/%s", exmoAPIVersion, exmoCurrency)
return result, e.SendHTTPRequest(exchange.RestSpot, urlPath, &result)
}
// GetUserInfo returns the user info
func (e *EXMO) GetUserInfo() (UserInfo, error) {
var result UserInfo
err := e.SendAuthenticatedHTTPRequest(http.MethodPost, exmoUserInfo, url.Values{}, &result)
err := e.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, exmoUserInfo, url.Values{}, &result)
return result, err
}
@@ -116,7 +116,7 @@ func (e *EXMO) CreateOrder(pair, orderType string, price, amount float64) (int64
v.Set("quantity", strconv.FormatFloat(amount, 'f', -1, 64))
var resp response
err := e.SendAuthenticatedHTTPRequest(http.MethodPost, exmoOrderCreate, v, &resp)
err := e.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, exmoOrderCreate, v, &resp)
if !resp.Result {
return -1, errors.New(resp.Error)
}
@@ -132,7 +132,7 @@ func (e *EXMO) CancelExistingOrder(orderID int64) error {
Error string `json:"error"`
}
var resp response
err := e.SendAuthenticatedHTTPRequest(http.MethodPost, exmoOrderCancel, v, &resp)
err := e.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, exmoOrderCancel, v, &resp)
if !resp.Result {
return errors.New(resp.Error)
}
@@ -142,7 +142,7 @@ func (e *EXMO) CancelExistingOrder(orderID int64) error {
// GetOpenOrders returns the users open orders
func (e *EXMO) GetOpenOrders() (map[string]OpenOrders, error) {
result := make(map[string]OpenOrders)
err := e.SendAuthenticatedHTTPRequest(http.MethodPost, exmoOpenOrders, url.Values{}, &result)
err := e.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, exmoOpenOrders, url.Values{}, &result)
return result, err
}
@@ -160,7 +160,7 @@ func (e *EXMO) GetUserTrades(pair, offset, limit string) (map[string][]UserTrade
v.Set("limit", limit)
}
err := e.SendAuthenticatedHTTPRequest(http.MethodPost, exmoUserTrades, v, &result)
err := e.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, exmoUserTrades, v, &result)
return result, err
}
@@ -177,7 +177,7 @@ func (e *EXMO) GetCancelledOrders(offset, limit string) ([]CancelledOrder, error
v.Set("limit", limit)
}
err := e.SendAuthenticatedHTTPRequest(http.MethodPost, exmoCancelledOrders, v, &result)
err := e.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, exmoCancelledOrders, v, &result)
return result, err
}
@@ -187,7 +187,7 @@ func (e *EXMO) GetOrderTrades(orderID int64) (OrderTrades, error) {
v := url.Values{}
v.Set("order_id", strconv.FormatInt(orderID, 10))
err := e.SendAuthenticatedHTTPRequest(http.MethodPost, exmoOrderTrades, v, &result)
err := e.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, exmoOrderTrades, v, &result)
return result, err
}
@@ -198,14 +198,14 @@ func (e *EXMO) GetRequiredAmount(pair string, amount float64) (RequiredAmount, e
v.Set("pair", pair)
v.Set("quantity", strconv.FormatFloat(amount, 'f', -1, 64))
var result RequiredAmount
err := e.SendAuthenticatedHTTPRequest(http.MethodPost, exmoRequiredAmount, v, &result)
err := e.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, exmoRequiredAmount, v, &result)
return result, err
}
// GetCryptoDepositAddress returns a list of addresses for cryptocurrency deposits
func (e *EXMO) GetCryptoDepositAddress() (map[string]string, error) {
var result interface{}
err := e.SendAuthenticatedHTTPRequest(http.MethodPost, exmoDepositAddress, url.Values{}, &result)
err := e.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, exmoDepositAddress, url.Values{}, &result)
if err != nil {
return nil, err
}
@@ -243,7 +243,7 @@ func (e *EXMO) WithdrawCryptocurrency(currency, address, invoice string, amount
v.Set("amount", strconv.FormatFloat(amount, 'f', -1, 64))
var resp response
err := e.SendAuthenticatedHTTPRequest(http.MethodPost, exmoWithdrawCrypt, v, &resp)
err := e.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, exmoWithdrawCrypt, v, &resp)
if err != nil {
return -1, err
}
@@ -264,7 +264,7 @@ func (e *EXMO) GetWithdrawTXID(taskID int64) (string, error) {
v.Set("task_id", strconv.FormatInt(taskID, 10))
var result response
err := e.SendAuthenticatedHTTPRequest(http.MethodPost, exmoGetWithdrawTXID, v, &result)
err := e.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, exmoGetWithdrawTXID, v, &result)
return result.TXID, err
}
@@ -275,7 +275,7 @@ func (e *EXMO) ExcodeCreate(currency string, amount float64) (ExcodeCreate, erro
v.Set("amount", strconv.FormatFloat(amount, 'f', -1, 64))
var result ExcodeCreate
err := e.SendAuthenticatedHTTPRequest(http.MethodPost, exmoExcodeCreate, v, &result)
err := e.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, exmoExcodeCreate, v, &result)
return result, err
}
@@ -285,7 +285,7 @@ func (e *EXMO) ExcodeLoad(excode string) (ExcodeLoad, error) {
v.Set("code", excode)
var result ExcodeLoad
err := e.SendAuthenticatedHTTPRequest(http.MethodPost, exmoExcodeLoad, v, &result)
err := e.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, exmoExcodeLoad, v, &result)
return result, err
}
@@ -295,15 +295,19 @@ func (e *EXMO) GetWalletHistory(date int64) (WalletHistory, error) {
v.Set("date", strconv.FormatInt(date, 10))
var result WalletHistory
err := e.SendAuthenticatedHTTPRequest(http.MethodPost, exmoWalletHistory, v, &result)
err := e.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, exmoWalletHistory, v, &result)
return result, err
}
// SendHTTPRequest sends an unauthenticated HTTP request
func (e *EXMO) SendHTTPRequest(path string, result interface{}) error {
func (e *EXMO) SendHTTPRequest(endpoint exchange.URL, path string, result interface{}) error {
urlPath, err := e.API.Endpoints.GetURL(endpoint)
if err != nil {
return err
}
return e.SendPayload(context.Background(), &request.Item{
Method: http.MethodGet,
Path: path,
Path: urlPath + path,
Result: result,
Verbose: e.Verbose,
HTTPDebugging: e.HTTPDebugging,
@@ -312,12 +316,17 @@ func (e *EXMO) SendHTTPRequest(path string, result interface{}) error {
}
// SendAuthenticatedHTTPRequest sends an authenticated HTTP request
func (e *EXMO) SendAuthenticatedHTTPRequest(method, endpoint string, vals url.Values, result interface{}) error {
func (e *EXMO) SendAuthenticatedHTTPRequest(epath exchange.URL, method, endpoint string, vals url.Values, result interface{}) error {
if !e.AllowAuthenticatedRequest() {
return fmt.Errorf(exchange.WarningAuthenticatedRequestWithoutCredentialsSet,
e.Name)
}
urlPath, err := e.API.Endpoints.GetURL(epath)
if err != nil {
return err
}
n := e.Requester.GetNonce(true).String()
vals.Set("nonce", n)
@@ -338,11 +347,11 @@ func (e *EXMO) SendAuthenticatedHTTPRequest(method, endpoint string, vals url.Va
headers["Sign"] = crypto.HexEncodeToString(hash)
headers["Content-Type"] = "application/x-www-form-urlencoded"
path := fmt.Sprintf("%s/v%s/%s", e.API.Endpoints.URL, exmoAPIVersion, endpoint)
path := fmt.Sprintf("/v%s/%s", exmoAPIVersion, endpoint)
return e.SendPayload(context.Background(), &request.Item{
Method: method,
Path: path,
Path: urlPath + path,
Headers: headers,
Body: strings.NewReader(payload),
Result: result,

View File

@@ -264,7 +264,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 := e.GetActiveOrders(&getOrdersRequest)
@@ -277,7 +278,8 @@ func TestGetActiveOrders(t *testing.T) {
func TestGetOrderHistory(t *testing.T) {
var getOrdersRequest = order.GetOrdersRequest{
Type: order.AnyType,
Type: order.AnyType,
AssetType: asset.Spot,
}
currPair := currency.NewPair(currency.BTC, currency.USD)
currPair.Delimiter = "_"

View File

@@ -108,9 +108,13 @@ func (e *EXMO) SetDefaults() {
e.Requester = request.New(e.Name,
common.NewHTTPClientWithTimeout(exchange.DefaultHTTPTimeout),
request.WithLimiter(request.NewBasicRateLimit(exmoRateInterval, exmoRequestRate)))
e.API.Endpoints.URLDefault = exmoAPIURL
e.API.Endpoints.URL = e.API.Endpoints.URLDefault
e.API.Endpoints = e.NewEndpoints()
err = e.API.Endpoints.SetDefaultEndpoints(map[exchange.URL]string{
exchange.RestSpot: exmoAPIURL,
})
if err != nil {
log.Errorln(log.ExchangeSys, err)
}
}
// Setup takes in the supplied exchange configuration details and sets params
@@ -320,7 +324,7 @@ func (e *EXMO) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*orderboo
// UpdateAccountInfo retrieves balances for all enabled currencies for the
// Exmo exchange
func (e *EXMO) UpdateAccountInfo() (account.Holdings, error) {
func (e *EXMO) UpdateAccountInfo(assetType asset.Item) (account.Holdings, error) {
var response account.Holdings
response.Exchange = e.Name
result, err := e.GetUserInfo()
@@ -356,10 +360,10 @@ func (e *EXMO) UpdateAccountInfo() (account.Holdings, error) {
}
// FetchAccountInfo retrieves balances for all enabled currencies
func (e *EXMO) FetchAccountInfo() (account.Holdings, error) {
acc, err := account.GetHoldings(e.Name)
func (e *EXMO) FetchAccountInfo(assetType asset.Item) (account.Holdings, error) {
acc, err := account.GetHoldings(e.Name, assetType)
if err != nil {
return e.UpdateAccountInfo()
return e.UpdateAccountInfo(assetType)
}
return acc, nil
@@ -655,8 +659,8 @@ func (e *EXMO) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, err
// ValidateCredentials validates current credentials used for wrapper
// functionality
func (e *EXMO) ValidateCredentials() error {
_, err := e.UpdateAccountInfo()
func (e *EXMO) ValidateCredentials(assetType asset.Item) error {
_, err := e.UpdateAccountInfo(assetType)
return e.CheckTransientError(err)
}