mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-30 07:26:46 +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:
@@ -3,7 +3,6 @@ package bitflyer
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
@@ -76,51 +75,41 @@ type Bitflyer struct {
|
||||
// analysis system
|
||||
func (b *Bitflyer) GetLatestBlockCA() (ChainAnalysisBlock, error) {
|
||||
var resp ChainAnalysisBlock
|
||||
path := b.API.Endpoints.URLSecondary + latestBlock
|
||||
return resp, b.SendHTTPRequest(path, &resp)
|
||||
return resp, b.SendHTTPRequest(exchange.ChainAnalysis, latestBlock, &resp)
|
||||
}
|
||||
|
||||
// GetBlockCA returns block information by blockhash from bitflyer chain
|
||||
// analysis system
|
||||
func (b *Bitflyer) GetBlockCA(blockhash string) (ChainAnalysisBlock, error) {
|
||||
var resp ChainAnalysisBlock
|
||||
path := b.API.Endpoints.URLSecondary + blockByBlockHash + blockhash
|
||||
return resp, b.SendHTTPRequest(path, &resp)
|
||||
return resp, b.SendHTTPRequest(exchange.ChainAnalysis, blockByBlockHash+blockhash, &resp)
|
||||
}
|
||||
|
||||
// GetBlockbyHeightCA returns the block information by height from bitflyer chain
|
||||
// analysis system
|
||||
func (b *Bitflyer) GetBlockbyHeightCA(height int64) (ChainAnalysisBlock, error) {
|
||||
var resp ChainAnalysisBlock
|
||||
path := b.API.Endpoints.URLSecondary +
|
||||
blockByBlockHeight +
|
||||
strconv.FormatInt(height, 10)
|
||||
return resp, b.SendHTTPRequest(path, &resp)
|
||||
return resp, b.SendHTTPRequest(exchange.ChainAnalysis, blockByBlockHeight+strconv.FormatInt(height, 10), &resp)
|
||||
}
|
||||
|
||||
// GetTransactionByHashCA returns transaction information by txHash from
|
||||
// bitflyer chain analysis system
|
||||
func (b *Bitflyer) GetTransactionByHashCA(txHash string) (ChainAnalysisTransaction, error) {
|
||||
var resp ChainAnalysisTransaction
|
||||
path := b.API.Endpoints.URLSecondary + transaction + txHash
|
||||
return resp, b.SendHTTPRequest(path, &resp)
|
||||
return resp, b.SendHTTPRequest(exchange.ChainAnalysis, transaction+txHash, &resp)
|
||||
}
|
||||
|
||||
// GetAddressInfoCA returns balance information for address by addressln string
|
||||
// from bitflyer chain analysis system
|
||||
func (b *Bitflyer) GetAddressInfoCA(addressln string) (ChainAnalysisAddress, error) {
|
||||
var resp ChainAnalysisAddress
|
||||
path := b.API.Endpoints.URLSecondary + address + addressln
|
||||
|
||||
return resp, b.SendHTTPRequest(path, &resp)
|
||||
return resp, b.SendHTTPRequest(exchange.ChainAnalysis, address+addressln, &resp)
|
||||
}
|
||||
|
||||
// GetMarkets returns market information
|
||||
func (b *Bitflyer) GetMarkets() ([]MarketInfo, error) {
|
||||
var resp []MarketInfo
|
||||
path := b.API.Endpoints.URL + pubGetMarkets
|
||||
|
||||
return resp, b.SendHTTPRequest(path, &resp)
|
||||
return resp, b.SendHTTPRequest(exchange.RestSpot, pubGetMarkets, &resp)
|
||||
}
|
||||
|
||||
// GetOrderBook returns market orderbook depth
|
||||
@@ -128,9 +117,8 @@ func (b *Bitflyer) GetOrderBook(symbol string) (Orderbook, error) {
|
||||
var resp Orderbook
|
||||
v := url.Values{}
|
||||
v.Set("product_code", symbol)
|
||||
path := fmt.Sprintf("%s%s?%s", b.API.Endpoints.URL, pubGetBoard, v.Encode())
|
||||
|
||||
return resp, b.SendHTTPRequest(path, &resp)
|
||||
return resp, b.SendHTTPRequest(exchange.RestSpot, pubGetBoard+"?"+v.Encode(), &resp)
|
||||
}
|
||||
|
||||
// GetTicker returns ticker information
|
||||
@@ -138,8 +126,7 @@ func (b *Bitflyer) GetTicker(symbol string) (Ticker, error) {
|
||||
var resp Ticker
|
||||
v := url.Values{}
|
||||
v.Set("product_code", symbol)
|
||||
path := fmt.Sprintf("%s%s?%s", b.API.Endpoints.URL, pubGetTicker, v.Encode())
|
||||
return resp, b.SendHTTPRequest(path, &resp)
|
||||
return resp, b.SendHTTPRequest(exchange.RestSpot, pubGetTicker+"?"+v.Encode(), &resp)
|
||||
}
|
||||
|
||||
// GetExecutionHistory returns past trades that were executed on the market
|
||||
@@ -147,18 +134,14 @@ func (b *Bitflyer) GetExecutionHistory(symbol string) ([]ExecutedTrade, error) {
|
||||
var resp []ExecutedTrade
|
||||
v := url.Values{}
|
||||
v.Set("product_code", symbol)
|
||||
path := fmt.Sprintf("%s%s?%s", b.API.Endpoints.URL, pubGetExecutionHistory, v.Encode())
|
||||
|
||||
return resp, b.SendHTTPRequest(path, &resp)
|
||||
return resp, b.SendHTTPRequest(exchange.RestSpot, pubGetExecutionHistory+"?"+v.Encode(), &resp)
|
||||
}
|
||||
|
||||
// GetExchangeStatus returns exchange status information
|
||||
func (b *Bitflyer) GetExchangeStatus() (string, error) {
|
||||
resp := make(map[string]string)
|
||||
|
||||
path := b.API.Endpoints.URL + pubGetHealth
|
||||
|
||||
err := b.SendHTTPRequest(path, &resp)
|
||||
err := b.SendHTTPRequest(exchange.RestSpot, pubGetHealth, &resp)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -183,8 +166,7 @@ func (b *Bitflyer) GetChats(fromDate string) ([]ChatLog, error) {
|
||||
var resp []ChatLog
|
||||
v := url.Values{}
|
||||
v.Set("from_date", fromDate)
|
||||
path := fmt.Sprintf("%s%s?%s", b.API.Endpoints.URL, pubGetChats, v.Encode())
|
||||
return resp, b.SendHTTPRequest(path, &resp)
|
||||
return resp, b.SendHTTPRequest(exchange.RestSpot, pubGetChats+"?"+v.Encode(), &resp)
|
||||
}
|
||||
|
||||
// GetPermissions returns current permissions for associated with your API
|
||||
@@ -304,10 +286,14 @@ func (b *Bitflyer) GetTradingCommission() {
|
||||
}
|
||||
|
||||
// SendHTTPRequest sends an unauthenticated request
|
||||
func (b *Bitflyer) SendHTTPRequest(path string, result interface{}) error {
|
||||
func (b *Bitflyer) 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,
|
||||
|
||||
@@ -283,7 +283,8 @@ func TestFormatWithdrawPermissions(t *testing.T) {
|
||||
func TestGetActiveOrders(t *testing.T) {
|
||||
t.Parallel()
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
Type: order.AnyType,
|
||||
Type: order.AnyType,
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
|
||||
_, err := b.GetActiveOrders(&getOrdersRequest)
|
||||
@@ -297,7 +298,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)
|
||||
|
||||
@@ -94,11 +94,14 @@ func (b *Bitflyer) SetDefaults() {
|
||||
b.Requester = request.New(b.Name,
|
||||
common.NewHTTPClientWithTimeout(exchange.DefaultHTTPTimeout),
|
||||
request.WithLimiter(SetRateLimit()))
|
||||
|
||||
b.API.Endpoints.URLDefault = japanURL
|
||||
b.API.Endpoints.URL = b.API.Endpoints.URLDefault
|
||||
b.API.Endpoints.URLSecondaryDefault = chainAnalysis
|
||||
b.API.Endpoints.URLSecondary = b.API.Endpoints.URLSecondaryDefault
|
||||
b.API.Endpoints = b.NewEndpoints()
|
||||
err = b.API.Endpoints.SetDefaultEndpoints(map[exchange.URL]string{
|
||||
exchange.RestSpot: japanURL,
|
||||
exchange.ChainAnalysis: chainAnalysis,
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorln(log.ExchangeSys, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Setup takes in the supplied exchange configuration details and sets params
|
||||
@@ -289,15 +292,15 @@ func (b *Bitflyer) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*orde
|
||||
|
||||
// UpdateAccountInfo retrieves balances for all enabled currencies on the
|
||||
// Bitflyer exchange
|
||||
func (b *Bitflyer) UpdateAccountInfo() (account.Holdings, error) {
|
||||
func (b *Bitflyer) UpdateAccountInfo(assetType asset.Item) (account.Holdings, error) {
|
||||
return account.Holdings{}, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// FetchAccountInfo retrieves balances for all enabled currencies
|
||||
func (b *Bitflyer) FetchAccountInfo() (account.Holdings, error) {
|
||||
acc, err := account.GetHoldings(b.Name)
|
||||
func (b *Bitflyer) 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
|
||||
@@ -442,8 +445,8 @@ func (b *Bitflyer) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error
|
||||
|
||||
// ValidateCredentials validates current credentials used for wrapper
|
||||
// functionality
|
||||
func (b *Bitflyer) ValidateCredentials() error {
|
||||
_, err := b.UpdateAccountInfo()
|
||||
func (b *Bitflyer) ValidateCredentials(assetType asset.Item) error {
|
||||
_, err := b.UpdateAccountInfo(assetType)
|
||||
return b.CheckTransientError(err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user