mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-29 15:10:37 +00:00
* init * surprise train commit * basic distinctions * the terms of binance are confusing * renames and introduction of allocatedMargin * add new margin funcs * pulling out wires * implement proper getposition stuff * bad coding day * investigate order manager next * a broken mess, but a progressing one * finally completes some usdtmargined stuff * coinMfutures eludes me * expand to okx * imports fix * completes okx wrapper implementations * cleans and polishes before rpc implementations * rpc setup, order manager features, exch features * more rpc, collateral and margin things * mini test * looking at rpc response, expansion of features * reorganising before the storm * changing how futures requests work * cleanup and tests of cli usage * remove silly client side logic * cleanup * collateral package, typo fix, margin err, rpc derive * uses convert.StringToFloat ONLY ON STRUCTS FROM THIS PR * fix binance order history bug * niteroos * adds new funcs to exchange standards testing * more post merge fixes * fix binance * replace simepletimeformat * fix for merge * merge fixes * micro fixes * order side now required for leverage * fix up the rest * global -> portfolio collateral * Update exchanges/collateral/collateral_test.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> * adds fields and todos * rm field redundancy * lint fix oopsie daisy * fixes panic, expands error and cli explanations (sorry shaz) * ensures casing is appropriate for underlying * Adds a shiny TODO --------- Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
86 lines
2.6 KiB
Go
86 lines
2.6 KiB
Go
package live
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/thrasher-corp/gocryptotrader/backtester/common"
|
|
"github.com/thrasher-corp/gocryptotrader/common/convert"
|
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
|
"github.com/thrasher-corp/gocryptotrader/engine"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
|
gctkline "github.com/thrasher-corp/gocryptotrader/exchanges/kline"
|
|
)
|
|
|
|
const testExchange = "okx"
|
|
|
|
func TestLoadCandles(t *testing.T) {
|
|
t.Parallel()
|
|
interval := gctkline.OneHour
|
|
cp := currency.NewPair(currency.BTC, currency.USDT)
|
|
a := asset.Spot
|
|
em := engine.NewExchangeManager()
|
|
exch, err := em.NewExchangeByName(testExchange)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
pFormat := ¤cy.PairFormat{Uppercase: true}
|
|
b := exch.GetBase()
|
|
exch.SetDefaults()
|
|
b.CurrencyPairs.Pairs = make(map[asset.Item]*currency.PairStore)
|
|
b.CurrencyPairs.Pairs[asset.Spot] = ¤cy.PairStore{
|
|
Available: currency.Pairs{cp},
|
|
Enabled: currency.Pairs{cp},
|
|
AssetEnabled: convert.BoolPtr(true),
|
|
RequestFormat: pFormat,
|
|
ConfigFormat: pFormat,
|
|
}
|
|
var data *gctkline.Item
|
|
data, err = LoadData(context.Background(), time.Now().Add(-interval.Duration()*10), exch, common.DataCandle, interval.Duration(), cp, currency.EMPTYPAIR, a, true)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(data.Candles) == 0 {
|
|
t.Error("expected candles")
|
|
}
|
|
_, err = LoadData(context.Background(), time.Now(), exch, -1, interval.Duration(), cp, currency.EMPTYPAIR, a, true)
|
|
if !errors.Is(err, common.ErrInvalidDataType) {
|
|
t.Errorf("received: %v, expected: %v", err, common.ErrInvalidDataType)
|
|
}
|
|
}
|
|
|
|
func TestLoadTrades(t *testing.T) {
|
|
t.Parallel()
|
|
interval := gctkline.OneMin
|
|
cp := currency.NewPair(currency.BTC, currency.USDT)
|
|
a := asset.Spot
|
|
em := engine.NewExchangeManager()
|
|
exch, err := em.NewExchangeByName(testExchange)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
pFormat := ¤cy.PairFormat{Uppercase: true}
|
|
b := exch.GetBase()
|
|
exch.SetDefaults()
|
|
b.CurrencyPairs.Pairs = make(map[asset.Item]*currency.PairStore)
|
|
b.CurrencyPairs.Pairs[asset.Spot] = ¤cy.PairStore{
|
|
Available: currency.Pairs{cp},
|
|
Enabled: currency.Pairs{cp},
|
|
AssetEnabled: convert.BoolPtr(true),
|
|
RequestFormat: pFormat,
|
|
ConfigFormat: pFormat,
|
|
}
|
|
var data *gctkline.Item
|
|
// start is 10 mins in the past to ensure there are some trades to pull from the exchange
|
|
start := time.Now().Add(-time.Minute * 10)
|
|
data, err = LoadData(context.Background(), start, exch, common.DataTrade, interval.Duration(), cp, currency.EMPTYPAIR, a, true)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(data.Candles) == 0 {
|
|
t.Error("expected candles")
|
|
}
|
|
}
|