Files
gocryptotrader/gctscript/wrappers/validator/validator_test.go
Andrew 70615279bd (GCTScript) Add technical analysis support via script bindings (#467)
* added mfi and example

* renamed to moving average

* converted to array return type and added obv and mfi

* started work on test coverage

* test coverage added for rsi & mfi

* test coverage added for all indicators removed go mod replace moved to append helper method

* moved all indicators to new appendTo and increased test coverage

* added additional test and bumped go-talib to latest commi

* go.mod update

* linter fixes

* go mod clean up

* small fixes

* reverted changes from previous attempt to rework as data is still incorrect now passing full OHLCV data back to script binding

* testing new structure of passing full ohlcv data

* started linking ohlcv to gctscript

* OHCLV link up completed reworking passing back to indicators started

* OHCLV link up completed reworking passing back to indicators started

* added test coverage for tofloat

* linter fixes (gofmt)

* removed unused value

* improved test coverage

* added correct detection for 1w added ParseInterval test coverage moved OHCLV string to const

* removed unused value

* first round of changes addressed

* all indicators have been split with packages named after each indicator and a new calculate() method added

* linters

* fixed tests

* added check to check ta is running in validator for uploading

* Added test data for OHLCV testing new indicator interface for wrapper

* typed const to float64

* reworked validator data to generate previous timestamps

* rewored macd to return slice of array

* adding bbands linking and example

* why didn't this pick it up before :D

* bumped up total number of modules for test

* moved parseIndicator to exchange added comments

* test coverage added for ParseMAType & ParseIndicatorSelector

* gofmt

* WIP changes

* updated tests for bbands  & obv bumped to latest go-talib

* move multiple use strong to const

* reverted rpc.pb.go to master

* added 4w option

* removed selector from obv as unneeded

* improved test coverage and reworked all indicator methods on how they pass errors back

* order incoming OHCLV data

* revert go.mod

* removed verbose toggles

* added spot asset type

* removed 4w as its unused/uncommon

* renamed

* reworked further tests

* converted all examples to use coinbasepro for consistency

* updated all date ranges to 2019 + 6 months

* backported binance OHLCV wrapper from #479

* removed o

* rounded numbers

* chnage requests addressed and attempt to fix MACD... today has been really unproctive code wise :D

* Migrated to gct-ta library

* Corrected test import

* wording changes on test

* removed TA lib from go.mod

* PR changes addressed

Removed parallel running from tests due to slight possibility in very extreme cases TestExecution might not be set to the expected value and will cause lower test coverage

* removed pkg folder

* bumped gct-ta version

* gct-ta version bump
2020-04-24 15:36:49 +10:00

221 lines
5.3 KiB
Go

package validator
import (
"testing"
"time"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
"github.com/thrasher-corp/gocryptotrader/exchanges/kline"
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
)
const (
exchName = "BTC Markets" // change to test on another exchange
exchAPIKEY = ""
exchAPISECRET = ""
exchClientID = ""
pairs = "BTC-AUD" // change to test another currency pair
delimiter = "-"
assetType = asset.Spot
orderID = "1234"
orderType = order.Limit
orderSide = order.Buy
orderClientID = ""
orderPrice = 1
orderAmount = 1
)
var (
currencyPair = currency.NewPairFromString("BTCAUD")
testWrapper = Wrapper{}
)
func TestWrapper_Exchanges(t *testing.T) {
t.Parallel()
x := testWrapper.Exchanges(false)
y := len(x)
if y != 1 {
t.Fatalf("expected 1 received %v", y)
}
x = testWrapper.Exchanges(true)
y = len(x)
if y != 1 {
t.Fatalf("expected 1 received %v", y)
}
}
func TestWrapper_IsEnabled(t *testing.T) {
t.Parallel()
f := testWrapper.IsEnabled("hello")
if !f {
t.Fatal("expected IsEnabled to return true for enabled exchange")
}
f = testWrapper.IsEnabled(exchError.String())
if f {
t.Fatal("expected IsEnabled to return false for disabled exchange")
}
}
func TestWrapper_AccountInformation(t *testing.T) {
t.Parallel()
_, err := testWrapper.AccountInformation(exchName)
if err != nil {
t.Fatal(err)
}
_, err = testWrapper.AccountInformation(exchError.String())
if err == nil {
t.Fatal("expected AccountInformation to return error on invalid name")
}
}
func TestWrapper_CancelOrder(t *testing.T) {
t.Parallel()
_, err := testWrapper.CancelOrder(exchName, orderID)
if err != nil {
t.Fatal(err)
}
_, err = testWrapper.CancelOrder(exchError.String(), "")
if err == nil {
t.Fatal("expected CancelOrder to return error on invalid name")
}
}
func TestWrapper_DepositAddress(t *testing.T) {
_, err := testWrapper.DepositAddress(exchError.String(), currency.NewCode("BTC"))
if err == nil {
t.Fatal("expected DepositAddress to return error on invalid name")
}
_, err = testWrapper.DepositAddress(exchName, currency.NewCode("BTC"))
if err != nil {
t.Fatal(err)
}
}
func TestWrapper_Orderbook(t *testing.T) {
t.Parallel()
c := currency.NewPairDelimiter(pairs, delimiter)
_, err := testWrapper.Orderbook(exchName, c, assetType)
if err != nil {
t.Fatal(err)
}
_, err = testWrapper.Orderbook(exchError.String(), currencyPair, asset.Spot)
if err == nil {
t.Fatal("expected Orderbook to return error with invalid name")
}
}
func TestWrapper_Pairs(t *testing.T) {
t.Parallel()
_, err := testWrapper.Pairs(exchName, false, assetType)
if err != nil {
t.Fatal(err)
}
_, err = testWrapper.Pairs(exchName, true, assetType)
if err != nil {
t.Fatal(err)
}
_, err = testWrapper.Pairs(exchError.String(), false, asset.Spot)
if err == nil {
t.Fatal("expected Pairs to return error on invalid name")
}
}
func TestWrapper_QueryOrder(t *testing.T) {
t.Parallel()
_, err := testWrapper.QueryOrder(exchName, orderID)
if err != nil {
t.Fatal(err)
}
_, err = testWrapper.QueryOrder(exchError.String(), "")
if err == nil {
t.Fatal("expected QueryOrder to return error on invalid name")
}
}
func TestWrapper_SubmitOrder(t *testing.T) {
t.Parallel()
tempOrder := &order.Submit{
Pair: currency.NewPairDelimiter(pairs, delimiter),
Type: orderType,
Side: orderSide,
TriggerPrice: 0,
TargetAmount: 0,
Price: orderPrice,
Amount: orderAmount,
ClientID: orderClientID,
Exchange: "true",
}
_, err := testWrapper.SubmitOrder(tempOrder)
if err != nil {
t.Fatal(err)
}
_, err = testWrapper.SubmitOrder(nil)
if err == nil {
t.Fatal("expected SubmitOrder to return error with invalid name")
}
}
func TestWrapper_Ticker(t *testing.T) {
t.Parallel()
c := currency.NewPairDelimiter(pairs, delimiter)
_, err := testWrapper.Ticker(exchName, c, assetType)
if err != nil {
t.Fatal(err)
}
_, err = testWrapper.Ticker(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(exchError.String(), nil)
if err == nil {
t.Fatal("expected WithdrawalCryptoFunds to return error with invalid name")
}
_, err = testWrapper.WithdrawalCryptoFunds(exchName, nil)
if err != nil {
t.Fatal("expected WithdrawalCryptoFunds to return error with invalid name")
}
}
func TestWrapper_WithdrawalFiatFunds(t *testing.T) {
_, err := testWrapper.WithdrawalFiatFunds(exchError.String(), "", nil)
if err == nil {
t.Fatal("expected WithdrawalFiatFunds to return error with invalid name")
}
_, err = testWrapper.WithdrawalFiatFunds(exchName, "", nil)
if err != nil {
t.Fatal("expected WithdrawalCryptoFunds to return error with invalid name")
}
}
func TestWrapper_OHLCV(t *testing.T) {
c := currency.NewPairDelimiter(pairs, delimiter)
_, err := testWrapper.OHLCV("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)
if err == nil {
t.Fatal("expected OHLCV to return error with invalid name")
}
}