cmd/exchange_template, exchanges: Update templates and propogate to exchanges (#1777)

* Added TimeInForce type and updated related files

* Linter issue fix and minor coinbasepro type update

* Bitrex consts update

* added unit test and minor changes in bittrex

* Unit tests update

* Fix minor linter issues

* Update TestStringToTimeInForce unit test

* Exchange test template change

* A different approach

* fix conflict with gateio timeInForce

* minor exchange template update

* Minor fix to test_files template

* Update order tests

* Complete updating the order unit tests

* Updating exchange wrapper and test template files

* update kucoin and deribit wrapper to match the time in force change

* minor comment update

* fix time-in-force related test errors

* linter issue fix

* ADD_NEW_EXCHANGE documentation update

* time in force constants, functions and unit tests update

* shift tif policies to TimeInForce

* Update time-in-force, related functions, and unit tests

* fix linter issue and time-in-force processing

* added a good till crossing tif value

* order type fix and fix related tim-in-force entries

* update time-in-force unmarshaling and unit test

* consistency guideline added

* fix time-in-force error in gateio

* linter issue fix

* update based on review comments

* add unit test and fix missing issues

* minor fix and added benchmark unit test

* change GTT to GTC for limit

* fix linter issue

* added time-in-force value to place order param

* fix minor issues based on review comment and move tif code to separate files

* update on exchanges linked to time-in-force

* resolve missing review comments

* minor linter issues fix

* added time-in-force handler and update timeInForce parametered endpoint

* minor fixes based on review

* nits fix

* update based on review

* linter fix

* rm getTimeInForce func and minor change to time-in-force

* minor change

* update based on review comments

* wrappers and time-in-force calling approach

* minor change

* update gateio string to timeInForce conversion and unit test

* update exchange template

* update wrapper template file

* policy comments, and template files update

* rename all exchange types name to Exchange

* update on template files and template generation

* templates and generation code and other updates

* linter issue fix

* added subscriptions and websocket templates

* update ADD_NEW_EXCHANGE.md with recent binance functions and implementations

* rename template files and update unit tests

* minor template and unit test fix

* rename templates and fix on unit tests

* update on template files and documentation

* removed unnecessary tag fix and update templates

* fix Add_NEW_EXCHANGE.md doc file

* formatting, comments, and error checks update on template files

* rename exchange receivers to e and ex for consistency

* rename unit test exchange receiver and minor updates

* linter issues fix

* fix deribit issue and minor style update

* fix test issues caused by receiver change

* raname local variables exchange declaration variables

* update templates comments

* update templates and related comments

* renamed ex to e

* update template comments

* toggle WS to false to improve coverage

* template comments update

* added test coverage to Ws enabled and minor changes

---------

Co-authored-by: Samuel Reid <43227667+cranktakular@users.noreply.github.com>
This commit is contained in:
Samuael A.
2025-07-17 03:46:36 +03:00
committed by GitHub
parent 485397a0c7
commit 3f534a15f1
163 changed files with 20453 additions and 20313 deletions

View File

@@ -42,20 +42,20 @@ const (
alphapointOrderFee = "GetOrderFee"
)
// Alphapoint is the overarching type across the alphapoint package
type Alphapoint struct {
// Exchange implements exchange.IBotExchange and contains additional specific api methods for interacting with Alphapoint
type Exchange struct {
exchange.Base
WebsocketConn *gws.Conn
}
// GetTicker returns current ticker information from Alphapoint for a selected
// currency pair ie "BTCUSD"
func (a *Alphapoint) GetTicker(ctx context.Context, currencyPair string) (Ticker, error) {
func (e *Exchange) GetTicker(ctx context.Context, currencyPair string) (Ticker, error) {
req := make(map[string]any)
req["productPair"] = currencyPair
response := Ticker{}
err := a.SendHTTPRequest(ctx,
err := e.SendHTTPRequest(ctx,
exchange.RestSpot,
http.MethodPost,
alphapointTicker,
@@ -76,14 +76,14 @@ func (a *Alphapoint) GetTicker(ctx context.Context, currencyPair string) (Ticker
// AlphaPoint Exchange. To begin from the most recent trade, set startIndex to
// 0 (default: 0)
// Count: specifies the number of trades to return (default: 10)
func (a *Alphapoint) GetTrades(ctx context.Context, currencyPair string, startIndex, count int) (Trades, error) {
func (e *Exchange) GetTrades(ctx context.Context, currencyPair string, startIndex, count int) (Trades, error) {
req := make(map[string]any)
req["ins"] = currencyPair
req["startIndex"] = startIndex
req["Count"] = count
response := Trades{}
err := a.SendHTTPRequest(ctx,
err := e.SendHTTPRequest(ctx,
exchange.RestSpot, http.MethodPost, alphapointTrades, req, &response)
if err != nil {
return response, err
@@ -96,12 +96,12 @@ func (a *Alphapoint) GetTrades(ctx context.Context, currencyPair string, startIn
// GetOrderbook fetches the current orderbook for a given currency pair
// CurrencyPair - trade pair (ex: “BTCUSD”)
func (a *Alphapoint) GetOrderbook(ctx context.Context, currencyPair string) (Orderbook, error) {
func (e *Exchange) GetOrderbook(ctx context.Context, currencyPair string) (Orderbook, error) {
req := make(map[string]any)
req["productPair"] = currencyPair
response := Orderbook{}
err := a.SendHTTPRequest(ctx,
err := e.SendHTTPRequest(ctx,
exchange.RestSpot, http.MethodPost, alphapointOrderbook, req, &response)
if err != nil {
return response, err
@@ -113,10 +113,10 @@ func (a *Alphapoint) GetOrderbook(ctx context.Context, currencyPair string) (Ord
}
// GetProductPairs gets the currency pairs currently traded on alphapoint
func (a *Alphapoint) GetProductPairs(ctx context.Context) (ProductPairs, error) {
func (e *Exchange) GetProductPairs(ctx context.Context) (ProductPairs, error) {
response := ProductPairs{}
err := a.SendHTTPRequest(ctx,
err := e.SendHTTPRequest(ctx,
exchange.RestSpot, http.MethodPost, alphapointProductPairs, nil, &response)
if err != nil {
return response, err
@@ -128,10 +128,10 @@ func (a *Alphapoint) GetProductPairs(ctx context.Context) (ProductPairs, error)
}
// GetProducts gets the currency products currently supported on alphapoint
func (a *Alphapoint) GetProducts(ctx context.Context) (Products, error) {
func (e *Exchange) GetProducts(ctx context.Context) (Products, error) {
response := Products{}
err := a.SendHTTPRequest(ctx,
err := e.SendHTTPRequest(ctx,
exchange.RestSpot, http.MethodPost, alphapointProducts, nil, &response)
if err != nil {
return response, err
@@ -148,7 +148,7 @@ func (a *Alphapoint) GetProducts(ctx context.Context) (Products, error) {
// Email - Email address
// Phone - Phone number (ex: “+12223334444”)
// Password - Minimum 8 characters
func (a *Alphapoint) CreateAccount(ctx context.Context, firstName, lastName, email, phone, password string) error {
func (e *Exchange) CreateAccount(ctx context.Context, firstName, lastName, email, phone, password string) error {
if len(password) < 8 {
return errors.New(
"alphapoint Error - Create account - Password must be 8 characters or more",
@@ -163,7 +163,7 @@ func (a *Alphapoint) CreateAccount(ctx context.Context, firstName, lastName, ema
req["password"] = password
response := Response{}
err := a.SendAuthenticatedHTTPRequest(ctx,
err := e.SendAuthenticatedHTTPRequest(ctx,
exchange.RestSpot, http.MethodPost, alphapointCreateAccount, req, &response)
if err != nil {
return fmt.Errorf("unable to create account. Reason: %s", err)
@@ -175,10 +175,10 @@ func (a *Alphapoint) CreateAccount(ctx context.Context, firstName, lastName, ema
}
// GetUserInfo returns current account user information
func (a *Alphapoint) GetUserInfo(ctx context.Context) (UserInfo, error) {
func (e *Exchange) GetUserInfo(ctx context.Context) (UserInfo, error) {
response := UserInfo{}
err := a.SendAuthenticatedHTTPRequest(ctx,
err := e.SendAuthenticatedHTTPRequest(ctx,
exchange.RestSpot,
http.MethodPost,
alphapointUserInfo,
@@ -202,7 +202,7 @@ func (a *Alphapoint) GetUserInfo(ctx context.Context) (UserInfo, error) {
// Cell2FAValue - Cell phone number, required for Authentication
// Use2FAForWithdraw - “true” or “false” set to true for using 2FA for
// withdrawals
func (a *Alphapoint) SetUserInfo(ctx context.Context, firstName, lastName, cell2FACountryCode, cell2FAValue string, useAuthy2FA, use2FAForWithdraw bool) (UserInfoSet, error) {
func (e *Exchange) SetUserInfo(ctx context.Context, firstName, lastName, cell2FACountryCode, cell2FAValue string, useAuthy2FA, use2FAForWithdraw bool) (UserInfoSet, error) {
response := UserInfoSet{}
userInfoKVPs := []UserInfoKVP{
@@ -235,7 +235,7 @@ func (a *Alphapoint) SetUserInfo(ctx context.Context, firstName, lastName, cell2
req := make(map[string]any)
req["userInfoKVP"] = userInfoKVPs
err := a.SendAuthenticatedHTTPRequest(ctx,
err := e.SendAuthenticatedHTTPRequest(ctx,
exchange.RestSpot,
http.MethodPost,
alphapointUserInfo,
@@ -252,10 +252,10 @@ func (a *Alphapoint) SetUserInfo(ctx context.Context, firstName, lastName, cell2
}
// GetAccountInformation returns account info
func (a *Alphapoint) GetAccountInformation(ctx context.Context) (AccountInfo, error) {
func (e *Exchange) GetAccountInformation(ctx context.Context) (AccountInfo, error) {
response := AccountInfo{}
err := a.SendAuthenticatedHTTPRequest(ctx,
err := e.SendAuthenticatedHTTPRequest(ctx,
exchange.RestSpot,
http.MethodPost,
alphapointAccountInfo,
@@ -275,14 +275,14 @@ func (a *Alphapoint) GetAccountInformation(ctx context.Context) (AccountInfo, er
// CurrencyPair - Instrument code (ex: “BTCUSD”)
// StartIndex - Starting index, if less than 0 then start from the beginning
// Count - Returns last trade, (Default: 30)
func (a *Alphapoint) GetAccountTrades(ctx context.Context, currencyPair string, startIndex, count int) (Trades, error) {
func (e *Exchange) GetAccountTrades(ctx context.Context, currencyPair string, startIndex, count int) (Trades, error) {
req := make(map[string]any)
req["ins"] = currencyPair
req["startIndex"] = startIndex
req["count"] = count
response := Trades{}
err := a.SendAuthenticatedHTTPRequest(ctx,
err := e.SendAuthenticatedHTTPRequest(ctx,
exchange.RestSpot,
http.MethodPost,
alphapointAccountTrades,
@@ -299,10 +299,10 @@ func (a *Alphapoint) GetAccountTrades(ctx context.Context, currencyPair string,
}
// GetDepositAddresses generates a deposit address
func (a *Alphapoint) GetDepositAddresses(ctx context.Context) ([]DepositAddresses, error) {
func (e *Exchange) GetDepositAddresses(ctx context.Context) ([]DepositAddresses, error) {
response := Response{}
err := a.SendAuthenticatedHTTPRequest(ctx,
err := e.SendAuthenticatedHTTPRequest(ctx,
exchange.RestSpot,
http.MethodPost,
alphapointDepositAddresses,
@@ -323,7 +323,7 @@ func (a *Alphapoint) GetDepositAddresses(ctx context.Context) ([]DepositAddresse
// product - Currency name (ex: “BTC”)
// amount - Amount (ex: “.011”)
// address - Withdraw address
func (a *Alphapoint) WithdrawCoins(ctx context.Context, symbol, product, address string, amount float64) error {
func (e *Exchange) WithdrawCoins(ctx context.Context, symbol, product, address string, amount float64) error {
req := make(map[string]any)
req["ins"] = symbol
req["product"] = product
@@ -331,7 +331,7 @@ func (a *Alphapoint) WithdrawCoins(ctx context.Context, symbol, product, address
req["sendToAddress"] = address
response := Response{}
err := a.SendAuthenticatedHTTPRequest(ctx,
err := e.SendAuthenticatedHTTPRequest(ctx,
exchange.RestSpot,
http.MethodPost,
alphapointWithdraw,
@@ -347,7 +347,7 @@ func (a *Alphapoint) WithdrawCoins(ctx context.Context, symbol, product, address
return nil
}
func (a *Alphapoint) convertOrderTypeToOrderTypeNumber(orderType string) (orderTypeNumber int64) {
func (e *Exchange) convertOrderTypeToOrderTypeNumber(orderType string) (orderTypeNumber int64) {
if orderType == order.Market.String() {
orderTypeNumber = 1
}
@@ -361,8 +361,8 @@ func (a *Alphapoint) convertOrderTypeToOrderTypeNumber(orderType string) (orderT
// orderType - “1” for market orders, “0” for limit orders
// quantity - Quantity
// price - Price in USD
func (a *Alphapoint) CreateOrder(ctx context.Context, symbol, side, orderType string, quantity, price float64) (int64, error) {
orderTypeNumber := a.convertOrderTypeToOrderTypeNumber(orderType)
func (e *Exchange) CreateOrder(ctx context.Context, symbol, side, orderType string, quantity, price float64) (int64, error) {
orderTypeNumber := e.convertOrderTypeToOrderTypeNumber(orderType)
req := make(map[string]any)
req["ins"] = symbol
req["side"] = side
@@ -371,7 +371,7 @@ func (a *Alphapoint) CreateOrder(ctx context.Context, symbol, side, orderType st
req["px"] = strconv.FormatFloat(price, 'f', -1, 64)
response := Response{}
err := a.SendAuthenticatedHTTPRequest(ctx,
err := e.SendAuthenticatedHTTPRequest(ctx,
exchange.RestSpot,
http.MethodPost,
alphapointCreateOrder,
@@ -395,14 +395,14 @@ func (a *Alphapoint) CreateOrder(ctx context.Context, symbol, side, orderType st
// book. A buy order will be modified to the highest bid and a sell order will
// be modified to the lowest ask price. “1” means "Execute now", which will
// convert a limit order into a market order.
func (a *Alphapoint) ModifyExistingOrder(ctx context.Context, symbol string, orderID, action int64) (int64, error) {
func (e *Exchange) ModifyExistingOrder(ctx context.Context, symbol string, orderID, action int64) (int64, error) {
req := make(map[string]any)
req["ins"] = symbol
req["serverOrderId"] = orderID
req["modifyAction"] = action
response := Response{}
err := a.SendAuthenticatedHTTPRequest(ctx,
err := e.SendAuthenticatedHTTPRequest(ctx,
exchange.RestSpot,
http.MethodPost,
alphapointModifyOrder,
@@ -421,13 +421,13 @@ func (a *Alphapoint) ModifyExistingOrder(ctx context.Context, symbol string, ord
// CancelExistingOrder cancels an order that has not been executed.
// symbol - Instrument code (ex: “BTCUSD”)
// OrderID - Order id (ex: 1000)
func (a *Alphapoint) CancelExistingOrder(ctx context.Context, orderID int64, omsid string) (int64, error) {
func (e *Exchange) CancelExistingOrder(ctx context.Context, orderID int64, omsid string) (int64, error) {
req := make(map[string]any)
req["OrderId"] = orderID
req["OMSId"] = omsid
response := Response{}
err := a.SendAuthenticatedHTTPRequest(ctx,
err := e.SendAuthenticatedHTTPRequest(ctx,
exchange.RestSpot,
http.MethodPost,
alphapointCancelOrder,
@@ -445,12 +445,12 @@ func (a *Alphapoint) CancelExistingOrder(ctx context.Context, orderID int64, oms
// CancelAllExistingOrders cancels all open orders by symbol.
// symbol - Instrument code (ex: “BTCUSD”)
func (a *Alphapoint) CancelAllExistingOrders(ctx context.Context, omsid string) error {
func (e *Exchange) CancelAllExistingOrders(ctx context.Context, omsid string) error {
req := make(map[string]any)
req["OMSId"] = omsid
response := Response{}
err := a.SendAuthenticatedHTTPRequest(ctx,
err := e.SendAuthenticatedHTTPRequest(ctx,
exchange.RestSpot,
http.MethodPost,
alphapointCancelAllOrders,
@@ -467,10 +467,10 @@ func (a *Alphapoint) CancelAllExistingOrders(ctx context.Context, omsid string)
}
// GetOrders returns all current open orders
func (a *Alphapoint) GetOrders(ctx context.Context) ([]OpenOrders, error) {
func (e *Exchange) GetOrders(ctx context.Context) ([]OpenOrders, error) {
response := OrderInfo{}
err := a.SendAuthenticatedHTTPRequest(ctx,
err := e.SendAuthenticatedHTTPRequest(ctx,
exchange.RestSpot,
http.MethodPost,
alphapointOpenOrders,
@@ -491,7 +491,7 @@ func (a *Alphapoint) GetOrders(ctx context.Context) ([]OpenOrders, error) {
// side - “buy” or “sell”
// quantity - Quantity
// price - Price in USD
func (a *Alphapoint) GetOrderFee(ctx context.Context, symbol, side string, quantity, price float64) (float64, error) {
func (e *Exchange) GetOrderFee(ctx context.Context, symbol, side string, quantity, price float64) (float64, error) {
req := make(map[string]any)
req["ins"] = symbol
req["side"] = side
@@ -499,7 +499,7 @@ func (a *Alphapoint) GetOrderFee(ctx context.Context, symbol, side string, quant
req["px"] = strconv.FormatFloat(price, 'f', -1, 64)
response := Response{}
err := a.SendAuthenticatedHTTPRequest(ctx,
err := e.SendAuthenticatedHTTPRequest(ctx,
exchange.RestSpot,
http.MethodPost,
alphapointOrderFee,
@@ -516,8 +516,8 @@ func (a *Alphapoint) GetOrderFee(ctx context.Context, symbol, side string, quant
}
// SendHTTPRequest sends an unauthenticated HTTP request
func (a *Alphapoint) SendHTTPRequest(ctx context.Context, ep exchange.URL, method, path string, data map[string]any, result any) error {
endpoint, err := a.API.Endpoints.GetURL(ep)
func (e *Exchange) SendHTTPRequest(ctx context.Context, ep exchange.URL, method, path string, data map[string]any, result any) error {
endpoint, err := e.API.Endpoints.GetURL(ep)
if err != nil {
return err
}
@@ -535,30 +535,30 @@ func (a *Alphapoint) SendHTTPRequest(ctx context.Context, ep exchange.URL, metho
Path: path,
Headers: headers,
Result: result,
Verbose: a.Verbose,
HTTPDebugging: a.HTTPDebugging,
HTTPRecording: a.HTTPRecording,
Verbose: e.Verbose,
HTTPDebugging: e.HTTPDebugging,
HTTPRecording: e.HTTPRecording,
}
return a.SendPayload(ctx, request.Unset, func() (*request.Item, error) {
return e.SendPayload(ctx, request.Unset, func() (*request.Item, error) {
item.Body = bytes.NewBuffer(PayloadJSON)
return item, nil
}, request.UnauthenticatedRequest)
}
// SendAuthenticatedHTTPRequest sends an authenticated request
func (a *Alphapoint) SendAuthenticatedHTTPRequest(ctx context.Context, ep exchange.URL, method, path string, data map[string]any, result any) error {
creds, err := a.GetCredentials(ctx)
func (e *Exchange) SendAuthenticatedHTTPRequest(ctx context.Context, ep exchange.URL, method, path string, data map[string]any, result any) error {
creds, err := e.GetCredentials(ctx)
if err != nil {
return err
}
endpoint, err := a.API.Endpoints.GetURL(ep)
endpoint, err := e.API.Endpoints.GetURL(ep)
if err != nil {
return err
}
n := a.Requester.GetNonce(nonce.UnixNano)
n := e.Requester.GetNonce(nonce.UnixNano)
headers := make(map[string]string)
headers["Content-Type"] = "application/json"
@@ -586,12 +586,12 @@ func (a *Alphapoint) SendAuthenticatedHTTPRequest(ctx context.Context, ep exchan
Headers: headers,
Result: result,
NonceEnabled: true,
Verbose: a.Verbose,
HTTPDebugging: a.HTTPDebugging,
HTTPRecording: a.HTTPRecording,
Verbose: e.Verbose,
HTTPDebugging: e.HTTPDebugging,
HTTPRecording: e.HTTPRecording,
}
return a.SendPayload(ctx, request.Unset, func() (*request.Item, error) {
return e.SendPayload(ctx, request.Unset, func() (*request.Item, error) {
item.Body = bytes.NewBuffer(PayloadJSON)
return item, nil
}, request.AuthenticatedRequest)

View File

@@ -22,15 +22,15 @@ const (
canManipulateRealOrders = false
)
var a *Alphapoint
var e = &Exchange{}
func TestMain(m *testing.M) {
a = new(Alphapoint)
a.SetDefaults()
e = new(Exchange)
e.SetDefaults()
if apiKey != "" && apiSecret != "" {
a.API.AuthenticatedSupport = true
a.SetCredentials(apiKey, apiSecret, "", "", "", "")
e.API.AuthenticatedSupport = true
e.SetCredentials(apiKey, apiSecret, "", "", "", "")
}
os.Exit(m.Run())
@@ -41,12 +41,12 @@ func TestGetTicker(t *testing.T) {
var ticker Ticker
var err error
if onlineTest {
ticker, err = a.GetTicker(t.Context(), "BTCUSD")
ticker, err = e.GetTicker(t.Context(), "BTCUSD")
if err != nil {
t.Fatal("Alphapoint GetTicker init error: ", err)
}
_, err = a.GetTicker(t.Context(), "wigwham")
_, err = e.GetTicker(t.Context(), "wigwham")
if err == nil {
t.Error("Alphapoint GetTicker Expected error")
}
@@ -75,12 +75,12 @@ func TestGetTrades(t *testing.T) {
var trades Trades
var err error
if onlineTest {
trades, err = a.GetTrades(t.Context(), "BTCUSD", 0, 10)
trades, err = e.GetTrades(t.Context(), "BTCUSD", 0, 10)
if err != nil {
t.Fatalf("Init error: %s", err)
}
_, err = a.GetTrades(t.Context(), "wigwham", 0, 10)
_, err = e.GetTrades(t.Context(), "wigwham", 0, 10)
if err == nil {
t.Fatal("GetTrades Expected error")
}
@@ -113,12 +113,12 @@ func TestGetOrderbook(t *testing.T) {
var orderBook Orderbook
var err error
if onlineTest {
orderBook, err = a.GetOrderbook(t.Context(), "BTCUSD")
orderBook, err = e.GetOrderbook(t.Context(), "BTCUSD")
if err != nil {
t.Errorf("Init error: %s", err)
}
_, err = a.GetOrderbook(t.Context(), "wigwham")
_, err = e.GetOrderbook(t.Context(), "wigwham")
if err == nil {
t.Error("GetOrderbook() Expected error")
}
@@ -156,7 +156,7 @@ func TestGetProductPairs(t *testing.T) {
var err error
if onlineTest {
products, err = a.GetProductPairs(t.Context())
products, err = e.GetProductPairs(t.Context())
if err != nil {
t.Errorf("Init error: %s", err)
}
@@ -194,7 +194,7 @@ func TestGetProducts(t *testing.T) {
var err error
if onlineTest {
products, err = a.GetProducts(t.Context())
products, err = e.GetProducts(t.Context())
if err != nil {
t.Errorf("Init error: %s", err)
}
@@ -228,19 +228,19 @@ func TestGetProducts(t *testing.T) {
func TestCreateAccount(t *testing.T) {
t.Parallel()
sharedtestvalues.SkipTestIfCredentialsUnset(t, a)
sharedtestvalues.SkipTestIfCredentialsUnset(t, e)
err := a.CreateAccount(t.Context(),
err := e.CreateAccount(t.Context(),
"test", "account", "something@something.com", "0292383745", "lolcat123")
if err != nil {
t.Errorf("Init error: %s", err)
}
err = a.CreateAccount(t.Context(),
err = e.CreateAccount(t.Context(),
"test", "account", "something@something.com", "0292383745", "bla")
if err == nil {
t.Errorf("CreateAccount() Expected error")
}
err = a.CreateAccount(t.Context(), "", "", "", "", "lolcat123")
err = e.CreateAccount(t.Context(), "", "", "", "", "lolcat123")
if err == nil {
t.Errorf("CreateAccount() Expected error")
}
@@ -248,9 +248,9 @@ func TestCreateAccount(t *testing.T) {
func TestGetUserInfo(t *testing.T) {
t.Parallel()
sharedtestvalues.SkipTestIfCredentialsUnset(t, a)
sharedtestvalues.SkipTestIfCredentialsUnset(t, e)
_, err := a.GetUserInfo(t.Context())
_, err := e.GetUserInfo(t.Context())
if err == nil {
t.Error("GetUserInfo() Expected error")
}
@@ -258,9 +258,9 @@ func TestGetUserInfo(t *testing.T) {
func TestSetUserInfo(t *testing.T) {
t.Parallel()
sharedtestvalues.SkipTestIfCredentialsUnset(t, a)
sharedtestvalues.SkipTestIfCredentialsUnset(t, e)
_, err := a.SetUserInfo(t.Context(),
_, err := e.SetUserInfo(t.Context(),
"bla", "bla", "1", "meh", true, true)
if err == nil {
t.Error("GetUserInfo() Expected error")
@@ -269,9 +269,9 @@ func TestSetUserInfo(t *testing.T) {
func TestGetAccountInfo(t *testing.T) {
t.Parallel()
sharedtestvalues.SkipTestIfCredentialsUnset(t, a)
sharedtestvalues.SkipTestIfCredentialsUnset(t, e)
_, err := a.UpdateAccountInfo(t.Context(), asset.Spot)
_, err := e.UpdateAccountInfo(t.Context(), asset.Spot)
if err == nil {
t.Error("GetUserInfo() Expected error")
}
@@ -279,9 +279,9 @@ func TestGetAccountInfo(t *testing.T) {
func TestGetAccountTrades(t *testing.T) {
t.Parallel()
sharedtestvalues.SkipTestIfCredentialsUnset(t, a)
sharedtestvalues.SkipTestIfCredentialsUnset(t, e)
_, err := a.GetAccountTrades(t.Context(), "", 1, 2)
_, err := e.GetAccountTrades(t.Context(), "", 1, 2)
if err == nil {
t.Error("GetUserInfo() Expected error")
}
@@ -289,9 +289,9 @@ func TestGetAccountTrades(t *testing.T) {
func TestGetDepositAddresses(t *testing.T) {
t.Parallel()
sharedtestvalues.SkipTestIfCredentialsUnset(t, a)
sharedtestvalues.SkipTestIfCredentialsUnset(t, e)
_, err := a.GetDepositAddresses(t.Context())
_, err := e.GetDepositAddresses(t.Context())
if err == nil {
t.Error("GetUserInfo() Expected error")
}
@@ -299,9 +299,9 @@ func TestGetDepositAddresses(t *testing.T) {
func TestWithdrawCoins(t *testing.T) {
t.Parallel()
sharedtestvalues.SkipTestIfCredentialsUnset(t, a)
sharedtestvalues.SkipTestIfCredentialsUnset(t, e)
err := a.WithdrawCoins(t.Context(), "", "", "", 0.01)
err := e.WithdrawCoins(t.Context(), "", "", "", 0.01)
if err == nil {
t.Error("GetUserInfo() Expected error")
}
@@ -309,9 +309,9 @@ func TestWithdrawCoins(t *testing.T) {
func TestCreateOrder(t *testing.T) {
t.Parallel()
sharedtestvalues.SkipTestIfCredentialsUnset(t, a)
sharedtestvalues.SkipTestIfCredentialsUnset(t, e)
_, err := a.CreateOrder(t.Context(),
_, err := e.CreateOrder(t.Context(),
"", "", order.Limit.String(), 0.01, 0)
if err == nil {
t.Error("GetUserInfo() Expected error")
@@ -320,9 +320,9 @@ func TestCreateOrder(t *testing.T) {
func TestModifyExistingOrder(t *testing.T) {
t.Parallel()
sharedtestvalues.SkipTestIfCredentialsUnset(t, a)
sharedtestvalues.SkipTestIfCredentialsUnset(t, e)
_, err := a.ModifyExistingOrder(t.Context(), "", 1, 1)
_, err := e.ModifyExistingOrder(t.Context(), "", 1, 1)
if err == nil {
t.Error("GetUserInfo() Expected error")
}
@@ -330,9 +330,9 @@ func TestModifyExistingOrder(t *testing.T) {
func TestCancelAllExistingOrders(t *testing.T) {
t.Parallel()
sharedtestvalues.SkipTestIfCredentialsUnset(t, a)
sharedtestvalues.SkipTestIfCredentialsUnset(t, e)
err := a.CancelAllExistingOrders(t.Context(), "")
err := e.CancelAllExistingOrders(t.Context(), "")
if err == nil {
t.Error("GetUserInfo() Expected error")
}
@@ -340,9 +340,9 @@ func TestCancelAllExistingOrders(t *testing.T) {
func TestGetOrders(t *testing.T) {
t.Parallel()
sharedtestvalues.SkipTestIfCredentialsUnset(t, a)
sharedtestvalues.SkipTestIfCredentialsUnset(t, e)
_, err := a.GetOrders(t.Context())
_, err := e.GetOrders(t.Context())
if err == nil {
t.Error("GetUserInfo() Expected error")
}
@@ -350,9 +350,9 @@ func TestGetOrders(t *testing.T) {
func TestGetOrderFee(t *testing.T) {
t.Parallel()
sharedtestvalues.SkipTestIfCredentialsUnset(t, a)
sharedtestvalues.SkipTestIfCredentialsUnset(t, e)
_, err := a.GetOrderFee(t.Context(), "", "", 1, 1)
_, err := e.GetOrderFee(t.Context(), "", "", 1, 1)
if err == nil {
t.Error("GetUserInfo() Expected error")
}
@@ -361,7 +361,7 @@ func TestGetOrderFee(t *testing.T) {
func TestFormatWithdrawPermissions(t *testing.T) {
t.Parallel()
expectedResult := exchange.AutoWithdrawCryptoWithAPIPermissionText + " & " + exchange.WithdrawCryptoWith2FAText + " & " + exchange.NoFiatWithdrawalsText
withdrawPermissions := a.FormatWithdrawPermissions()
withdrawPermissions := e.FormatWithdrawPermissions()
if withdrawPermissions != expectedResult {
t.Errorf("Expected: %s, Received: %s", expectedResult, withdrawPermissions)
}
@@ -375,10 +375,10 @@ func TestGetActiveOrders(t *testing.T) {
Side: order.AnySide,
}
_, err := a.GetActiveOrders(t.Context(), &getOrdersRequest)
if sharedtestvalues.AreAPICredentialsSet(a) && err != nil {
_, err := e.GetActiveOrders(t.Context(), &getOrdersRequest)
if sharedtestvalues.AreAPICredentialsSet(e) && err != nil {
t.Errorf("Could not get open orders: %s", err)
} else if !sharedtestvalues.AreAPICredentialsSet(a) && err == nil {
} else if !sharedtestvalues.AreAPICredentialsSet(e) && err == nil {
t.Error("Expecting an error when no keys are set")
}
}
@@ -391,10 +391,10 @@ func TestGetOrderHistory(t *testing.T) {
Side: order.AnySide,
}
_, err := a.GetOrderHistory(t.Context(), &getOrdersRequest)
if sharedtestvalues.AreAPICredentialsSet(a) && err != nil {
_, err := e.GetOrderHistory(t.Context(), &getOrdersRequest)
if sharedtestvalues.AreAPICredentialsSet(e) && err != nil {
t.Errorf("Could not get order history: %s", err)
} else if !sharedtestvalues.AreAPICredentialsSet(a) && err == nil {
} else if !sharedtestvalues.AreAPICredentialsSet(e) && err == nil {
t.Error("Expecting an error when no keys are set")
}
}
@@ -404,10 +404,10 @@ func TestGetOrderHistory(t *testing.T) {
func TestSubmitOrder(t *testing.T) {
t.Parallel()
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, a, canManipulateRealOrders)
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, e, canManipulateRealOrders)
orderSubmission := &order.Submit{
Exchange: a.Name,
Exchange: e.Name,
Pair: currency.Pair{
Delimiter: "_",
Base: currency.BTC,
@@ -421,11 +421,11 @@ func TestSubmitOrder(t *testing.T) {
AssetType: asset.Spot,
}
response, err := a.SubmitOrder(t.Context(), orderSubmission)
if !sharedtestvalues.AreAPICredentialsSet(a) && err == nil {
response, err := e.SubmitOrder(t.Context(), orderSubmission)
if !sharedtestvalues.AreAPICredentialsSet(e) && err == nil {
t.Error("Expecting an error when no keys are set")
}
if sharedtestvalues.AreAPICredentialsSet(a) && err != nil {
if sharedtestvalues.AreAPICredentialsSet(e) && err != nil {
t.Errorf("Withdraw failed to be placed: %v", err)
if response.Status != order.New {
@@ -436,7 +436,7 @@ func TestSubmitOrder(t *testing.T) {
func TestCancelExchangeOrder(t *testing.T) {
t.Parallel()
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, a, canManipulateRealOrders)
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, e, canManipulateRealOrders)
currencyPair := currency.NewPair(currency.BTC, currency.LTC)
orderCancellation := &order.Cancel{
@@ -446,18 +446,18 @@ func TestCancelExchangeOrder(t *testing.T) {
AssetType: asset.Spot,
}
err := a.CancelOrder(t.Context(), orderCancellation)
if !sharedtestvalues.AreAPICredentialsSet(a) && err == nil {
err := e.CancelOrder(t.Context(), orderCancellation)
if !sharedtestvalues.AreAPICredentialsSet(e) && err == nil {
t.Error("Expecting an error when no keys are set")
}
if sharedtestvalues.AreAPICredentialsSet(a) && err != nil {
if sharedtestvalues.AreAPICredentialsSet(e) && err != nil {
t.Errorf("Withdraw failed to be placed: %v", err)
}
}
func TestCancelAllExchangeOrders(t *testing.T) {
t.Parallel()
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, a, canManipulateRealOrders)
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, e, canManipulateRealOrders)
currencyPair := currency.NewPair(currency.BTC, currency.LTC)
orderCancellation := &order.Cancel{
@@ -467,11 +467,11 @@ func TestCancelAllExchangeOrders(t *testing.T) {
AssetType: asset.Spot,
}
resp, err := a.CancelAllOrders(t.Context(), orderCancellation)
if !sharedtestvalues.AreAPICredentialsSet(a) && err == nil {
resp, err := e.CancelAllOrders(t.Context(), orderCancellation)
if !sharedtestvalues.AreAPICredentialsSet(e) && err == nil {
t.Error("Expecting an error when no keys are set")
}
if sharedtestvalues.AreAPICredentialsSet(a) && err != nil {
if sharedtestvalues.AreAPICredentialsSet(e) && err != nil {
t.Errorf("Withdraw failed to be placed: %v", err)
}
@@ -482,8 +482,8 @@ func TestCancelAllExchangeOrders(t *testing.T) {
func TestModifyOrder(t *testing.T) {
t.Parallel()
sharedtestvalues.SkipTestIfCredentialsUnset(t, a, canManipulateRealOrders)
_, err := a.ModifyOrder(t.Context(), &order.Modify{AssetType: asset.Spot})
sharedtestvalues.SkipTestIfCredentialsUnset(t, e, canManipulateRealOrders)
_, err := e.ModifyOrder(t.Context(), &order.Modify{AssetType: asset.Spot})
if err == nil {
t.Error("ModifyOrder() Expected error")
}
@@ -491,7 +491,7 @@ func TestModifyOrder(t *testing.T) {
func TestWithdraw(t *testing.T) {
t.Parallel()
_, err := a.WithdrawCryptocurrencyFunds(t.Context(),
_, err := e.WithdrawCryptocurrencyFunds(t.Context(),
&withdraw.Request{})
if err != common.ErrNotYetImplemented {
t.Errorf("Expected 'Not implemented', received %v", err)
@@ -500,9 +500,9 @@ func TestWithdraw(t *testing.T) {
func TestWithdrawFiat(t *testing.T) {
t.Parallel()
sharedtestvalues.SkipTestIfCredentialsUnset(t, a, canManipulateRealOrders)
sharedtestvalues.SkipTestIfCredentialsUnset(t, e, canManipulateRealOrders)
_, err := a.WithdrawFiatFunds(t.Context(),
_, err := e.WithdrawFiatFunds(t.Context(),
&withdraw.Request{})
if err != common.ErrNotYetImplemented {
t.Errorf("Expected '%v', received: '%v'", common.ErrNotYetImplemented, err)
@@ -511,9 +511,9 @@ func TestWithdrawFiat(t *testing.T) {
func TestWithdrawInternationalBank(t *testing.T) {
t.Parallel()
sharedtestvalues.SkipTestIfCredentialsUnset(t, a, canManipulateRealOrders)
sharedtestvalues.SkipTestIfCredentialsUnset(t, e, canManipulateRealOrders)
_, err := a.WithdrawFiatFundsToInternationalBank(t.Context(), &withdraw.Request{})
_, err := e.WithdrawFiatFundsToInternationalBank(t.Context(), &withdraw.Request{})
if err != common.ErrNotYetImplemented {
t.Errorf("Expected '%v', received: '%v'", common.ErrNotYetImplemented, err)
}
@@ -525,7 +525,7 @@ func TestGetRecentTrades(t *testing.T) {
if err != nil {
t.Fatal(err)
}
_, err = a.GetRecentTrades(t.Context(), currencyPair, asset.Spot)
_, err = e.GetRecentTrades(t.Context(), currencyPair, asset.Spot)
if err != nil && err != common.ErrNotYetImplemented {
t.Error(err)
}
@@ -537,7 +537,7 @@ func TestGetHistoricTrades(t *testing.T) {
if err != nil {
t.Fatal(err)
}
_, err = a.GetHistoricTrades(t.Context(),
_, err = e.GetHistoricTrades(t.Context(),
currencyPair, asset.Spot, time.Now().Add(-time.Minute*15), time.Now())
if err != nil && err != common.ErrNotYetImplemented {
t.Error(err)

View File

@@ -14,35 +14,35 @@ const (
)
// WebsocketClient starts a new webstocket connection
func (a *Alphapoint) WebsocketClient() {
for a.Enabled {
func (e *Exchange) WebsocketClient() {
for e.Enabled {
var dialer gws.Dialer
var err error
var httpResp *http.Response
endpoint, err := a.API.Endpoints.GetURL(exchange.WebsocketSpot)
endpoint, err := e.API.Endpoints.GetURL(exchange.WebsocketSpot)
if err != nil {
log.Errorln(log.WebsocketMgr, err)
}
a.WebsocketConn, httpResp, err = dialer.Dial(endpoint, http.Header{})
e.WebsocketConn, httpResp, err = dialer.Dial(endpoint, http.Header{})
httpResp.Body.Close() // not used, so safely free the body
if err != nil {
log.Errorf(log.ExchangeSys, "%s Unable to connect to Websocket. Error: %s\n", a.Name, err)
log.Errorf(log.ExchangeSys, "%s Unable to connect to Websocket. Error: %s\n", e.Name, err)
continue
}
if a.Verbose {
log.Debugf(log.ExchangeSys, "%s Connected to Websocket.\n", a.Name)
if e.Verbose {
log.Debugf(log.ExchangeSys, "%s Connected to Websocket.\n", e.Name)
}
err = a.WebsocketConn.WriteMessage(gws.TextMessage, []byte(`{"messageType": "logon"}`))
err = e.WebsocketConn.WriteMessage(gws.TextMessage, []byte(`{"messageType": "logon"}`))
if err != nil {
log.Errorln(log.ExchangeSys, err)
return
}
for a.Enabled {
msgType, resp, err := a.WebsocketConn.ReadMessage()
for e.Enabled {
msgType, resp, err := e.WebsocketConn.ReadMessage()
if err != nil {
log.Errorln(log.ExchangeSys, err)
break
@@ -70,7 +70,7 @@ func (a *Alphapoint) WebsocketClient() {
}
}
}
a.WebsocketConn.Close()
log.Debugf(log.ExchangeSys, "%s Websocket client disconnected.", a.Name)
e.WebsocketConn.Close()
log.Debugf(log.ExchangeSys, "%s Websocket client disconnected.", e.Name)
}
}

View File

@@ -27,22 +27,22 @@ import (
)
// SetDefaults sets current default settings
func (a *Alphapoint) SetDefaults() {
a.Name = "Alphapoint"
a.Enabled = true
a.Verbose = true
a.API.Endpoints = a.NewEndpoints()
err := a.API.Endpoints.SetDefaultEndpoints(map[exchange.URL]string{
func (e *Exchange) SetDefaults() {
e.Name = "Alphapoint"
e.Enabled = true
e.Verbose = true
e.API.Endpoints = e.NewEndpoints()
err := e.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
e.API.CredentialsValidator.RequiresKey = true
e.API.CredentialsValidator.RequiresSecret = true
a.Features = exchange.Features{
e.Features = exchange.Features{
Supports: exchange.FeaturesSupported{
REST: true,
Websocket: true,
@@ -72,7 +72,7 @@ func (a *Alphapoint) SetDefaults() {
},
}
a.Requester, err = request.New(a.Name,
e.Requester, err = request.New(e.Name,
common.NewHTTPClientWithTimeout(exchange.DefaultHTTPTimeout))
if err != nil {
log.Errorln(log.ExchangeSys, err)
@@ -80,32 +80,32 @@ func (a *Alphapoint) SetDefaults() {
}
// Setup takes in the supplied exchange configuration details and sets params
func (a *Alphapoint) Setup(_ *config.Exchange) error {
func (e *Exchange) Setup(_ *config.Exchange) error {
return common.ErrFunctionNotSupported
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (a *Alphapoint) FetchTradablePairs(_ context.Context, _ asset.Item) (currency.Pairs, error) {
func (e *Exchange) FetchTradablePairs(_ context.Context, _ asset.Item) (currency.Pairs, error) {
return nil, common.ErrFunctionNotSupported
}
// GetServerTime returns the current exchange server time.
func (a *Alphapoint) GetServerTime(_ context.Context, _ asset.Item) (time.Time, error) {
func (e *Exchange) GetServerTime(_ context.Context, _ asset.Item) (time.Time, error) {
return time.Time{}, common.ErrFunctionNotSupported
}
// UpdateTradablePairs updates the exchanges available pairs and stores
// them in the exchanges config
func (a *Alphapoint) UpdateTradablePairs(_ context.Context, _ bool) error {
func (e *Exchange) UpdateTradablePairs(_ context.Context, _ bool) error {
return common.ErrFunctionNotSupported
}
// UpdateAccountInfo retrieves balances for all enabled currencies on the
// Alphapoint exchange
func (a *Alphapoint) UpdateAccountInfo(ctx context.Context, assetType asset.Item) (account.Holdings, error) {
func (e *Exchange) UpdateAccountInfo(ctx context.Context, assetType asset.Item) (account.Holdings, error) {
var response account.Holdings
response.Exchange = a.Name
acc, err := a.GetAccountInformation(ctx)
response.Exchange = e.Name
acc, err := e.GetAccountInformation(ctx)
if err != nil {
return response, err
}
@@ -125,7 +125,7 @@ func (a *Alphapoint) UpdateAccountInfo(ctx context.Context, assetType asset.Item
AssetType: assetType,
})
creds, err := a.GetCredentials(ctx)
creds, err := e.GetCredentials(ctx)
if err != nil {
return account.Holdings{}, err
}
@@ -139,19 +139,19 @@ func (a *Alphapoint) UpdateAccountInfo(ctx context.Context, assetType asset.Item
}
// UpdateTickers updates the ticker for all currency pairs of a given asset type
func (a *Alphapoint) UpdateTickers(_ context.Context, _ asset.Item) error {
func (e *Exchange) UpdateTickers(_ context.Context, _ asset.Item) error {
return common.ErrFunctionNotSupported
}
// UpdateTicker updates and returns the ticker for a currency pair
func (a *Alphapoint) UpdateTicker(ctx context.Context, p currency.Pair, assetType asset.Item) (*ticker.Price, error) {
func (e *Exchange) UpdateTicker(ctx context.Context, p currency.Pair, assetType asset.Item) (*ticker.Price, error) {
if p.IsEmpty() {
return nil, currency.ErrCurrencyPairEmpty
}
if err := a.CurrencyPairs.IsAssetEnabled(assetType); err != nil {
if err := e.CurrencyPairs.IsAssetEnabled(assetType); err != nil {
return nil, err
}
tick, err := a.GetTicker(ctx, p.String())
tick, err := e.GetTicker(ctx, p.String())
if err != nil {
return nil, err
}
@@ -164,26 +164,26 @@ func (a *Alphapoint) UpdateTicker(ctx context.Context, p currency.Pair, assetTyp
High: tick.High,
Volume: tick.Volume,
Last: tick.Last,
ExchangeName: a.Name,
ExchangeName: e.Name,
AssetType: assetType,
})
if err != nil {
return nil, err
}
return ticker.GetTicker(a.Name, p, assetType)
return ticker.GetTicker(e.Name, p, assetType)
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (a *Alphapoint) UpdateOrderbook(ctx context.Context, p currency.Pair, assetType asset.Item) (*orderbook.Book, error) {
func (e *Exchange) UpdateOrderbook(ctx context.Context, p currency.Pair, assetType asset.Item) (*orderbook.Book, error) {
if p.IsEmpty() {
return nil, currency.ErrCurrencyPairEmpty
}
if err := a.CurrencyPairs.IsAssetEnabled(assetType); err != nil {
if err := e.CurrencyPairs.IsAssetEnabled(assetType); err != nil {
return nil, err
}
orderBook := new(orderbook.Book)
orderbookNew, err := a.GetOrderbook(ctx, p.String())
orderbookNew, err := e.GetOrderbook(ctx, p.String())
if err != nil {
return orderBook, err
}
@@ -205,7 +205,7 @@ func (a *Alphapoint) UpdateOrderbook(ctx context.Context, p currency.Pair, asset
}
orderBook.Pair = p
orderBook.Exchange = a.Name
orderBook.Exchange = e.Name
orderBook.Asset = assetType
err = orderBook.Process()
@@ -213,44 +213,44 @@ func (a *Alphapoint) UpdateOrderbook(ctx context.Context, p currency.Pair, asset
return orderBook, err
}
return orderbook.Get(a.Name, p, assetType)
return orderbook.Get(e.Name, p, assetType)
}
// GetAccountFundingHistory returns funding history, deposits and
// withdrawals
func (a *Alphapoint) GetAccountFundingHistory(_ context.Context) ([]exchange.FundingHistory, error) {
func (e *Exchange) GetAccountFundingHistory(_ context.Context) ([]exchange.FundingHistory, error) {
// https://alphapoint.github.io/slate/#generatetreasuryactivityreport
return nil, common.ErrNotYetImplemented
}
// GetWithdrawalsHistory returns previous withdrawals data
func (a *Alphapoint) GetWithdrawalsHistory(_ context.Context, _ currency.Code, _ asset.Item) ([]exchange.WithdrawalHistory, error) {
func (e *Exchange) GetWithdrawalsHistory(_ context.Context, _ currency.Code, _ asset.Item) ([]exchange.WithdrawalHistory, error) {
return nil, common.ErrNotYetImplemented
}
// GetRecentTrades returns the most recent trades for a currency and asset
func (a *Alphapoint) GetRecentTrades(_ context.Context, _ currency.Pair, _ asset.Item) ([]trade.Data, error) {
func (e *Exchange) GetRecentTrades(_ context.Context, _ currency.Pair, _ asset.Item) ([]trade.Data, error) {
return nil, common.ErrNotYetImplemented
}
// GetHistoricTrades returns historic trade data within the timeframe provided
func (a *Alphapoint) GetHistoricTrades(_ context.Context, _ currency.Pair, _ asset.Item, _, _ time.Time) ([]trade.Data, error) {
func (e *Exchange) GetHistoricTrades(_ context.Context, _ currency.Pair, _ asset.Item, _, _ time.Time) ([]trade.Data, error) {
return nil, common.ErrNotYetImplemented
}
// SubmitOrder submits a new order and returns a true value when
// successfully submitted
func (a *Alphapoint) SubmitOrder(ctx context.Context, s *order.Submit) (*order.SubmitResponse, error) {
if err := s.Validate(a.GetTradingRequirements()); err != nil {
func (e *Exchange) SubmitOrder(ctx context.Context, s *order.Submit) (*order.SubmitResponse, error) {
if err := s.Validate(e.GetTradingRequirements()); err != nil {
return nil, err
}
fPair, err := a.FormatExchangeCurrency(s.Pair, s.AssetType)
fPair, err := e.FormatExchangeCurrency(s.Pair, s.AssetType)
if err != nil {
return nil, err
}
response, err := a.CreateOrder(ctx,
response, err := e.CreateOrder(ctx,
fPair.String(),
s.Side.String(),
s.Type.String(),
@@ -264,12 +264,12 @@ func (a *Alphapoint) SubmitOrder(ctx context.Context, s *order.Submit) (*order.S
// ModifyOrder will allow of changing orderbook placement and limit to
// market conversion
func (a *Alphapoint) ModifyOrder(_ context.Context, _ *order.Modify) (*order.ModifyResponse, error) {
func (e *Exchange) ModifyOrder(_ context.Context, _ *order.Modify) (*order.ModifyResponse, error) {
return nil, common.ErrNotYetImplemented
}
// CancelOrder cancels an order by its corresponding ID number
func (a *Alphapoint) CancelOrder(ctx context.Context, o *order.Cancel) error {
func (e *Exchange) CancelOrder(ctx context.Context, o *order.Cancel) error {
if err := o.Validate(o.StandardCancel()); err != nil {
return err
}
@@ -277,32 +277,32 @@ func (a *Alphapoint) CancelOrder(ctx context.Context, o *order.Cancel) error {
if err != nil {
return err
}
_, err = a.CancelExistingOrder(ctx, orderIDInt, o.AccountID)
_, err = e.CancelExistingOrder(ctx, orderIDInt, o.AccountID)
return err
}
// CancelBatchOrders cancels an orders by their corresponding ID numbers
func (a *Alphapoint) CancelBatchOrders(_ context.Context, _ []order.Cancel) (*order.CancelBatchResponse, error) {
func (e *Exchange) CancelBatchOrders(_ context.Context, _ []order.Cancel) (*order.CancelBatchResponse, error) {
return nil, common.ErrNotYetImplemented
}
// CancelAllOrders cancels all orders for a given account
func (a *Alphapoint) CancelAllOrders(ctx context.Context, orderCancellation *order.Cancel) (order.CancelAllResponse, error) {
func (e *Exchange) CancelAllOrders(ctx context.Context, orderCancellation *order.Cancel) (order.CancelAllResponse, error) {
if err := orderCancellation.Validate(); err != nil {
return order.CancelAllResponse{}, err
}
return order.CancelAllResponse{},
a.CancelAllExistingOrders(ctx, orderCancellation.AccountID)
e.CancelAllExistingOrders(ctx, orderCancellation.AccountID)
}
// GetOrderInfo returns order information based on order ID
func (a *Alphapoint) GetOrderInfo(_ context.Context, _ string, _ currency.Pair, _ asset.Item) (*order.Detail, error) {
func (e *Exchange) GetOrderInfo(_ context.Context, _ string, _ currency.Pair, _ asset.Item) (*order.Detail, error) {
return nil, common.ErrNotYetImplemented
}
// GetDepositAddress returns a deposit address for a specified currency
func (a *Alphapoint) GetDepositAddress(ctx context.Context, cryptocurrency currency.Code, _, _ string) (*deposit.Address, error) {
addresses, err := a.GetDepositAddresses(ctx)
func (e *Exchange) GetDepositAddress(ctx context.Context, cryptocurrency currency.Code, _, _ string) (*deposit.Address, error) {
addresses, err := e.GetDepositAddresses(ctx)
if err != nil {
return nil, err
}
@@ -319,34 +319,34 @@ func (a *Alphapoint) GetDepositAddress(ctx context.Context, cryptocurrency curre
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
// submitted
func (a *Alphapoint) WithdrawCryptocurrencyFunds(_ context.Context, _ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
func (e *Exchange) WithdrawCryptocurrencyFunds(_ context.Context, _ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
return nil, common.ErrNotYetImplemented
}
// WithdrawFiatFunds returns a withdrawal ID when a withdrawal is submitted
func (a *Alphapoint) WithdrawFiatFunds(_ context.Context, _ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
func (e *Exchange) WithdrawFiatFunds(_ context.Context, _ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
return nil, common.ErrNotYetImplemented
}
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a withdrawal is
// submitted
func (a *Alphapoint) WithdrawFiatFundsToInternationalBank(_ context.Context, _ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
func (e *Exchange) WithdrawFiatFundsToInternationalBank(_ context.Context, _ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
return nil, common.ErrNotYetImplemented
}
// GetFeeByType returns an estimate of fee based on type of transaction
func (a *Alphapoint) GetFeeByType(_ context.Context, _ *exchange.FeeBuilder) (float64, error) {
func (e *Exchange) GetFeeByType(_ context.Context, _ *exchange.FeeBuilder) (float64, error) {
return 0, common.ErrFunctionNotSupported
}
// GetActiveOrders retrieves any orders that are active/open
// This function is not concurrency safe due to orderSide/orderType maps
func (a *Alphapoint) GetActiveOrders(ctx context.Context, req *order.MultiOrderRequest) (order.FilteredOrders, error) {
func (e *Exchange) GetActiveOrders(ctx context.Context, req *order.MultiOrderRequest) (order.FilteredOrders, error) {
err := req.Validate()
if err != nil {
return nil, err
}
resp, err := a.GetOrders(ctx)
resp, err := e.GetOrders(ctx)
if err != nil {
return nil, err
}
@@ -359,7 +359,7 @@ func (a *Alphapoint) GetActiveOrders(ctx context.Context, req *order.MultiOrderR
}
orders = append(orders, order.Detail{
Amount: resp[x].OpenOrders[y].QtyTotal,
Exchange: a.Name,
Exchange: e.Name,
ExecutedAmount: resp[x].OpenOrders[y].QtyTotal - resp[x].OpenOrders[y].QtyRemaining,
AccountID: strconv.FormatInt(int64(resp[x].OpenOrders[y].AccountID), 10),
OrderID: strconv.FormatInt(int64(resp[x].OpenOrders[y].ServerOrderID), 10),
@@ -371,19 +371,19 @@ func (a *Alphapoint) GetActiveOrders(ctx context.Context, req *order.MultiOrderR
})
}
}
return req.Filter(a.Name, orders), nil
return req.Filter(e.Name, orders), nil
}
// GetOrderHistory retrieves account order information
// Can Limit response to specific order status
// This function is not concurrency safe due to orderSide/orderType maps
func (a *Alphapoint) GetOrderHistory(ctx context.Context, req *order.MultiOrderRequest) (order.FilteredOrders, error) {
func (e *Exchange) GetOrderHistory(ctx context.Context, req *order.MultiOrderRequest) (order.FilteredOrders, error) {
err := req.Validate()
if err != nil {
return nil, err
}
resp, err := a.GetOrders(ctx)
resp, err := e.GetOrders(ctx)
if err != nil {
return nil, err
}
@@ -398,7 +398,7 @@ func (a *Alphapoint) GetOrderHistory(ctx context.Context, req *order.MultiOrderR
orders = append(orders, order.Detail{
Amount: resp[x].OpenOrders[y].QtyTotal,
AccountID: strconv.FormatInt(int64(resp[x].OpenOrders[y].AccountID), 10),
Exchange: a.Name,
Exchange: e.Name,
ExecutedAmount: resp[x].OpenOrders[y].QtyTotal - resp[x].OpenOrders[y].QtyRemaining,
OrderID: strconv.FormatInt(int64(resp[x].OpenOrders[y].ServerOrderID), 10),
Price: resp[x].OpenOrders[y].Price,
@@ -409,38 +409,38 @@ func (a *Alphapoint) GetOrderHistory(ctx context.Context, req *order.MultiOrderR
})
}
}
return req.Filter(a.Name, orders), nil
return req.Filter(e.Name, orders), nil
}
// ValidateAPICredentials validates current credentials used for wrapper
// functionality
func (a *Alphapoint) ValidateAPICredentials(ctx context.Context, assetType asset.Item) error {
_, err := a.UpdateAccountInfo(ctx, assetType)
return a.CheckTransientError(err)
func (e *Exchange) ValidateAPICredentials(ctx context.Context, assetType asset.Item) error {
_, err := e.UpdateAccountInfo(ctx, assetType)
return e.CheckTransientError(err)
}
// GetHistoricCandles returns candles between a time period for a set time interval
func (a *Alphapoint) GetHistoricCandles(_ context.Context, _ currency.Pair, _ asset.Item, _ kline.Interval, _, _ time.Time) (*kline.Item, error) {
func (e *Exchange) GetHistoricCandles(_ context.Context, _ currency.Pair, _ asset.Item, _ kline.Interval, _, _ time.Time) (*kline.Item, error) {
return nil, common.ErrNotYetImplemented
}
// GetHistoricCandlesExtended returns candles between a time period for a set
// time interval
func (a *Alphapoint) GetHistoricCandlesExtended(_ context.Context, _ currency.Pair, _ asset.Item, _ kline.Interval, _, _ time.Time) (*kline.Item, error) {
func (e *Exchange) GetHistoricCandlesExtended(_ context.Context, _ currency.Pair, _ asset.Item, _ kline.Interval, _, _ time.Time) (*kline.Item, error) {
return nil, common.ErrNotYetImplemented
}
// GetFuturesContractDetails returns all contracts from the exchange by asset type
func (a *Alphapoint) GetFuturesContractDetails(context.Context, asset.Item) ([]futures.Contract, error) {
func (e *Exchange) GetFuturesContractDetails(context.Context, asset.Item) ([]futures.Contract, error) {
return nil, common.ErrFunctionNotSupported
}
// GetLatestFundingRates returns the latest funding rates data
func (a *Alphapoint) GetLatestFundingRates(context.Context, *fundingrate.LatestRateRequest) ([]fundingrate.LatestRateResponse, error) {
func (e *Exchange) GetLatestFundingRates(context.Context, *fundingrate.LatestRateRequest) ([]fundingrate.LatestRateResponse, error) {
return nil, common.ErrFunctionNotSupported
}
// UpdateOrderExecutionLimits updates order execution limits
func (a *Alphapoint) UpdateOrderExecutionLimits(_ context.Context, _ asset.Item) error {
func (e *Exchange) UpdateOrderExecutionLimits(_ context.Context, _ asset.Item) error {
return common.ErrNotYetImplemented
}