mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-16 07:26:47 +00:00
* 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
263 lines
6.0 KiB
Go
263 lines
6.0 KiB
Go
package validator
|
|
|
|
import (
|
|
"math/rand"
|
|
"time"
|
|
|
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/account"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/kline"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
|
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
|
)
|
|
|
|
const (
|
|
validatorOpen float64 = 5000
|
|
validatorHigh float64 = 6000
|
|
validatorLow float64 = 5500
|
|
validatorClose float64 = 5700
|
|
validatorVol float64 = 10
|
|
)
|
|
|
|
// Exchanges validator for test execution/scripts
|
|
func (w Wrapper) Exchanges(enabledOnly bool) []string {
|
|
if enabledOnly {
|
|
return []string{
|
|
"hello world",
|
|
}
|
|
}
|
|
return []string{
|
|
"nope",
|
|
}
|
|
}
|
|
|
|
// IsEnabled returns if requested exchange is enabled or disabled
|
|
func (w Wrapper) IsEnabled(exch string) (v bool) {
|
|
if exch == exchError.String() {
|
|
return
|
|
}
|
|
return true
|
|
}
|
|
|
|
// Orderbook validator for test execution/scripts
|
|
func (w Wrapper) Orderbook(exch string, pair currency.Pair, item asset.Item) (*orderbook.Base, error) {
|
|
if exch == exchError.String() {
|
|
return nil, errTestFailed
|
|
}
|
|
|
|
return &orderbook.Base{
|
|
ExchangeName: exch,
|
|
AssetType: item,
|
|
Pair: pair,
|
|
Bids: []orderbook.Item{
|
|
{
|
|
Amount: 1,
|
|
Price: 1,
|
|
},
|
|
},
|
|
Asks: []orderbook.Item{
|
|
{
|
|
Amount: 1,
|
|
Price: 1,
|
|
},
|
|
},
|
|
}, nil
|
|
}
|
|
|
|
// Ticker validator for test execution/scripts
|
|
func (w Wrapper) Ticker(exch string, pair currency.Pair, item asset.Item) (*ticker.Price, error) {
|
|
if exch == exchError.String() {
|
|
return nil, errTestFailed
|
|
}
|
|
return &ticker.Price{
|
|
Last: 1,
|
|
High: 2,
|
|
Low: 3,
|
|
Bid: 4,
|
|
Ask: 5,
|
|
Volume: 6,
|
|
QuoteVolume: 7,
|
|
PriceATH: 8,
|
|
Open: 9,
|
|
Close: 10,
|
|
Pair: pair,
|
|
ExchangeName: exch,
|
|
AssetType: item,
|
|
LastUpdated: time.Now(),
|
|
}, nil
|
|
}
|
|
|
|
// Pairs validator for test execution/scripts
|
|
func (w Wrapper) Pairs(exch string, _ bool, _ asset.Item) (*currency.Pairs, error) {
|
|
if exch == exchError.String() {
|
|
return nil, errTestFailed
|
|
}
|
|
|
|
pairs := currency.NewPairsFromStrings([]string{"btc_usd", "btc_aud", "btc_ltc"})
|
|
return &pairs, nil
|
|
}
|
|
|
|
// QueryOrder validator for test execution/scripts
|
|
func (w Wrapper) QueryOrder(exch, _ string) (*order.Detail, error) {
|
|
if exch == exchError.String() {
|
|
return nil, errTestFailed
|
|
}
|
|
return &order.Detail{
|
|
Exchange: exch,
|
|
AccountID: "hello",
|
|
ID: "1",
|
|
Pair: currency.NewPairFromString("BTCAUD"),
|
|
Side: "ask",
|
|
Type: "limit",
|
|
Date: time.Now(),
|
|
Status: "cancelled",
|
|
Price: 1,
|
|
Amount: 2,
|
|
ExecutedAmount: 1,
|
|
RemainingAmount: 0,
|
|
Fee: 0,
|
|
Trades: []order.TradeHistory{
|
|
{
|
|
Timestamp: time.Now(),
|
|
TID: "",
|
|
Price: 1,
|
|
Amount: 2,
|
|
Exchange: exch,
|
|
Type: "limit",
|
|
Side: "ask",
|
|
Fee: 0,
|
|
Description: "",
|
|
},
|
|
},
|
|
}, nil
|
|
}
|
|
|
|
// SubmitOrder validator for test execution/scripts
|
|
func (w Wrapper) SubmitOrder(o *order.Submit) (*order.SubmitResponse, error) {
|
|
if o == nil {
|
|
return nil, errTestFailed
|
|
}
|
|
if o.Exchange == exchError.String() {
|
|
return nil, errTestFailed
|
|
}
|
|
|
|
tempOrder := &order.SubmitResponse{
|
|
IsOrderPlaced: false,
|
|
OrderID: o.Exchange,
|
|
}
|
|
|
|
if o.Exchange == "true" {
|
|
tempOrder.IsOrderPlaced = true
|
|
}
|
|
|
|
return tempOrder, nil
|
|
}
|
|
|
|
// CancelOrder validator for test execution/scripts
|
|
func (w Wrapper) CancelOrder(exch, orderid string) (bool, error) {
|
|
if exch == exchError.String() {
|
|
return false, errTestFailed
|
|
}
|
|
return orderid != "false", nil
|
|
}
|
|
|
|
// AccountInformation validator for test execution/scripts
|
|
func (w Wrapper) AccountInformation(exch string) (account.Holdings, error) {
|
|
if exch == exchError.String() {
|
|
return account.Holdings{}, errTestFailed
|
|
}
|
|
|
|
return account.Holdings{
|
|
Exchange: exch,
|
|
Accounts: []account.SubAccount{
|
|
{
|
|
ID: exch,
|
|
Currencies: []account.Balance{
|
|
{
|
|
CurrencyName: currency.Code{
|
|
Item: ¤cy.Item{
|
|
ID: 0,
|
|
FullName: "Bitcoin",
|
|
Symbol: "BTC",
|
|
Role: 1,
|
|
AssocChain: "",
|
|
AssocExchange: nil,
|
|
},
|
|
},
|
|
TotalValue: 100,
|
|
Hold: 0,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}, nil
|
|
}
|
|
|
|
// DepositAddress validator for test execution/scripts
|
|
func (w Wrapper) DepositAddress(exch string, _ currency.Code) (string, error) {
|
|
if exch == exchError.String() {
|
|
return exch, errTestFailed
|
|
}
|
|
|
|
return exch, nil
|
|
}
|
|
|
|
// WithdrawalCryptoFunds validator for test execution/scripts
|
|
func (w Wrapper) WithdrawalCryptoFunds(exch string, _ *withdraw.Request) (out string, err error) {
|
|
if exch == exchError.String() {
|
|
return exch, errTestFailed
|
|
}
|
|
|
|
return "", nil
|
|
}
|
|
|
|
// WithdrawalFiatFunds validator for test execution/scripts
|
|
func (w Wrapper) WithdrawalFiatFunds(exch, _ string, _ *withdraw.Request) (out string, err error) {
|
|
if exch == exchError.String() {
|
|
return exch, errTestFailed
|
|
}
|
|
|
|
return "123", nil
|
|
}
|
|
|
|
// 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 time.Duration) (kline.Item, error) {
|
|
if exch == exchError.String() {
|
|
return kline.Item{}, errTestFailed
|
|
}
|
|
var candles []kline.Candle
|
|
|
|
candles = append(candles, kline.Candle{
|
|
Time: start,
|
|
Open: validatorOpen,
|
|
High: validatorHigh,
|
|
Low: validatorLow,
|
|
Close: validatorClose,
|
|
Volume: validatorVol,
|
|
})
|
|
|
|
for x := 1; x < 200; x++ {
|
|
r := validatorLow + rand.Float64()*(validatorHigh-validatorLow)
|
|
candle := kline.Candle{
|
|
Time: candles[x-1].Time.Add(-i),
|
|
Open: r,
|
|
High: r,
|
|
Low: r,
|
|
Close: r,
|
|
Volume: r,
|
|
}
|
|
candles = append(candles, candle)
|
|
}
|
|
|
|
return kline.Item{
|
|
Exchange: exch,
|
|
Pair: p,
|
|
Asset: a,
|
|
Interval: i,
|
|
Candles: candles,
|
|
}, nil
|
|
}
|