Skip to content

Commit 3f534a1

Browse files
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>
1 parent 485397a commit 3f534a1

File tree

163 files changed

+20454
-20314
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

163 files changed

+20454
-20314
lines changed

backtester/engine/backtest_test.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ func TestReset(t *testing.T) {
418418

419419
func TestFullCycle(t *testing.T) {
420420
t.Parallel()
421-
ex := testExchange
421+
e := testExchange
422422
cp := currency.NewBTCUSDT()
423423
a := asset.Spot
424424
tt := time.Now()
@@ -431,18 +431,18 @@ func TestFullCycle(t *testing.T) {
431431
}, &risk.Risk{}, decimal.Zero)
432432
assert.NoError(t, err)
433433

434-
fx := &binance.Binance{}
434+
fx := &binance.Exchange{}
435435
fx.Name = testExchange
436436
err = port.SetCurrencySettingsMap(&exchange.Settings{Exchange: fx, Asset: a, Pair: cp})
437437
assert.NoError(t, err)
438438

439439
f, err := funding.SetupFundingManager(&engine.ExchangeManager{}, false, true, false)
440440
assert.NoError(t, err)
441441

442-
b, err := funding.CreateItem(ex, a, cp.Base, decimal.Zero, decimal.Zero)
442+
b, err := funding.CreateItem(e, a, cp.Base, decimal.Zero, decimal.Zero)
443443
assert.NoError(t, err)
444444

445-
quote, err := funding.CreateItem(ex, a, cp.Quote, decimal.NewFromInt(1337), decimal.Zero)
445+
quote, err := funding.CreateItem(e, a, cp.Quote, decimal.NewFromInt(1337), decimal.Zero)
446446
assert.NoError(t, err)
447447

448448
pair, err := funding.CreatePair(b, quote)
@@ -467,7 +467,7 @@ func TestFullCycle(t *testing.T) {
467467
bt.DataHolder = data.NewHandlerHolder()
468468
k := &kline.DataFromKline{
469469
Item: &gctkline.Item{
470-
Exchange: ex,
470+
Exchange: e,
471471
Pair: cp,
472472
Asset: a,
473473
Interval: gctkline.FifteenMin,
@@ -502,7 +502,7 @@ func TestFullCycle(t *testing.T) {
502502
err = k.Load()
503503
assert.NoError(t, err)
504504

505-
err = bt.DataHolder.SetDataForCurrency(ex, a, cp, k)
505+
err = bt.DataHolder.SetDataForCurrency(e, a, cp, k)
506506
assert.NoError(t, err)
507507

508508
bt.MetaData.DateLoaded = time.Now()
@@ -536,7 +536,7 @@ func TestStop(t *testing.T) {
536536

537537
func TestFullCycleMulti(t *testing.T) {
538538
t.Parallel()
539-
ex := testExchange
539+
e := testExchange
540540
cp := currency.NewBTCUSDT()
541541
a := asset.Spot
542542
tt := time.Now()
@@ -550,16 +550,16 @@ func TestFullCycleMulti(t *testing.T) {
550550
}, &risk.Risk{}, decimal.Zero)
551551
assert.NoError(t, err)
552552

553-
err = port.SetCurrencySettingsMap(&exchange.Settings{Exchange: &binance.Binance{}, Asset: a, Pair: cp})
553+
err = port.SetCurrencySettingsMap(&exchange.Settings{Exchange: &binance.Exchange{}, Asset: a, Pair: cp})
554554
assert.NoError(t, err)
555555

556556
f, err := funding.SetupFundingManager(&engine.ExchangeManager{}, false, true, false)
557557
assert.NoError(t, err)
558558

559-
b, err := funding.CreateItem(ex, a, cp.Base, decimal.Zero, decimal.Zero)
559+
b, err := funding.CreateItem(e, a, cp.Base, decimal.Zero, decimal.Zero)
560560
assert.NoError(t, err)
561561

562-
quote, err := funding.CreateItem(ex, a, cp.Quote, decimal.NewFromInt(1337), decimal.Zero)
562+
quote, err := funding.CreateItem(e, a, cp.Quote, decimal.NewFromInt(1337), decimal.Zero)
563563
assert.NoError(t, err)
564564

565565
pair, err := funding.CreatePair(b, quote)
@@ -586,7 +586,7 @@ func TestFullCycleMulti(t *testing.T) {
586586
bt.DataHolder = data.NewHandlerHolder()
587587
k := &kline.DataFromKline{
588588
Item: &gctkline.Item{
589-
Exchange: ex,
589+
Exchange: e,
590590
Pair: cp,
591591
Asset: a,
592592
Interval: gctkline.FifteenMin,
@@ -621,7 +621,7 @@ func TestFullCycleMulti(t *testing.T) {
621621
err = k.Load()
622622
assert.NoError(t, err)
623623

624-
err = bt.DataHolder.SetDataForCurrency(ex, a, cp, k)
624+
err = bt.DataHolder.SetDataForCurrency(e, a, cp, k)
625625
assert.NoError(t, err)
626626

627627
err = bt.Run()
@@ -762,7 +762,7 @@ func TestUpdateStatsForDataEvent(t *testing.T) {
762762
require.NoError(t, err, "CreateCollateral must not error")
763763

764764
bt.Funding = f
765-
exch := &binance.Binance{}
765+
exch := &binance.Exchange{}
766766
exch.Name = testExchange
767767
ev.Time = time.Now()
768768
fl := &fill.Fill{
@@ -831,7 +831,7 @@ func TestProcessSignalEvent(t *testing.T) {
831831
require.NoError(t, err, "CreateCollateral must not error")
832832

833833
bt.Funding = f
834-
exch := &binance.Binance{}
834+
exch := &binance.Exchange{}
835835
exch.Name = testExchange
836836
bt.Exchange.SetExchangeAssetCurrencySettings(a, cp, &exchange.Settings{
837837
Exchange: exch,
@@ -889,7 +889,7 @@ func TestProcessOrderEvent(t *testing.T) {
889889
require.NoError(t, err, "CreateCollateral must not error")
890890

891891
bt.Funding = f
892-
exch := &binance.Binance{}
892+
exch := &binance.Exchange{}
893893
exch.Name = testExchange
894894
err = pt.SetCurrencySettingsMap(&exchange.Settings{
895895
Exchange: exch,
@@ -1204,7 +1204,7 @@ func TestCloseAllPositions(t *testing.T) {
12041204
dc.funding = bt.Funding
12051205
cp := currency.NewBTCUSD()
12061206
dc.sourcesToCheck = append(dc.sourcesToCheck, &liveDataSourceDataHandler{
1207-
exchange: &binance.Binance{},
1207+
exchange: &binance.Exchange{},
12081208
exchangeName: testExchange,
12091209
asset: asset.Spot,
12101210
pair: cp,
@@ -1285,7 +1285,7 @@ func TestRunLive(t *testing.T) {
12851285
}
12861286
// AppendDataSource(exchange gctexchange.IBotExchange, interval gctkline.Interval, asset asset.Asset, pair, underlyingPair currency.Pair, dataType int64) error
12871287
setup := &liveDataSourceSetup{
1288-
exchange: &binance.Binance{},
1288+
exchange: &binance.Exchange{},
12891289
interval: i.Interval,
12901290
asset: i.Asset,
12911291
pair: i.Pair,
@@ -1373,7 +1373,7 @@ func TestSetExchangeCredentials(t *testing.T) {
13731373
assert.ErrorIs(t, err, gctcommon.ErrNilPointer)
13741374

13751375
cfg := &config.Config{}
1376-
f := &binanceus.Binanceus{}
1376+
f := &binanceus.Exchange{}
13771377
f.SetDefaults()
13781378
b := f.GetBase()
13791379
err = setExchangeCredentials(cfg, b)
@@ -1416,7 +1416,7 @@ func TestGetFees(t *testing.T) {
14161416
_, _, err := getFees(t.Context(), nil, currency.EMPTYPAIR)
14171417
assert.ErrorIs(t, err, gctcommon.ErrNilPointer)
14181418

1419-
f := &binance.Binance{}
1419+
f := &binance.Exchange{}
14201420
f.SetDefaults()
14211421
_, _, err = getFees(t.Context(), f, currency.EMPTYPAIR)
14221422
assert.ErrorIs(t, err, currency.ErrCurrencyPairEmpty)

backtester/engine/live_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func TestAppendDataSource(t *testing.T) {
219219
err = dataHandler.AppendDataSource(setup)
220220
assert.ErrorIs(t, err, gctcommon.ErrNilPointer)
221221

222-
setup.exchange = &binance.Binance{}
222+
setup.exchange = &binance.Exchange{}
223223
err = dataHandler.AppendDataSource(setup)
224224
assert.ErrorIs(t, err, common.ErrInvalidDataType)
225225

@@ -264,7 +264,7 @@ func TestFetchLatestData(t *testing.T) {
264264
_, err = dataHandler.FetchLatestData()
265265
require.NoError(t, err)
266266
cp := currency.NewBTCUSDT()
267-
f := &binanceus.Binanceus{}
267+
f := &binanceus.Exchange{}
268268
f.SetDefaults()
269269
fb := f.GetBase()
270270
require.NoError(t, fb.CurrencyPairs.SetAssetEnabled(asset.Spot, true), "SetAssetEnabled must not error")
@@ -322,7 +322,7 @@ func TestLoadCandleData(t *testing.T) {
322322
_, err := l.loadCandleData(time.Now())
323323
assert.ErrorIs(t, err, gctcommon.ErrNilPointer)
324324

325-
exch := &binanceus.Binanceus{}
325+
exch := &binanceus.Exchange{}
326326
exch.SetDefaults()
327327
cp := currency.NewBTCUSDT().Format(
328328
currency.PairFormat{
@@ -367,7 +367,7 @@ func TestSetDataForClosingAllPositions(t *testing.T) {
367367

368368
dataHandler.started = 1
369369
cp := currency.NewBTCUSDT()
370-
f := &binanceus.Binanceus{}
370+
f := &binanceus.Exchange{}
371371
f.SetDefaults()
372372
fb := f.GetBase()
373373
err := fb.CurrencyPairs.StorePairs(asset.Spot, currency.Pairs{cp}, true)

backtester/eventhandlers/exchange/exchange_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func TestSetCurrency(t *testing.T) {
125125
if len(e.CurrencySettings) != 0 {
126126
t.Error("expected 0")
127127
}
128-
f := &binance.Binance{}
128+
f := &binance.Exchange{}
129129
f.Name = testExchange
130130
cs := &Settings{
131131
Exchange: f,
@@ -240,7 +240,7 @@ func TestExecuteOrder(t *testing.T) {
240240
require.NoError(t, exchB.CurrencyPairs.SetAssetEnabled(a, true), "SetAssetEnabled must not error")
241241
_, err = exch.UpdateOrderbook(t.Context(), p, a)
242242
require.NoError(t, err, "UpdateOrderbook must not error")
243-
f := &binanceus.Binanceus{}
243+
f := &binanceus.Exchange{}
244244
f.Name = testExchange
245245
cs := Settings{
246246
Exchange: f,
@@ -359,7 +359,7 @@ func TestExecuteOrderBuySellSizeLimit(t *testing.T) {
359359
limits, err := exch.GetOrderExecutionLimits(a, p)
360360
require.NoError(t, err, "GetOrderExecutionLimits must not error")
361361

362-
f := &btcmarkets.BTCMarkets{}
362+
f := &btcmarkets.Exchange{}
363363
f.Name = testExchange
364364
cs := Settings{
365365
Exchange: f,

backtester/eventhandlers/exchange/slippage/slippage_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestRandomSlippage(t *testing.T) {
2121

2222
func TestCalculateSlippageByOrderbook(t *testing.T) {
2323
t.Parallel()
24-
b := bitstamp.Bitstamp{}
24+
b := bitstamp.Exchange{}
2525
b.SetDefaults()
2626

2727
cp := currency.NewBTCUSD()

0 commit comments

Comments
 (0)