mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-24 23:16:52 +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:
@@ -68,10 +68,7 @@ func (b *Bithumb) GetTradablePairs() ([]string, error) {
|
||||
// symbol e.g. "btc"
|
||||
func (b *Bithumb) GetTicker(symbol string) (Ticker, error) {
|
||||
var response TickerResponse
|
||||
path := b.API.Endpoints.URL +
|
||||
publicTicker +
|
||||
strings.ToUpper(symbol)
|
||||
err := b.SendHTTPRequest(path, &response)
|
||||
err := b.SendHTTPRequest(exchange.RestSpot, publicTicker+strings.ToUpper(symbol), &response)
|
||||
if err != nil {
|
||||
return response.Data, err
|
||||
}
|
||||
@@ -86,8 +83,7 @@ func (b *Bithumb) GetTicker(symbol string) (Ticker, error) {
|
||||
// GetAllTickers returns all ticker information
|
||||
func (b *Bithumb) GetAllTickers() (map[string]Ticker, error) {
|
||||
var response TickersResponse
|
||||
path := b.API.Endpoints.URL + publicTicker + "all"
|
||||
err := b.SendHTTPRequest(path, &response)
|
||||
err := b.SendHTTPRequest(exchange.RestSpot, publicTicker+"all", &response)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -116,9 +112,7 @@ func (b *Bithumb) GetAllTickers() (map[string]Ticker, error) {
|
||||
// symbol e.g. "btc"
|
||||
func (b *Bithumb) GetOrderBook(symbol string) (Orderbook, error) {
|
||||
response := Orderbook{}
|
||||
path := b.API.Endpoints.URL + publicOrderBook + strings.ToUpper(symbol)
|
||||
|
||||
err := b.SendHTTPRequest(path, &response)
|
||||
err := b.SendHTTPRequest(exchange.RestSpot, publicOrderBook+strings.ToUpper(symbol), &response)
|
||||
if err != nil {
|
||||
return response, err
|
||||
}
|
||||
@@ -135,11 +129,10 @@ func (b *Bithumb) GetOrderBook(symbol string) (Orderbook, error) {
|
||||
// symbol e.g. "btc"
|
||||
func (b *Bithumb) GetTransactionHistory(symbol string) (TransactionHistory, error) {
|
||||
response := TransactionHistory{}
|
||||
path := b.API.Endpoints.URL +
|
||||
publicTransactionHistory +
|
||||
path := publicTransactionHistory +
|
||||
strings.ToUpper(symbol)
|
||||
|
||||
err := b.SendHTTPRequest(path, &response)
|
||||
err := b.SendHTTPRequest(exchange.RestSpot, path, &response)
|
||||
if err != nil {
|
||||
return response, err
|
||||
}
|
||||
@@ -166,7 +159,7 @@ func (b *Bithumb) GetAccountInformation(orderCurrency, paymentCurrency string) (
|
||||
}
|
||||
|
||||
return response,
|
||||
b.SendAuthenticatedHTTPRequest(privateAccInfo, val, &response)
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, privateAccInfo, val, &response)
|
||||
}
|
||||
|
||||
// GetAccountBalance returns customer wallet information
|
||||
@@ -185,7 +178,7 @@ func (b *Bithumb) GetAccountBalance(c string) (FullBalance, error) {
|
||||
vals.Set("currency", c)
|
||||
}
|
||||
|
||||
err := b.SendAuthenticatedHTTPRequest(privateAccBalance, vals, &response)
|
||||
err := b.SendAuthenticatedHTTPRequest(exchange.RestSpot, privateAccBalance, vals, &response)
|
||||
if err != nil {
|
||||
return fullBalance, err
|
||||
}
|
||||
@@ -238,7 +231,7 @@ func (b *Bithumb) GetWalletAddress(currency string) (WalletAddressRes, error) {
|
||||
params := url.Values{}
|
||||
params.Set("currency", strings.ToUpper(currency))
|
||||
|
||||
err := b.SendAuthenticatedHTTPRequest(privateWalletAdd, params, &response)
|
||||
err := b.SendAuthenticatedHTTPRequest(exchange.RestSpot, privateWalletAdd, params, &response)
|
||||
if err != nil {
|
||||
return response, err
|
||||
}
|
||||
@@ -257,7 +250,7 @@ func (b *Bithumb) GetLastTransaction() (LastTransactionTicker, error) {
|
||||
response := LastTransactionTicker{}
|
||||
|
||||
return response,
|
||||
b.SendAuthenticatedHTTPRequest(privateTicker, nil, &response)
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, privateTicker, nil, &response)
|
||||
}
|
||||
|
||||
// GetOrders returns order list
|
||||
@@ -292,7 +285,7 @@ func (b *Bithumb) GetOrders(orderID, transactionType, count, after, currency str
|
||||
}
|
||||
|
||||
return response,
|
||||
b.SendAuthenticatedHTTPRequest(privateOrders, params, &response)
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, privateOrders, params, &response)
|
||||
}
|
||||
|
||||
// GetUserTransactions returns customer transactions
|
||||
@@ -300,7 +293,7 @@ func (b *Bithumb) GetUserTransactions() (UserTransactions, error) {
|
||||
response := UserTransactions{}
|
||||
|
||||
return response,
|
||||
b.SendAuthenticatedHTTPRequest(privateUserTrans, nil, &response)
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, privateUserTrans, nil, &response)
|
||||
}
|
||||
|
||||
// PlaceTrade executes a trade order
|
||||
@@ -321,7 +314,7 @@ func (b *Bithumb) PlaceTrade(orderCurrency, transactionType string, units float6
|
||||
params.Set("price", strconv.FormatInt(price, 10))
|
||||
|
||||
return response,
|
||||
b.SendAuthenticatedHTTPRequest(privatePlaceTrade, params, &response)
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, privatePlaceTrade, params, &response)
|
||||
}
|
||||
|
||||
// ModifyTrade modifies an order already on the exchange books
|
||||
@@ -337,7 +330,7 @@ func (b *Bithumb) ModifyTrade(orderID, orderCurrency, transactionType string, un
|
||||
params.Set("order_id", orderID)
|
||||
|
||||
return response,
|
||||
b.SendAuthenticatedHTTPRequest(privatePlaceTrade, params, &response)
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, privatePlaceTrade, params, &response)
|
||||
}
|
||||
|
||||
// GetOrderDetails returns specific order details
|
||||
@@ -355,7 +348,7 @@ func (b *Bithumb) GetOrderDetails(orderID, transactionType, currency string) (Or
|
||||
params.Set("currency", strings.ToUpper(currency))
|
||||
|
||||
return response,
|
||||
b.SendAuthenticatedHTTPRequest(privateOrderDetail, params, &response)
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, privateOrderDetail, params, &response)
|
||||
}
|
||||
|
||||
// CancelTrade cancels a customer purchase/sales transaction
|
||||
@@ -372,7 +365,7 @@ func (b *Bithumb) CancelTrade(transactionType, orderID, currency string) (Action
|
||||
params.Set("currency", strings.ToUpper(currency))
|
||||
|
||||
return response,
|
||||
b.SendAuthenticatedHTTPRequest(privateCancelTrade, nil, &response)
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, privateCancelTrade, nil, &response)
|
||||
}
|
||||
|
||||
// WithdrawCrypto withdraws a customer currency to an address
|
||||
@@ -395,7 +388,7 @@ func (b *Bithumb) WithdrawCrypto(address, destination, currency string, units fl
|
||||
params.Set("units", strconv.FormatFloat(units, 'f', -1, 64))
|
||||
|
||||
return response,
|
||||
b.SendAuthenticatedHTTPRequest(privateBTCWithdraw, params, &response)
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, privateBTCWithdraw, params, &response)
|
||||
}
|
||||
|
||||
// RequestKRWDepositDetails returns Bithumb banking details for deposit
|
||||
@@ -404,7 +397,7 @@ func (b *Bithumb) RequestKRWDepositDetails() (KRWDeposit, error) {
|
||||
response := KRWDeposit{}
|
||||
|
||||
return response,
|
||||
b.SendAuthenticatedHTTPRequest(privateKRWDeposit, nil, &response)
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, privateKRWDeposit, nil, &response)
|
||||
}
|
||||
|
||||
// RequestKRWWithdraw allows a customer KRW withdrawal request
|
||||
@@ -421,7 +414,7 @@ func (b *Bithumb) RequestKRWWithdraw(bank, account string, price int64) (ActionS
|
||||
params.Set("price", strconv.FormatInt(price, 10))
|
||||
|
||||
return response,
|
||||
b.SendAuthenticatedHTTPRequest(privateKRWWithdraw, params, &response)
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, privateKRWWithdraw, params, &response)
|
||||
}
|
||||
|
||||
// MarketBuyOrder initiates a buy order through available order books
|
||||
@@ -437,7 +430,7 @@ func (b *Bithumb) MarketBuyOrder(currency string, units float64) (MarketBuy, err
|
||||
params.Set("units", strconv.FormatFloat(units, 'f', -1, 64))
|
||||
|
||||
return response,
|
||||
b.SendAuthenticatedHTTPRequest(privateMarketBuy, params, &response)
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, privateMarketBuy, params, &response)
|
||||
}
|
||||
|
||||
// MarketSellOrder initiates a sell order through available order books
|
||||
@@ -453,14 +446,18 @@ func (b *Bithumb) MarketSellOrder(currency string, units float64) (MarketSell, e
|
||||
params.Set("units", strconv.FormatFloat(units, 'f', -1, 64))
|
||||
|
||||
return response,
|
||||
b.SendAuthenticatedHTTPRequest(privateMarketSell, params, &response)
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, privateMarketSell, params, &response)
|
||||
}
|
||||
|
||||
// SendHTTPRequest sends an unauthenticated HTTP request
|
||||
func (b *Bithumb) SendHTTPRequest(path string, result interface{}) error {
|
||||
func (b *Bithumb) SendHTTPRequest(ep exchange.URL, path string, result interface{}) error {
|
||||
endpoint, err := b.API.Endpoints.GetURL(ep)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return b.SendPayload(context.Background(), &request.Item{
|
||||
Method: http.MethodGet,
|
||||
Path: path,
|
||||
Path: endpoint + path,
|
||||
Result: result,
|
||||
Verbose: b.Verbose,
|
||||
HTTPDebugging: b.HTTPDebugging,
|
||||
@@ -469,11 +466,14 @@ func (b *Bithumb) SendHTTPRequest(path string, result interface{}) error {
|
||||
}
|
||||
|
||||
// SendAuthenticatedHTTPRequest sends an authenticated HTTP request to bithumb
|
||||
func (b *Bithumb) SendAuthenticatedHTTPRequest(path string, params url.Values, result interface{}) error {
|
||||
func (b *Bithumb) SendAuthenticatedHTTPRequest(ep exchange.URL, path string, params url.Values, result interface{}) error {
|
||||
if !b.AllowAuthenticatedRequest() {
|
||||
return fmt.Errorf(exchange.WarningAuthenticatedRequestWithoutCredentialsSet, b.Name)
|
||||
}
|
||||
|
||||
endpoint, err := b.API.Endpoints.GetURL(ep)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if params == nil {
|
||||
params = url.Values{}
|
||||
}
|
||||
@@ -501,9 +501,9 @@ func (b *Bithumb) SendAuthenticatedHTTPRequest(path string, params url.Values, r
|
||||
Message string `json:"message"`
|
||||
}{}
|
||||
|
||||
err := b.SendPayload(context.Background(), &request.Item{
|
||||
err = b.SendPayload(context.Background(), &request.Item{
|
||||
Method: http.MethodPost,
|
||||
Path: b.API.Endpoints.URL + path,
|
||||
Path: endpoint + path,
|
||||
Headers: headers,
|
||||
Body: bytes.NewBufferString(payload),
|
||||
Result: &intermediary,
|
||||
@@ -608,7 +608,7 @@ var errCode = map[string]string{
|
||||
|
||||
// GetCandleStick returns candle stick data for requested pair
|
||||
func (b *Bithumb) GetCandleStick(symbol, interval string) (resp OHLCVResponse, err error) {
|
||||
path := b.API.Endpoints.URL + publicCandleStick + symbol + "/" + interval
|
||||
err = b.SendHTTPRequest(path, &resp)
|
||||
path := publicCandleStick + symbol + "/" + interval
|
||||
err = b.SendHTTPRequest(exchange.RestSpot, path, &resp)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -343,8 +343,9 @@ func TestFormatWithdrawPermissions(t *testing.T) {
|
||||
func TestGetActiveOrders(t *testing.T) {
|
||||
t.Parallel()
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
Type: order.AnyType,
|
||||
Side: order.Sell,
|
||||
Type: order.AnyType,
|
||||
Side: order.Sell,
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
|
||||
_, err := b.GetActiveOrders(&getOrdersRequest)
|
||||
@@ -358,7 +359,8 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
func TestGetOrderHistory(t *testing.T) {
|
||||
t.Parallel()
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
Type: order.AnyType,
|
||||
Type: order.AnyType,
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
|
||||
_, err := b.GetOrderHistory(&getOrdersRequest)
|
||||
@@ -457,12 +459,12 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
func TestGetAccountInfo(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() {
|
||||
_, err := b.UpdateAccountInfo()
|
||||
_, err := b.UpdateAccountInfo(asset.Spot)
|
||||
if err != nil {
|
||||
t.Error("Bithumb GetAccountInfo() error", err)
|
||||
}
|
||||
} else {
|
||||
_, err := b.UpdateAccountInfo()
|
||||
_, err := b.UpdateAccountInfo(asset.Spot)
|
||||
if err == nil {
|
||||
t.Error("Bithumb GetAccountInfo() Expected error")
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@ type Ticker struct {
|
||||
PreviousClosingPrice float64 `json:"prev_closing_price,string"`
|
||||
UnitsTraded24Hr float64 `json:"units_traded_24H,string"`
|
||||
AccumulatedTradeValue24hr float64 `json:"acc_trade_value_24H,string"`
|
||||
Fluctate24Hr string `json:"fluctate_24H"`
|
||||
FluctateRate24hr float64 `json:"fluctate_rate_24H,string"`
|
||||
Fluctuate24Hr float64 `json:"fluctate_24H,string"`
|
||||
FluctuateRate24hr float64 `json:"fluctate_rate_24H,string"`
|
||||
Date int64 `json:"date,string"`
|
||||
}
|
||||
|
||||
|
||||
@@ -116,9 +116,13 @@ func (b *Bithumb) SetDefaults() {
|
||||
b.Requester = request.New(b.Name,
|
||||
common.NewHTTPClientWithTimeout(exchange.DefaultHTTPTimeout),
|
||||
request.WithLimiter(SetRateLimit()))
|
||||
|
||||
b.API.Endpoints.URLDefault = apiURL
|
||||
b.API.Endpoints.URL = b.API.Endpoints.URLDefault
|
||||
b.API.Endpoints = b.NewEndpoints()
|
||||
err = b.API.Endpoints.SetDefaultEndpoints(map[exchange.URL]string{
|
||||
exchange.RestSpot: apiURL,
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorln(log.ExchangeSys, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Setup takes in the supplied exchange configuration details and sets params
|
||||
@@ -204,7 +208,6 @@ func (b *Bithumb) UpdateTicker(p currency.Pair, assetType asset.Item) (*ticker.P
|
||||
fmt.Errorf("enabled pair %s [%s] not found in returned ticker map %v",
|
||||
pairs[i], pairs, tickers)
|
||||
}
|
||||
|
||||
err = ticker.ProcessTicker(&ticker.Price{
|
||||
High: t.MaxPrice,
|
||||
Low: t.MinPrice,
|
||||
@@ -280,7 +283,7 @@ func (b *Bithumb) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*order
|
||||
|
||||
// UpdateAccountInfo retrieves balances for all enabled currencies for the
|
||||
// Bithumb exchange
|
||||
func (b *Bithumb) UpdateAccountInfo() (account.Holdings, error) {
|
||||
func (b *Bithumb) UpdateAccountInfo(assetType asset.Item) (account.Holdings, error) {
|
||||
var info account.Holdings
|
||||
bal, err := b.GetAccountBalance("ALL")
|
||||
if err != nil {
|
||||
@@ -316,10 +319,10 @@ func (b *Bithumb) UpdateAccountInfo() (account.Holdings, error) {
|
||||
}
|
||||
|
||||
// FetchAccountInfo retrieves balances for all enabled currencies
|
||||
func (b *Bithumb) FetchAccountInfo() (account.Holdings, error) {
|
||||
acc, err := account.GetHoldings(b.Name)
|
||||
func (b *Bithumb) FetchAccountInfo(assetType asset.Item) (account.Holdings, error) {
|
||||
acc, err := account.GetHoldings(b.Name, assetType)
|
||||
if err != nil {
|
||||
return b.UpdateAccountInfo()
|
||||
return b.UpdateAccountInfo(assetType)
|
||||
}
|
||||
|
||||
return acc, nil
|
||||
@@ -680,8 +683,8 @@ func (b *Bithumb) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail,
|
||||
|
||||
// ValidateCredentials validates current credentials used for wrapper
|
||||
// functionality
|
||||
func (b *Bithumb) ValidateCredentials() error {
|
||||
_, err := b.UpdateAccountInfo()
|
||||
func (b *Bithumb) ValidateCredentials(assetType asset.Item) error {
|
||||
_, err := b.UpdateAccountInfo(assetType)
|
||||
return b.CheckTransientError(err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user