mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-30 15:10:40 +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:
@@ -58,7 +58,7 @@ func (a *Alphapoint) GetTicker(currencyPair string) (Ticker, error) {
|
||||
req["productPair"] = currencyPair
|
||||
response := Ticker{}
|
||||
|
||||
err := a.SendHTTPRequest(http.MethodPost, alphapointTicker, req, &response)
|
||||
err := a.SendHTTPRequest(exchange.RestSpot, http.MethodPost, alphapointTicker, req, &response)
|
||||
if err != nil {
|
||||
return response, err
|
||||
}
|
||||
@@ -81,7 +81,7 @@ func (a *Alphapoint) GetTrades(currencyPair string, startIndex, count int) (Trad
|
||||
req["Count"] = count
|
||||
response := Trades{}
|
||||
|
||||
err := a.SendHTTPRequest(http.MethodPost, alphapointTrades, req, &response)
|
||||
err := a.SendHTTPRequest(exchange.RestSpot, http.MethodPost, alphapointTrades, req, &response)
|
||||
if err != nil {
|
||||
return response, err
|
||||
}
|
||||
@@ -102,7 +102,7 @@ func (a *Alphapoint) GetTradesByDate(currencyPair string, startDate, endDate int
|
||||
req["endDate"] = endDate
|
||||
response := Trades{}
|
||||
|
||||
err := a.SendHTTPRequest(http.MethodPost, alphapointTradesByDate, req, &response)
|
||||
err := a.SendHTTPRequest(exchange.RestSpot, http.MethodPost, alphapointTradesByDate, req, &response)
|
||||
if err != nil {
|
||||
return response, err
|
||||
}
|
||||
@@ -119,7 +119,7 @@ func (a *Alphapoint) GetOrderbook(currencyPair string) (Orderbook, error) {
|
||||
req["productPair"] = currencyPair
|
||||
response := Orderbook{}
|
||||
|
||||
err := a.SendHTTPRequest(http.MethodPost, alphapointOrderbook, req, &response)
|
||||
err := a.SendHTTPRequest(exchange.RestSpot, http.MethodPost, alphapointOrderbook, req, &response)
|
||||
if err != nil {
|
||||
return response, err
|
||||
}
|
||||
@@ -133,7 +133,7 @@ func (a *Alphapoint) GetOrderbook(currencyPair string) (Orderbook, error) {
|
||||
func (a *Alphapoint) GetProductPairs() (ProductPairs, error) {
|
||||
response := ProductPairs{}
|
||||
|
||||
err := a.SendHTTPRequest(http.MethodPost, alphapointProductPairs, nil, &response)
|
||||
err := a.SendHTTPRequest(exchange.RestSpot, http.MethodPost, alphapointProductPairs, nil, &response)
|
||||
if err != nil {
|
||||
return response, err
|
||||
}
|
||||
@@ -147,7 +147,7 @@ func (a *Alphapoint) GetProductPairs() (ProductPairs, error) {
|
||||
func (a *Alphapoint) GetProducts() (Products, error) {
|
||||
response := Products{}
|
||||
|
||||
err := a.SendHTTPRequest(http.MethodPost, alphapointProducts, nil, &response)
|
||||
err := a.SendHTTPRequest(exchange.RestSpot, http.MethodPost, alphapointProducts, nil, &response)
|
||||
if err != nil {
|
||||
return response, err
|
||||
}
|
||||
@@ -178,7 +178,7 @@ func (a *Alphapoint) CreateAccount(firstName, lastName, email, phone, password s
|
||||
req["password"] = password
|
||||
response := Response{}
|
||||
|
||||
err := a.SendAuthenticatedHTTPRequest(http.MethodPost, alphapointCreateAccount, req, &response)
|
||||
err := a.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, alphapointCreateAccount, req, &response)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to create account. Reason: %s", err)
|
||||
}
|
||||
@@ -192,7 +192,7 @@ func (a *Alphapoint) CreateAccount(firstName, lastName, email, phone, password s
|
||||
func (a *Alphapoint) GetUserInfo() (UserInfo, error) {
|
||||
response := UserInfo{}
|
||||
|
||||
err := a.SendAuthenticatedHTTPRequest(http.MethodPost, alphapointUserInfo, map[string]interface{}{}, &response)
|
||||
err := a.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, alphapointUserInfo, map[string]interface{}{}, &response)
|
||||
if err != nil {
|
||||
return UserInfo{}, err
|
||||
}
|
||||
@@ -245,6 +245,7 @@ func (a *Alphapoint) SetUserInfo(firstName, lastName, cell2FACountryCode, cell2F
|
||||
req["userInfoKVP"] = userInfoKVPs
|
||||
|
||||
err := a.SendAuthenticatedHTTPRequest(
|
||||
exchange.RestSpot,
|
||||
http.MethodPost,
|
||||
alphapointUserInfo,
|
||||
req,
|
||||
@@ -264,6 +265,7 @@ func (a *Alphapoint) GetAccountInformation() (AccountInfo, error) {
|
||||
response := AccountInfo{}
|
||||
|
||||
err := a.SendAuthenticatedHTTPRequest(
|
||||
exchange.RestSpot,
|
||||
http.MethodPost,
|
||||
alphapointAccountInfo,
|
||||
map[string]interface{}{},
|
||||
@@ -290,6 +292,7 @@ func (a *Alphapoint) GetAccountTrades(currencyPair string, startIndex, count int
|
||||
response := Trades{}
|
||||
|
||||
err := a.SendAuthenticatedHTTPRequest(
|
||||
exchange.RestSpot,
|
||||
http.MethodPost,
|
||||
alphapointAccountTrades,
|
||||
req,
|
||||
@@ -308,7 +311,7 @@ func (a *Alphapoint) GetAccountTrades(currencyPair string, startIndex, count int
|
||||
func (a *Alphapoint) GetDepositAddresses() ([]DepositAddresses, error) {
|
||||
response := Response{}
|
||||
|
||||
err := a.SendAuthenticatedHTTPRequest(http.MethodPost, alphapointDepositAddresses,
|
||||
err := a.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, alphapointDepositAddresses,
|
||||
map[string]interface{}{}, &response,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -334,6 +337,7 @@ func (a *Alphapoint) WithdrawCoins(symbol, product, address string, amount float
|
||||
|
||||
response := Response{}
|
||||
err := a.SendAuthenticatedHTTPRequest(
|
||||
exchange.RestSpot,
|
||||
http.MethodPost,
|
||||
alphapointWithdraw,
|
||||
req,
|
||||
@@ -373,6 +377,7 @@ func (a *Alphapoint) CreateOrder(symbol, side, orderType string, quantity, price
|
||||
response := Response{}
|
||||
|
||||
err := a.SendAuthenticatedHTTPRequest(
|
||||
exchange.RestSpot,
|
||||
http.MethodPost,
|
||||
alphapointCreateOrder,
|
||||
req,
|
||||
@@ -403,6 +408,7 @@ func (a *Alphapoint) ModifyExistingOrder(symbol string, orderID, action int64) (
|
||||
response := Response{}
|
||||
|
||||
err := a.SendAuthenticatedHTTPRequest(
|
||||
exchange.RestSpot,
|
||||
http.MethodPost,
|
||||
alphapointModifyOrder,
|
||||
req,
|
||||
@@ -427,6 +433,7 @@ func (a *Alphapoint) CancelExistingOrder(orderID int64, omsid string) (int64, er
|
||||
response := Response{}
|
||||
|
||||
err := a.SendAuthenticatedHTTPRequest(
|
||||
exchange.RestSpot,
|
||||
http.MethodPost,
|
||||
alphapointCancelOrder,
|
||||
req,
|
||||
@@ -449,6 +456,7 @@ func (a *Alphapoint) CancelAllExistingOrders(omsid string) error {
|
||||
response := Response{}
|
||||
|
||||
err := a.SendAuthenticatedHTTPRequest(
|
||||
exchange.RestSpot,
|
||||
http.MethodPost,
|
||||
alphapointCancelAllOrders,
|
||||
req,
|
||||
@@ -468,6 +476,7 @@ func (a *Alphapoint) GetOrders() ([]OpenOrders, error) {
|
||||
response := OrderInfo{}
|
||||
|
||||
err := a.SendAuthenticatedHTTPRequest(
|
||||
exchange.RestSpot,
|
||||
http.MethodPost,
|
||||
alphapointOpenOrders,
|
||||
map[string]interface{}{},
|
||||
@@ -496,6 +505,7 @@ func (a *Alphapoint) GetOrderFee(symbol, side string, quantity, price float64) (
|
||||
response := Response{}
|
||||
|
||||
err := a.SendAuthenticatedHTTPRequest(
|
||||
exchange.RestSpot,
|
||||
http.MethodPost,
|
||||
alphapointOrderFee,
|
||||
req,
|
||||
@@ -511,10 +521,14 @@ func (a *Alphapoint) GetOrderFee(symbol, side string, quantity, price float64) (
|
||||
}
|
||||
|
||||
// SendHTTPRequest sends an unauthenticated HTTP request
|
||||
func (a *Alphapoint) SendHTTPRequest(method, path string, data map[string]interface{}, result interface{}) error {
|
||||
func (a *Alphapoint) SendHTTPRequest(ep exchange.URL, method, path string, data map[string]interface{}, result interface{}) error {
|
||||
endpoint, err := a.API.Endpoints.GetURL(ep)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
headers := make(map[string]string)
|
||||
headers["Content-Type"] = "application/json"
|
||||
path = fmt.Sprintf("%s/ajax/v%s/%s", a.API.Endpoints.URL, alphapointAPIVersion, path)
|
||||
path = fmt.Sprintf("%s/ajax/v%s/%s", endpoint, alphapointAPIVersion, path)
|
||||
|
||||
PayloadJSON, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
@@ -533,11 +547,16 @@ func (a *Alphapoint) SendHTTPRequest(method, path string, data map[string]interf
|
||||
}
|
||||
|
||||
// SendAuthenticatedHTTPRequest sends an authenticated request
|
||||
func (a *Alphapoint) SendAuthenticatedHTTPRequest(method, path string, data map[string]interface{}, result interface{}) error {
|
||||
func (a *Alphapoint) SendAuthenticatedHTTPRequest(ep exchange.URL, method, path string, data map[string]interface{}, result interface{}) error {
|
||||
if !a.AllowAuthenticatedRequest() {
|
||||
return fmt.Errorf(exchange.WarningAuthenticatedRequestWithoutCredentialsSet, a.Name)
|
||||
}
|
||||
|
||||
endpoint, err := a.API.Endpoints.GetURL(ep)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
n := a.Requester.GetNonce(true)
|
||||
|
||||
headers := make(map[string]string)
|
||||
@@ -548,7 +567,7 @@ func (a *Alphapoint) SendAuthenticatedHTTPRequest(method, path string, data map[
|
||||
[]byte(n.String()+a.API.Credentials.ClientID+a.API.Credentials.Key),
|
||||
[]byte(a.API.Credentials.Secret))
|
||||
data["apiSig"] = strings.ToUpper(crypto.HexEncodeToString(hmac))
|
||||
path = fmt.Sprintf("%s/ajax/v%s/%s", a.API.Endpoints.URL, alphapointAPIVersion, path)
|
||||
path = fmt.Sprintf("%s/ajax/v%s/%s", endpoint, alphapointAPIVersion, path)
|
||||
|
||||
PayloadJSON, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
|
||||
@@ -2,7 +2,6 @@ package alphapoint
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -30,12 +29,6 @@ func TestMain(m *testing.M) {
|
||||
a.API.Credentials.Key = apiKey
|
||||
a.API.Credentials.Secret = apiSecret
|
||||
a.API.AuthenticatedSupport = true
|
||||
if a.API.Endpoints.URL != "https://sim3.alphapoint.com:8400" {
|
||||
log.Fatal("SetDefaults: String Incorrect -", a.API.Endpoints.URL)
|
||||
}
|
||||
if a.API.Endpoints.WebsocketURL != "wss://sim3.alphapoint.com:8401/v1/GetTicker/" {
|
||||
log.Fatal("SetDefaults: String Incorrect -", a.API.Endpoints.WebsocketURL)
|
||||
}
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
@@ -327,7 +320,7 @@ func TestGetAccountInfo(t *testing.T) {
|
||||
t.Skip("API keys not set, skipping")
|
||||
}
|
||||
|
||||
_, err := a.UpdateAccountInfo()
|
||||
_, err := a.UpdateAccountInfo(asset.Spot)
|
||||
if err == nil {
|
||||
t.Error("GetUserInfo() Expected error")
|
||||
}
|
||||
@@ -441,7 +434,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 := a.GetActiveOrders(&getOrdersRequest)
|
||||
@@ -455,7 +449,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 := a.GetOrderHistory(&getOrdersRequest)
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
)
|
||||
|
||||
@@ -18,7 +19,11 @@ func (a *Alphapoint) WebsocketClient() {
|
||||
var dialer websocket.Dialer
|
||||
var err error
|
||||
var httpResp *http.Response
|
||||
a.WebsocketConn, httpResp, err = dialer.Dial(a.API.Endpoints.WebsocketURL, http.Header{})
|
||||
endpoint, err := a.API.Endpoints.GetURL(exchange.WebsocketSpot)
|
||||
if err != nil {
|
||||
log.Error(log.WebsocketMgr, err)
|
||||
}
|
||||
a.WebsocketConn, httpResp, err = dialer.Dial(endpoint, http.Header{})
|
||||
httpResp.Body.Close() // not used, so safely free the body
|
||||
|
||||
if err != nil {
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/trade"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
@@ -30,8 +31,14 @@ func (a *Alphapoint) SetDefaults() {
|
||||
a.Name = "Alphapoint"
|
||||
a.Enabled = true
|
||||
a.Verbose = true
|
||||
a.API.Endpoints.URL = alphapointDefaultAPIURL
|
||||
a.API.Endpoints.WebsocketURL = alphapointDefaultWebsocketURL
|
||||
a.API.Endpoints = a.NewEndpoints()
|
||||
err := a.API.Endpoints.SetDefaultEndpoints(map[exchange.URL]string{
|
||||
exchange.RestSpot: alphapointDefaultAPIURL,
|
||||
exchange.WebsocketSpot: alphapointDefaultWebsocketURL,
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorln(log.ExchangeSys, err)
|
||||
}
|
||||
a.API.CredentialsValidator.RequiresKey = true
|
||||
a.API.CredentialsValidator.RequiresSecret = true
|
||||
|
||||
@@ -82,7 +89,7 @@ func (a *Alphapoint) UpdateTradablePairs(forceUpdate bool) error {
|
||||
|
||||
// UpdateAccountInfo retrieves balances for all enabled currencies on the
|
||||
// Alphapoint exchange
|
||||
func (a *Alphapoint) UpdateAccountInfo() (account.Holdings, error) {
|
||||
func (a *Alphapoint) UpdateAccountInfo(assetType asset.Item) (account.Holdings, error) {
|
||||
var response account.Holdings
|
||||
response.Exchange = a.Name
|
||||
acc, err := a.GetAccountInformation()
|
||||
@@ -114,10 +121,10 @@ func (a *Alphapoint) UpdateAccountInfo() (account.Holdings, error) {
|
||||
|
||||
// FetchAccountInfo retrieves balances for all enabled currencies on the
|
||||
// Alphapoint exchange
|
||||
func (a *Alphapoint) FetchAccountInfo() (account.Holdings, error) {
|
||||
acc, err := account.GetHoldings(a.Name)
|
||||
func (a *Alphapoint) FetchAccountInfo(assetType asset.Item) (account.Holdings, error) {
|
||||
acc, err := account.GetHoldings(a.Name, assetType)
|
||||
if err != nil {
|
||||
return a.UpdateAccountInfo()
|
||||
return a.UpdateAccountInfo(assetType)
|
||||
}
|
||||
|
||||
return acc, nil
|
||||
@@ -433,7 +440,7 @@ func (a *Alphapoint) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detai
|
||||
|
||||
// ValidateCredentials validates current credentials used for wrapper
|
||||
// functionality
|
||||
func (a *Alphapoint) ValidateCredentials() error {
|
||||
_, err := a.UpdateAccountInfo()
|
||||
func (a *Alphapoint) ValidateCredentials(assetType asset.Item) error {
|
||||
_, err := a.UpdateAccountInfo(assetType)
|
||||
return a.CheckTransientError(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user