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

@@ -43,9 +43,9 @@ type LakeBTC struct {
// GetTicker returns the current ticker from lakeBTC
func (l *LakeBTC) GetTicker() (map[string]Ticker, error) {
response := make(map[string]TickerResponse)
path := fmt.Sprintf("%s/%s", l.API.Endpoints.URL, lakeBTCTicker)
path := fmt.Sprintf("/%s", lakeBTCTicker)
err := l.SendHTTPRequest(path, &response)
err := l.SendHTTPRequest(exchange.RestSpot, path, &response)
if err != nil {
return nil, err
}
@@ -102,9 +102,9 @@ func (l *LakeBTC) GetOrderBook(currency string) (Orderbook, error) {
Bids [][]string `json:"bids"`
Asks [][]string `json:"asks"`
}
path := fmt.Sprintf("%s/%s?symbol=%s", l.API.Endpoints.URL, lakeBTCOrderbook, strings.ToLower(currency))
path := fmt.Sprintf("/%s?symbol=%s", lakeBTCOrderbook, strings.ToLower(currency))
resp := Response{}
err := l.SendHTTPRequest(path, &resp)
err := l.SendHTTPRequest(exchange.RestSpot, path, &resp)
if err != nil {
return Orderbook{}, err
}
@@ -144,15 +144,15 @@ func (l *LakeBTC) GetOrderBook(currency string) (Orderbook, error) {
func (l *LakeBTC) GetTradeHistory(currency string) ([]TradeHistory, error) {
v := url.Values{}
v.Set("symbol", strings.ToLower(currency))
path := fmt.Sprintf("%s/%s?%s", l.API.Endpoints.URL, lakeBTCTrades, v.Encode())
path := fmt.Sprintf("/%s?%s", lakeBTCTrades, v.Encode())
var resp []TradeHistory
return resp, l.SendHTTPRequest(path, &resp)
return resp, l.SendHTTPRequest(exchange.RestSpot, path, &resp)
}
// GetAccountInformation returns your current account information
func (l *LakeBTC) GetAccountInformation() (AccountInfo, error) {
resp := AccountInfo{}
return resp, l.SendAuthenticatedHTTPRequest(lakeBTCGetAccountInfo, "", &resp)
return resp, l.SendAuthenticatedHTTPRequest(exchange.RestSpot, lakeBTCGetAccountInfo, "", &resp)
}
// Trade executes an order on the exchange and returns trade inforamtion or an
@@ -162,11 +162,11 @@ func (l *LakeBTC) Trade(isBuyOrder bool, amount, price float64, currency string)
params := strconv.FormatFloat(price, 'f', -1, 64) + "," + strconv.FormatFloat(amount, 'f', -1, 64) + "," + currency
if isBuyOrder {
if err := l.SendAuthenticatedHTTPRequest(lakeBTCBuyOrder, params, &resp); err != nil {
if err := l.SendAuthenticatedHTTPRequest(exchange.RestSpot, lakeBTCBuyOrder, params, &resp); err != nil {
return resp, err
}
} else {
if err := l.SendAuthenticatedHTTPRequest(lakeBTCSellOrder, params, &resp); err != nil {
if err := l.SendAuthenticatedHTTPRequest(exchange.RestSpot, lakeBTCSellOrder, params, &resp); err != nil {
return resp, err
}
}
@@ -182,7 +182,7 @@ func (l *LakeBTC) Trade(isBuyOrder bool, amount, price float64, currency string)
func (l *LakeBTC) GetOpenOrders() ([]OpenOrders, error) {
var orders []OpenOrders
return orders, l.SendAuthenticatedHTTPRequest(lakeBTCOpenOrders, "", &orders)
return orders, l.SendAuthenticatedHTTPRequest(exchange.RestSpot, lakeBTCOpenOrders, "", &orders)
}
// GetOrders returns your orders
@@ -194,7 +194,7 @@ func (l *LakeBTC) GetOrders(orders []int64) ([]Orders, error) {
var resp []Orders
return resp,
l.SendAuthenticatedHTTPRequest(lakeBTCGetOrders, strings.Join(ordersStr, ","), &resp)
l.SendAuthenticatedHTTPRequest(exchange.RestSpot, lakeBTCGetOrders, strings.Join(ordersStr, ","), &resp)
}
// CancelExistingOrder cancels an order by ID number and returns an error
@@ -205,7 +205,7 @@ func (l *LakeBTC) CancelExistingOrder(orderID int64) error {
resp := Response{}
params := strconv.FormatInt(orderID, 10)
err := l.SendAuthenticatedHTTPRequest(lakeBTCCancelOrder, params, &resp)
err := l.SendAuthenticatedHTTPRequest(exchange.RestSpot, lakeBTCCancelOrder, params, &resp)
if err != nil {
return err
}
@@ -224,7 +224,7 @@ func (l *LakeBTC) CancelExistingOrders(orderIDs []string) error {
resp := Response{}
params := strings.Join(orderIDs, ",")
err := l.SendAuthenticatedHTTPRequest(lakeBTCCancelOrder, params, &resp)
err := l.SendAuthenticatedHTTPRequest(exchange.RestSpot, lakeBTCCancelOrder, params, &resp)
if err != nil {
return err
}
@@ -243,14 +243,14 @@ func (l *LakeBTC) GetTrades(timestamp int64) ([]AuthenticatedTradeHistory, error
}
var trades []AuthenticatedTradeHistory
return trades, l.SendAuthenticatedHTTPRequest(lakeBTCGetTrades, params, &trades)
return trades, l.SendAuthenticatedHTTPRequest(exchange.RestSpot, lakeBTCGetTrades, params, &trades)
}
// GetExternalAccounts returns your external accounts WARNING: Only for BTC!
func (l *LakeBTC) GetExternalAccounts() ([]ExternalAccounts, error) {
var resp []ExternalAccounts
return resp, l.SendAuthenticatedHTTPRequest(lakeBTCGetExternalAccounts, "", &resp)
return resp, l.SendAuthenticatedHTTPRequest(exchange.RestSpot, lakeBTCGetExternalAccounts, "", &resp)
}
// CreateWithdraw allows your to withdraw to external account WARNING: Only for
@@ -259,7 +259,7 @@ func (l *LakeBTC) CreateWithdraw(amount float64, accountID string) (Withdraw, er
resp := Withdraw{}
params := strconv.FormatFloat(amount, 'f', -1, 64) + ",btc," + accountID
err := l.SendAuthenticatedHTTPRequest(lakeBTCCreateWithdraw, params, &resp)
err := l.SendAuthenticatedHTTPRequest(exchange.RestSpot, lakeBTCCreateWithdraw, params, &resp)
if err != nil {
return Withdraw{}, err
}
@@ -271,10 +271,14 @@ func (l *LakeBTC) CreateWithdraw(amount float64, accountID string) (Withdraw, er
}
// SendHTTPRequest sends an unauthenticated http request
func (l *LakeBTC) SendHTTPRequest(path string, result interface{}) error {
func (l *LakeBTC) SendHTTPRequest(endpoint exchange.URL, path string, result interface{}) error {
pathURL, err := l.API.Endpoints.GetURL(endpoint)
if err != nil {
return err
}
return l.SendPayload(context.Background(), &request.Item{
Method: http.MethodGet,
Path: path,
Path: pathURL + path,
Result: result,
Verbose: l.Verbose,
HTTPDebugging: l.HTTPDebugging,
@@ -283,18 +287,21 @@ func (l *LakeBTC) SendHTTPRequest(path string, result interface{}) error {
}
// SendAuthenticatedHTTPRequest sends an autheticated HTTP request to a LakeBTC
func (l *LakeBTC) SendAuthenticatedHTTPRequest(method, params string, result interface{}) (err error) {
func (l *LakeBTC) SendAuthenticatedHTTPRequest(ep exchange.URL, method, params string, result interface{}) (err error) {
if !l.AllowAuthenticatedRequest() {
return fmt.Errorf(exchange.WarningAuthenticatedRequestWithoutCredentialsSet, l.Name)
}
endpoint, err := l.API.Endpoints.GetURL(ep)
if err != nil {
return err
}
n := l.Requester.GetNonce(true).String()
req := fmt.Sprintf("tonce=%s&accesskey=%s&requestmethod=post&id=1&method=%s&params=%s", n, l.API.Credentials.Key, method, params)
hmac := crypto.GetHMAC(crypto.HashSHA1, []byte(req), []byte(l.API.Credentials.Secret))
if l.Verbose {
log.Debugf(log.ExchangeSys, "Sending POST request to %s calling method %s with params %s\n", l.API.Endpoints.URL, method, req)
log.Debugf(log.ExchangeSys, "Sending POST request to %s calling method %s with params %s\n", endpoint, method, req)
}
postData := make(map[string]interface{})
@@ -314,7 +321,7 @@ func (l *LakeBTC) SendAuthenticatedHTTPRequest(method, params string, result int
return l.SendPayload(context.Background(), &request.Item{
Method: http.MethodPost,
Path: l.API.Endpoints.URL,
Path: endpoint,
Headers: headers,
Body: strings.NewReader(string(data)),
Result: result,

View File

@@ -263,7 +263,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 := l.GetActiveOrders(&getOrdersRequest)
@@ -276,7 +277,8 @@ func TestGetActiveOrders(t *testing.T) {
func TestGetOrderHistory(t *testing.T) {
var getOrdersRequest = order.GetOrdersRequest{
Type: order.AnyType,
Type: order.AnyType,
AssetType: asset.Spot,
}
_, err := l.GetOrderHistory(&getOrdersRequest)

View File

@@ -102,11 +102,15 @@ func (l *LakeBTC) SetDefaults() {
l.Requester = request.New(l.Name,
common.NewHTTPClientWithTimeout(exchange.DefaultHTTPTimeout))
l.API.Endpoints.URLDefault = lakeBTCAPIURL
l.API.Endpoints.URL = l.API.Endpoints.URLDefault
l.API.Endpoints = l.NewEndpoints()
err = l.API.Endpoints.SetDefaultEndpoints(map[exchange.URL]string{
exchange.RestSpot: lakeBTCAPIURL,
exchange.WebsocketSpot: lakeBTCWSURL,
})
if err != nil {
log.Errorln(log.ExchangeSys, err)
}
l.Websocket = stream.New()
l.API.Endpoints.WebsocketURL = lakeBTCWSURL
l.WebsocketResponseMaxLimit = exchange.DefaultWebsocketResponseMaxLimit
l.WebsocketResponseCheckTimeout = exchange.DefaultWebsocketResponseCheckTimeout
l.WebsocketOrderbookBufferLimit = exchange.DefaultWebsocketOrderbookBufferLimit
@@ -124,6 +128,11 @@ func (l *LakeBTC) Setup(exch *config.ExchangeConfig) error {
return err
}
wsRunningURL, err := l.API.Endpoints.GetURL(exchange.WebsocketSpot)
if err != nil {
return err
}
return l.Websocket.Setup(&stream.WebsocketSetup{
Enabled: exch.Features.Enabled.Websocket,
Verbose: exch.Verbose,
@@ -131,7 +140,7 @@ func (l *LakeBTC) Setup(exch *config.ExchangeConfig) error {
WebsocketTimeout: exch.WebsocketTrafficTimeout,
DefaultURL: lakeBTCWSURL,
ExchangeName: exch.Name,
RunningURL: exch.API.Endpoints.WebsocketURL,
RunningURL: wsRunningURL,
Connector: l.WsConnect,
Subscriber: l.Subscribe,
UnSubscriber: l.Unsubscribe,
@@ -305,7 +314,7 @@ func (l *LakeBTC) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*order
// UpdateAccountInfo retrieves balances for all enabled currencies for the
// LakeBTC exchange
func (l *LakeBTC) UpdateAccountInfo() (account.Holdings, error) {
func (l *LakeBTC) UpdateAccountInfo(assetType asset.Item) (account.Holdings, error) {
var response account.Holdings
response.Exchange = l.Name
accountInfo, err := l.GetAccountInformation()
@@ -340,10 +349,10 @@ func (l *LakeBTC) UpdateAccountInfo() (account.Holdings, error) {
}
// FetchAccountInfo retrieves balances for all enabled currencies
func (l *LakeBTC) FetchAccountInfo() (account.Holdings, error) {
acc, err := account.GetHoldings(l.Name)
func (l *LakeBTC) FetchAccountInfo(assetType asset.Item) (account.Holdings, error) {
acc, err := account.GetHoldings(l.Name, assetType)
if err != nil {
return l.UpdateAccountInfo()
return l.UpdateAccountInfo(assetType)
}
return acc, nil
@@ -630,8 +639,8 @@ func (l *LakeBTC) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail,
// ValidateCredentials validates current credentials used for wrapper
// functionality
func (l *LakeBTC) ValidateCredentials() error {
_, err := l.UpdateAccountInfo()
func (l *LakeBTC) ValidateCredentials(assetType asset.Item) error {
_, err := l.UpdateAccountInfo(assetType)
return l.CheckTransientError(err)
}