mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
exchanges: Initial context propagation (#744)
* gct: phase one context awareness pass * exchanges: context propagation pass * common/requester: force context requirement * gctcli/exchanges: linter fix * rpcserver: fix test using dummy rpc server * backtester: fix comments * grpc: add correct cancel and timeout for commands * rpcserver_test: add comment on dummy server * common: deprecated SendHTTPGetRequest * linter: fix * linter: turn on no context check * apichecker: fix context linter issue * binance: use param context * common: remove checks as this gets executed before main * common: change mutex to RW as clients can be used by multiple go routines. * common: remove init and JIT default client. Unexport global variables and add protection. * common: Add comments * bithumb: after dinner mints fix
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package gct
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
@@ -63,7 +64,8 @@ func ExchangeOrderbook(args ...objects.Object) (objects.Object, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ob, err := wrappers.GetWrapper().Orderbook(exchangeName, pair, assetType)
|
||||
ob, err := wrappers.GetWrapper().
|
||||
Orderbook(context.TODO(), exchangeName, pair, assetType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -129,7 +131,8 @@ func ExchangeTicker(args ...objects.Object) (objects.Object, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tx, err := wrappers.GetWrapper().Ticker(exchangeName, pair, assetType)
|
||||
tx, err := wrappers.GetWrapper().
|
||||
Ticker(context.TODO(), exchangeName, pair, assetType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -229,7 +232,8 @@ func ExchangeAccountInfo(args ...objects.Object) (objects.Object, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rtnValue, err := wrappers.GetWrapper().AccountInformation(exchangeName, assetType)
|
||||
rtnValue, err := wrappers.GetWrapper().
|
||||
AccountInformation(context.TODO(), exchangeName, assetType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -297,7 +301,8 @@ func ExchangeOrderQuery(args ...objects.Object) (objects.Object, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
orderDetails, err := wrappers.GetWrapper().QueryOrder(exchangeName, orderID, pair, assetType)
|
||||
orderDetails, err := wrappers.GetWrapper().
|
||||
QueryOrder(context.TODO(), exchangeName, orderID, pair, assetType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -384,7 +389,8 @@ func ExchangeOrderCancel(args ...objects.Object) (objects.Object, error) {
|
||||
}
|
||||
|
||||
var isCancelled bool
|
||||
isCancelled, err = wrappers.GetWrapper().CancelOrder(exchangeName, orderID, cp, a)
|
||||
isCancelled, err = wrappers.GetWrapper().
|
||||
CancelOrder(context.TODO(), exchangeName, orderID, cp, a)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -457,7 +463,7 @@ func ExchangeOrderSubmit(args ...objects.Object) (objects.Object, error) {
|
||||
Exchange: exchangeName,
|
||||
}
|
||||
|
||||
rtn, err := wrappers.GetWrapper().SubmitOrder(tempSubmit)
|
||||
rtn, err := wrappers.GetWrapper().SubmitOrder(context.TODO(), tempSubmit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -547,7 +553,8 @@ func ExchangeWithdrawCrypto(args ...objects.Object) (objects.Object, error) {
|
||||
Amount: amount,
|
||||
}
|
||||
|
||||
rtn, err := wrappers.GetWrapper().WithdrawalCryptoFunds(withdrawRequest)
|
||||
rtn, err := wrappers.GetWrapper().
|
||||
WithdrawalCryptoFunds(context.TODO(), withdrawRequest)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -589,7 +596,8 @@ func ExchangeWithdrawFiat(args ...objects.Object) (objects.Object, error) {
|
||||
Amount: amount,
|
||||
}
|
||||
|
||||
rtn, err := wrappers.GetWrapper().WithdrawalFiatFunds(bankAccountID, withdrawRequest)
|
||||
rtn, err := wrappers.GetWrapper().
|
||||
WithdrawalFiatFunds(context.TODO(), bankAccountID, withdrawRequest)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -656,7 +664,14 @@ func exchangeOHLCV(args ...objects.Object) (objects.Object, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ret, err := wrappers.GetWrapper().OHLCV(exchangeName, pair, assetType, startTime, endTime, kline.Interval(interval))
|
||||
ret, err := wrappers.GetWrapper().
|
||||
OHLCV(context.TODO(),
|
||||
exchangeName,
|
||||
pair,
|
||||
assetType,
|
||||
startTime,
|
||||
endTime,
|
||||
kline.Interval(interval))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package modules
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
@@ -32,17 +33,17 @@ type GCT interface {
|
||||
type Exchange interface {
|
||||
Exchanges(enabledOnly bool) []string
|
||||
IsEnabled(exch string) bool
|
||||
Orderbook(exch string, pair currency.Pair, item asset.Item) (*orderbook.Base, error)
|
||||
Ticker(exch string, pair currency.Pair, item asset.Item) (*ticker.Price, error)
|
||||
Orderbook(ctx context.Context, exch string, pair currency.Pair, item asset.Item) (*orderbook.Base, error)
|
||||
Ticker(ctx context.Context, exch string, pair currency.Pair, item asset.Item) (*ticker.Price, error)
|
||||
Pairs(exch string, enabledOnly bool, item asset.Item) (*currency.Pairs, error)
|
||||
QueryOrder(exch, orderid string, pair currency.Pair, assetType asset.Item) (*order.Detail, error)
|
||||
SubmitOrder(submit *order.Submit) (*order.SubmitResponse, error)
|
||||
CancelOrder(exch, orderid string, pair currency.Pair, item asset.Item) (bool, error)
|
||||
AccountInformation(exch string, assetType asset.Item) (account.Holdings, error)
|
||||
QueryOrder(ctx context.Context, exch, orderid string, pair currency.Pair, assetType asset.Item) (*order.Detail, error)
|
||||
SubmitOrder(ctx context.Context, submit *order.Submit) (*order.SubmitResponse, error)
|
||||
CancelOrder(ctx context.Context, exch, orderid string, pair currency.Pair, item asset.Item) (bool, error)
|
||||
AccountInformation(ctx context.Context, exch string, assetType asset.Item) (account.Holdings, error)
|
||||
DepositAddress(exch string, currencyCode currency.Code) (string, error)
|
||||
WithdrawalFiatFunds(bankAccountID string, request *withdraw.Request) (out string, err error)
|
||||
WithdrawalCryptoFunds(request *withdraw.Request) (out string, err error)
|
||||
OHLCV(exch string, pair currency.Pair, item asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error)
|
||||
WithdrawalFiatFunds(ctx context.Context, bankAccountID string, request *withdraw.Request) (out string, err error)
|
||||
WithdrawalCryptoFunds(ctx context.Context, request *withdraw.Request) (out string, err error)
|
||||
OHLCV(ctx context.Context, exch string, pair currency.Pair, item asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error)
|
||||
}
|
||||
|
||||
// SetModuleWrapper link the wrapper and interface to use for modules
|
||||
|
||||
@@ -41,7 +41,7 @@ func (g *GctScriptManager) Validate(file string) (err error) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return tempVM.Run()
|
||||
return tempVM.RunCtx()
|
||||
}
|
||||
|
||||
// ShutdownAll shutdown all
|
||||
|
||||
@@ -109,38 +109,19 @@ func (vm *VM) Compile() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// Run runs byte code
|
||||
func (vm *VM) Run() (err error) {
|
||||
if vm.config.Verbose {
|
||||
log.Debugf(log.GCTScriptMgr, "Running script: %s ID: %v", vm.ShortName(), vm.ID)
|
||||
}
|
||||
|
||||
err = vm.Compiled.Run()
|
||||
if err != nil {
|
||||
vm.event(StatusFailure, TypeExecute)
|
||||
return Error{
|
||||
Action: "Run",
|
||||
Cause: err,
|
||||
}
|
||||
}
|
||||
vm.event(StatusSuccess, TypeExecute)
|
||||
return
|
||||
}
|
||||
|
||||
// RunCtx runs compiled byte code with context.Context support.
|
||||
func (vm *VM) RunCtx() (err error) {
|
||||
if vm.ctx == nil {
|
||||
vm.ctx = context.Background()
|
||||
}
|
||||
|
||||
ct, cancel := context.WithTimeout(vm.ctx, vm.config.ScriptTimeout)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), vm.config.ScriptTimeout)
|
||||
defer cancel()
|
||||
|
||||
if vm.config.Verbose {
|
||||
log.Debugf(log.GCTScriptMgr, "Running script: %s ID: %v", vm.ShortName(), vm.ID)
|
||||
log.Debugf(log.GCTScriptMgr,
|
||||
"Running script: %s ID: %v",
|
||||
vm.ShortName(),
|
||||
vm.ID)
|
||||
}
|
||||
|
||||
err = vm.Compiled.RunContext(ct)
|
||||
err = vm.Compiled.RunContext(ctx)
|
||||
if err != nil {
|
||||
vm.event(StatusFailure, TypeExecute)
|
||||
return Error{
|
||||
|
||||
@@ -219,7 +219,7 @@ func TestVMRun(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = testVM.Run()
|
||||
err = testVM.RunCtx()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -444,7 +444,7 @@ func TestVM_CompileInvalid(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = testVM.Run()
|
||||
err = testVM.RunCtx()
|
||||
if err == nil {
|
||||
t.Fatal("unexpected result broken script compiled successfully ")
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package vm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -54,7 +53,6 @@ type VM struct {
|
||||
Path string
|
||||
Script *tengo.Script
|
||||
Compiled *tengo.Compiled
|
||||
ctx context.Context
|
||||
T time.Duration
|
||||
NextRun time.Time
|
||||
S chan struct{}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package exchange
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"sort"
|
||||
"strconv"
|
||||
@@ -43,18 +44,18 @@ func (e Exchange) IsEnabled(exch string) bool {
|
||||
}
|
||||
|
||||
// Orderbook returns current orderbook requested exchange, pair and asset
|
||||
func (e Exchange) Orderbook(exch string, pair currency.Pair, item asset.Item) (*orderbook.Base, error) {
|
||||
return engine.Bot.GetSpecificOrderbook(pair, exch, item)
|
||||
func (e Exchange) Orderbook(ctx context.Context, exch string, pair currency.Pair, item asset.Item) (*orderbook.Base, error) {
|
||||
return engine.Bot.GetSpecificOrderbook(ctx, pair, exch, item)
|
||||
}
|
||||
|
||||
// Ticker returns ticker for provided currency pair & asset type
|
||||
func (e Exchange) Ticker(exch string, pair currency.Pair, item asset.Item) (*ticker.Price, error) {
|
||||
func (e Exchange) Ticker(ctx context.Context, exch string, pair currency.Pair, item asset.Item) (*ticker.Price, error) {
|
||||
ex, err := e.GetExchange(exch)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ex.FetchTicker(pair, item)
|
||||
return ex.FetchTicker(ctx, pair, item)
|
||||
}
|
||||
|
||||
// Pairs returns either all or enabled currency pairs
|
||||
@@ -76,8 +77,8 @@ func (e Exchange) Pairs(exch string, enabledOnly bool, item asset.Item) (*curren
|
||||
}
|
||||
|
||||
// QueryOrder returns details of a valid exchange order
|
||||
func (e Exchange) QueryOrder(exch, orderID string, pair currency.Pair, assetType asset.Item) (*order.Detail, error) {
|
||||
o, err := engine.Bot.OrderManager.GetOrderInfo(exch, orderID, pair, assetType)
|
||||
func (e Exchange) QueryOrder(ctx context.Context, exch, orderID string, pair currency.Pair, assetType asset.Item) (*order.Detail, error) {
|
||||
o, err := engine.Bot.OrderManager.GetOrderInfo(ctx, exch, orderID, pair, assetType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -86,8 +87,8 @@ func (e Exchange) QueryOrder(exch, orderID string, pair currency.Pair, assetType
|
||||
}
|
||||
|
||||
// SubmitOrder submit new order on exchange
|
||||
func (e Exchange) SubmitOrder(submit *order.Submit) (*order.SubmitResponse, error) {
|
||||
r, err := engine.Bot.OrderManager.Submit(submit)
|
||||
func (e Exchange) SubmitOrder(ctx context.Context, submit *order.Submit) (*order.SubmitResponse, error) {
|
||||
r, err := engine.Bot.OrderManager.Submit(ctx, submit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -96,8 +97,8 @@ func (e Exchange) SubmitOrder(submit *order.Submit) (*order.SubmitResponse, erro
|
||||
}
|
||||
|
||||
// CancelOrder wrapper to cancel order on exchange
|
||||
func (e Exchange) CancelOrder(exch, orderID string, cp currency.Pair, a asset.Item) (bool, error) {
|
||||
orderDetails, err := e.QueryOrder(exch, orderID, cp, a)
|
||||
func (e Exchange) CancelOrder(ctx context.Context, exch, orderID string, cp currency.Pair, a asset.Item) (bool, error) {
|
||||
orderDetails, err := e.QueryOrder(ctx, exch, orderID, cp, a)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -111,7 +112,7 @@ func (e Exchange) CancelOrder(exch, orderID string, cp currency.Pair, a asset.It
|
||||
Exchange: exch,
|
||||
}
|
||||
|
||||
err = engine.Bot.OrderManager.Cancel(cancel)
|
||||
err = engine.Bot.OrderManager.Cancel(ctx, cancel)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -119,13 +120,13 @@ func (e Exchange) CancelOrder(exch, orderID string, cp currency.Pair, a asset.It
|
||||
}
|
||||
|
||||
// AccountInformation returns account information (balance etc) for requested exchange
|
||||
func (e Exchange) AccountInformation(exch string, assetType asset.Item) (account.Holdings, error) {
|
||||
func (e Exchange) AccountInformation(ctx context.Context, exch string, assetType asset.Item) (account.Holdings, error) {
|
||||
ex, err := e.GetExchange(exch)
|
||||
if err != nil {
|
||||
return account.Holdings{}, err
|
||||
}
|
||||
|
||||
accountInfo, err := ex.FetchAccountInfo(assetType)
|
||||
accountInfo, err := ex.FetchAccountInfo(ctx, assetType)
|
||||
if err != nil {
|
||||
return account.Holdings{}, err
|
||||
}
|
||||
@@ -136,14 +137,13 @@ func (e Exchange) AccountInformation(exch string, assetType asset.Item) (account
|
||||
// DepositAddress gets the address required to deposit funds for currency type
|
||||
func (e Exchange) DepositAddress(exch string, currencyCode currency.Code) (out string, err error) {
|
||||
if currencyCode.IsEmpty() {
|
||||
err = errors.New("currency code is empty")
|
||||
return
|
||||
return "", errors.New("currency code is empty")
|
||||
}
|
||||
return engine.Bot.DepositAddressManager.GetDepositAddressByExchangeAndCurrency(exch, currencyCode)
|
||||
}
|
||||
|
||||
// WithdrawalFiatFunds withdraw funds from exchange to requested fiat source
|
||||
func (e Exchange) WithdrawalFiatFunds(bankAccountID string, request *withdraw.Request) (string, error) {
|
||||
func (e Exchange) WithdrawalFiatFunds(ctx context.Context, bankAccountID string, request *withdraw.Request) (string, error) {
|
||||
ex, err := e.GetExchange(request.Exchange)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -176,7 +176,7 @@ func (e Exchange) WithdrawalFiatFunds(bankAccountID string, request *withdraw.Re
|
||||
request.Fiat.Bank.SWIFTCode = v.SWIFTCode
|
||||
request.Fiat.Bank.IBAN = v.IBAN
|
||||
|
||||
resp, err := engine.Bot.WithdrawManager.SubmitWithdrawal(request)
|
||||
resp, err := engine.Bot.WithdrawManager.SubmitWithdrawal(ctx, request)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -184,7 +184,7 @@ func (e Exchange) WithdrawalFiatFunds(bankAccountID string, request *withdraw.Re
|
||||
}
|
||||
|
||||
// WithdrawalCryptoFunds withdraw funds from exchange to requested Crypto source
|
||||
func (e Exchange) WithdrawalCryptoFunds(request *withdraw.Request) (string, error) {
|
||||
func (e Exchange) WithdrawalCryptoFunds(ctx context.Context, request *withdraw.Request) (string, error) {
|
||||
// Checks if exchange is enabled or not so we don't call OTP generation
|
||||
_, err := e.GetExchange(request.Exchange)
|
||||
if err != nil {
|
||||
@@ -199,7 +199,7 @@ func (e Exchange) WithdrawalCryptoFunds(request *withdraw.Request) (string, erro
|
||||
request.OneTimePassword = v
|
||||
}
|
||||
|
||||
resp, err := engine.Bot.WithdrawManager.SubmitWithdrawal(request)
|
||||
resp, err := engine.Bot.WithdrawManager.SubmitWithdrawal(ctx, request)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -207,12 +207,12 @@ func (e Exchange) WithdrawalCryptoFunds(request *withdraw.Request) (string, erro
|
||||
}
|
||||
|
||||
// OHLCV returns open high low close volume candles for requested exchange/pair/asset/start & end time
|
||||
func (e Exchange) OHLCV(exch string, pair currency.Pair, item asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
|
||||
func (e Exchange) OHLCV(ctx context.Context, exch string, pair currency.Pair, item asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
|
||||
ex, err := e.GetExchange(exch)
|
||||
if err != nil {
|
||||
return kline.Item{}, err
|
||||
}
|
||||
ret, err := ex.GetHistoricCandlesExtended(pair, item, start, end, interval)
|
||||
ret, err := ex.GetHistoricCandlesExtended(ctx, pair, item, start, end, interval)
|
||||
if err != nil {
|
||||
return kline.Item{}, err
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package exchange
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -95,7 +96,7 @@ func TestExchange_Ticker(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = exchangeTest.Ticker(exchName, c, assetType)
|
||||
_, err = exchangeTest.Ticker(context.Background(), exchName, c, assetType)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -107,7 +108,7 @@ func TestExchange_Orderbook(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = exchangeTest.Orderbook(exchName, c, assetType)
|
||||
_, err = exchangeTest.Orderbook(context.Background(), exchName, c, assetType)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -129,7 +130,8 @@ func TestExchange_AccountInformation(t *testing.T) {
|
||||
if !configureExchangeKeys() {
|
||||
t.Skip("no exchange configured test skipped")
|
||||
}
|
||||
_, err := exchangeTest.AccountInformation(exchName, asset.Spot)
|
||||
_, err := exchangeTest.AccountInformation(context.Background(),
|
||||
exchName, asset.Spot)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -140,7 +142,8 @@ func TestExchange_QueryOrder(t *testing.T) {
|
||||
t.Skip("no exchange configured test skipped")
|
||||
}
|
||||
t.Parallel()
|
||||
_, err := exchangeTest.QueryOrder(exchName, orderID, currency.Pair{}, assetType)
|
||||
_, err := exchangeTest.QueryOrder(context.Background(),
|
||||
exchName, orderID, currency.Pair{}, assetType)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -168,7 +171,7 @@ func TestExchange_SubmitOrder(t *testing.T) {
|
||||
Exchange: exchName,
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
_, err = exchangeTest.SubmitOrder(tempOrder)
|
||||
_, err = exchangeTest.SubmitOrder(context.Background(), tempOrder)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -181,7 +184,8 @@ func TestExchange_CancelOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
cp := currency.NewPair(currency.BTC, currency.USD)
|
||||
a := asset.Spot
|
||||
_, err := exchangeTest.CancelOrder(exchName, orderID, cp, a)
|
||||
_, err := exchangeTest.CancelOrder(context.Background(),
|
||||
exchName, orderID, cp, a)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -191,7 +195,7 @@ func TestOHLCV(t *testing.T) {
|
||||
t.Parallel()
|
||||
cp := currency.NewPair(currency.BTC, currency.AUD)
|
||||
cp.Delimiter = currency.DashDelimiter
|
||||
calvinKline, err := exchangeTest.OHLCV(exchName, cp, assetType, time.Now().Add(-time.Hour*24).UTC(), time.Now().UTC(), kline.OneHour)
|
||||
calvinKline, err := exchangeTest.OHLCV(context.Background(), exchName, cp, assetType, time.Now().Add(-time.Hour*24).UTC(), time.Now().UTC(), kline.OneHour)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package validator
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
@@ -43,7 +44,7 @@ func (w Wrapper) IsEnabled(exch string) (v bool) {
|
||||
}
|
||||
|
||||
// Orderbook validator for test execution/scripts
|
||||
func (w Wrapper) Orderbook(exch string, pair currency.Pair, item asset.Item) (*orderbook.Base, error) {
|
||||
func (w Wrapper) Orderbook(ctx context.Context, exch string, pair currency.Pair, item asset.Item) (*orderbook.Base, error) {
|
||||
if exch == exchError.String() {
|
||||
return nil, errTestFailed
|
||||
}
|
||||
@@ -68,7 +69,7 @@ func (w Wrapper) Orderbook(exch string, pair currency.Pair, item asset.Item) (*o
|
||||
}
|
||||
|
||||
// Ticker validator for test execution/scripts
|
||||
func (w Wrapper) Ticker(exch string, pair currency.Pair, item asset.Item) (*ticker.Price, error) {
|
||||
func (w Wrapper) Ticker(ctx context.Context, exch string, pair currency.Pair, item asset.Item) (*ticker.Price, error) {
|
||||
if exch == exchError.String() {
|
||||
return nil, errTestFailed
|
||||
}
|
||||
@@ -106,7 +107,7 @@ func (w Wrapper) Pairs(exch string, _ bool, _ asset.Item) (*currency.Pairs, erro
|
||||
}
|
||||
|
||||
// QueryOrder validator for test execution/scripts
|
||||
func (w Wrapper) QueryOrder(exch, _ string, _ currency.Pair, _ asset.Item) (*order.Detail, error) {
|
||||
func (w Wrapper) QueryOrder(ctx context.Context, exch, _ string, _ currency.Pair, _ asset.Item) (*order.Detail, error) {
|
||||
if exch == exchError.String() {
|
||||
return nil, errTestFailed
|
||||
}
|
||||
@@ -146,7 +147,7 @@ func (w Wrapper) QueryOrder(exch, _ string, _ currency.Pair, _ asset.Item) (*ord
|
||||
}
|
||||
|
||||
// SubmitOrder validator for test execution/scripts
|
||||
func (w Wrapper) SubmitOrder(o *order.Submit) (*order.SubmitResponse, error) {
|
||||
func (w Wrapper) SubmitOrder(ctx context.Context, o *order.Submit) (*order.SubmitResponse, error) {
|
||||
if o == nil {
|
||||
return nil, errTestFailed
|
||||
}
|
||||
@@ -167,7 +168,7 @@ func (w Wrapper) SubmitOrder(o *order.Submit) (*order.SubmitResponse, error) {
|
||||
}
|
||||
|
||||
// CancelOrder validator for test execution/scripts
|
||||
func (w Wrapper) CancelOrder(exch, orderid string, cp currency.Pair, a asset.Item) (bool, error) {
|
||||
func (w Wrapper) CancelOrder(ctx context.Context, exch, orderid string, cp currency.Pair, a asset.Item) (bool, error) {
|
||||
if exch == exchError.String() {
|
||||
return false, errTestFailed
|
||||
}
|
||||
@@ -184,7 +185,7 @@ func (w Wrapper) CancelOrder(exch, orderid string, cp currency.Pair, a asset.Ite
|
||||
}
|
||||
|
||||
// AccountInformation validator for test execution/scripts
|
||||
func (w Wrapper) AccountInformation(exch string, assetType asset.Item) (account.Holdings, error) {
|
||||
func (w Wrapper) AccountInformation(ctx context.Context, exch string, assetType asset.Item) (account.Holdings, error) {
|
||||
if exch == exchError.String() {
|
||||
return account.Holdings{}, errTestFailed
|
||||
}
|
||||
@@ -224,7 +225,7 @@ func (w Wrapper) DepositAddress(exch string, _ currency.Code) (string, error) {
|
||||
}
|
||||
|
||||
// WithdrawalCryptoFunds validator for test execution/scripts
|
||||
func (w Wrapper) WithdrawalCryptoFunds(r *withdraw.Request) (out string, err error) {
|
||||
func (w Wrapper) WithdrawalCryptoFunds(ctx context.Context, r *withdraw.Request) (out string, err error) {
|
||||
if r.Exchange == exchError.String() {
|
||||
return r.Exchange, errTestFailed
|
||||
}
|
||||
@@ -233,7 +234,7 @@ func (w Wrapper) WithdrawalCryptoFunds(r *withdraw.Request) (out string, err err
|
||||
}
|
||||
|
||||
// WithdrawalFiatFunds validator for test execution/scripts
|
||||
func (w Wrapper) WithdrawalFiatFunds(_ string, r *withdraw.Request) (out string, err error) {
|
||||
func (w Wrapper) WithdrawalFiatFunds(ctx context.Context, _ string, r *withdraw.Request) (out string, err error) {
|
||||
if r.Exchange == exchError.String() {
|
||||
return r.Exchange, errTestFailed
|
||||
}
|
||||
@@ -242,7 +243,7 @@ func (w Wrapper) WithdrawalFiatFunds(_ string, r *withdraw.Request) (out string,
|
||||
}
|
||||
|
||||
// OHLCV returns open high low close volume candles for requested exchange/pair/asset/start & end time
|
||||
func (w Wrapper) OHLCV(exch string, p currency.Pair, a asset.Item, start, end time.Time, i kline.Interval) (kline.Item, error) {
|
||||
func (w Wrapper) OHLCV(ctx context.Context, exch string, p currency.Pair, a asset.Item, start, end time.Time, i kline.Interval) (kline.Item, error) {
|
||||
if exch == exchError.String() {
|
||||
return kline.Item{}, errTestFailed
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package validator
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -63,12 +64,14 @@ func TestWrapper_IsEnabled(t *testing.T) {
|
||||
func TestWrapper_AccountInformation(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
_, err := testWrapper.AccountInformation(exchName, asset.Spot)
|
||||
_, err := testWrapper.AccountInformation(context.Background(),
|
||||
exchName, asset.Spot)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = testWrapper.AccountInformation(exchError.String(), asset.Spot)
|
||||
_, err = testWrapper.AccountInformation(context.Background(),
|
||||
exchError.String(), asset.Spot)
|
||||
if err == nil {
|
||||
t.Fatal("expected AccountInformation to return error on invalid name")
|
||||
}
|
||||
@@ -77,27 +80,32 @@ func TestWrapper_AccountInformation(t *testing.T) {
|
||||
func TestWrapper_CancelOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
cp := currency.NewPair(currency.BTC, currency.USD)
|
||||
_, err := testWrapper.CancelOrder(exchName, orderID, cp, assetType)
|
||||
_, err := testWrapper.CancelOrder(context.Background(),
|
||||
exchName, orderID, cp, assetType)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
_, err = testWrapper.CancelOrder(exchError.String(), orderID, cp, assetType)
|
||||
_, err = testWrapper.CancelOrder(context.Background(),
|
||||
exchError.String(), orderID, cp, assetType)
|
||||
if err == nil {
|
||||
t.Error("expected CancelOrder to return error on invalid name")
|
||||
}
|
||||
|
||||
_, err = testWrapper.CancelOrder(exchName, "", cp, assetType)
|
||||
_, err = testWrapper.CancelOrder(context.Background(),
|
||||
exchName, "", cp, assetType)
|
||||
if err == nil {
|
||||
t.Error("expected CancelOrder to return error on invalid name")
|
||||
}
|
||||
|
||||
_, err = testWrapper.CancelOrder(exchName, orderID, currency.Pair{}, assetType)
|
||||
_, err = testWrapper.CancelOrder(context.Background(),
|
||||
exchName, orderID, currency.Pair{}, assetType)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
_, err = testWrapper.CancelOrder(exchName, orderID, cp, "")
|
||||
_, err = testWrapper.CancelOrder(context.Background(),
|
||||
exchName, orderID, cp, "")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -121,12 +129,14 @@ func TestWrapper_Orderbook(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = testWrapper.Orderbook(exchName, c, assetType)
|
||||
_, err = testWrapper.Orderbook(context.Background(),
|
||||
exchName, c, assetType)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = testWrapper.Orderbook(exchError.String(), currencyPair, asset.Spot)
|
||||
_, err = testWrapper.Orderbook(context.Background(),
|
||||
exchError.String(), currencyPair, asset.Spot)
|
||||
if err == nil {
|
||||
t.Fatal("expected Orderbook to return error with invalid name")
|
||||
}
|
||||
@@ -152,12 +162,14 @@ func TestWrapper_Pairs(t *testing.T) {
|
||||
func TestWrapper_QueryOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
_, err := testWrapper.QueryOrder(exchName, orderID, currency.Pair{}, assetType)
|
||||
_, err := testWrapper.QueryOrder(context.Background(),
|
||||
exchName, orderID, currency.Pair{}, assetType)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = testWrapper.QueryOrder(exchError.String(), "", currency.Pair{}, assetType)
|
||||
_, err = testWrapper.QueryOrder(context.Background(),
|
||||
exchError.String(), "", currency.Pair{}, assetType)
|
||||
if err == nil {
|
||||
t.Fatal("expected QueryOrder to return error on invalid name")
|
||||
}
|
||||
@@ -181,12 +193,12 @@ func TestWrapper_SubmitOrder(t *testing.T) {
|
||||
Exchange: "true",
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
_, err = testWrapper.SubmitOrder(tempOrder)
|
||||
_, err = testWrapper.SubmitOrder(context.Background(), tempOrder)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = testWrapper.SubmitOrder(nil)
|
||||
_, err = testWrapper.SubmitOrder(context.Background(), nil)
|
||||
if err == nil {
|
||||
t.Fatal("expected SubmitOrder to return error with invalid name")
|
||||
}
|
||||
@@ -198,36 +210,40 @@ func TestWrapper_Ticker(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = testWrapper.Ticker(exchName, c, assetType)
|
||||
_, err = testWrapper.Ticker(context.Background(), exchName, c, assetType)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = testWrapper.Ticker(exchError.String(), currencyPair, asset.Spot)
|
||||
_, err = testWrapper.Ticker(context.Background(), exchError.String(), currencyPair, asset.Spot)
|
||||
if err == nil {
|
||||
t.Fatal("expected Ticker to return error with invalid name")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWrapper_WithdrawalCryptoFunds(t *testing.T) {
|
||||
_, err := testWrapper.WithdrawalCryptoFunds(&withdraw.Request{Exchange: exchError.String()})
|
||||
_, err := testWrapper.WithdrawalCryptoFunds(context.Background(),
|
||||
&withdraw.Request{Exchange: exchError.String()})
|
||||
if err == nil {
|
||||
t.Fatal("expected WithdrawalCryptoFunds to return error with invalid name")
|
||||
}
|
||||
|
||||
_, err = testWrapper.WithdrawalCryptoFunds(&withdraw.Request{Exchange: exchName})
|
||||
_, err = testWrapper.WithdrawalCryptoFunds(context.Background(),
|
||||
&withdraw.Request{Exchange: exchName})
|
||||
if err != nil {
|
||||
t.Fatal("expected WithdrawalCryptoFunds to return error with invalid name")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWrapper_WithdrawalFiatFunds(t *testing.T) {
|
||||
_, err := testWrapper.WithdrawalFiatFunds("", &withdraw.Request{Exchange: exchError.String()})
|
||||
_, err := testWrapper.WithdrawalFiatFunds(context.Background(),
|
||||
"", &withdraw.Request{Exchange: exchError.String()})
|
||||
if err == nil {
|
||||
t.Fatal("expected WithdrawalFiatFunds to return error with invalid name")
|
||||
}
|
||||
|
||||
_, err = testWrapper.WithdrawalFiatFunds("", &withdraw.Request{Exchange: exchName})
|
||||
_, err = testWrapper.WithdrawalFiatFunds(context.Background(),
|
||||
"", &withdraw.Request{Exchange: exchName})
|
||||
if err != nil {
|
||||
t.Fatal("expected WithdrawalCryptoFunds to return error with invalid name")
|
||||
}
|
||||
@@ -238,11 +254,15 @@ func TestWrapper_OHLCV(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = testWrapper.OHLCV("test", c, asset.Spot, time.Now().Add(-24*time.Hour), time.Now(), kline.OneDay)
|
||||
_, err = testWrapper.OHLCV(context.Background(),
|
||||
"test", c, asset.Spot, time.Now().Add(-24*time.Hour), time.Now(), kline.OneDay)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = testWrapper.OHLCV(exchError.String(), c, asset.Spot, time.Now().Add(-24*time.Hour), time.Now(), kline.OneDay)
|
||||
_, err = testWrapper.OHLCV(context.Background(),
|
||||
exchError.String(), c, asset.Spot,
|
||||
time.Now().Add(-24*time.Hour),
|
||||
time.Now(), kline.OneDay)
|
||||
if err == nil {
|
||||
t.Fatal("expected OHLCV to return error with invalid name")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user