Deribit: Add subscription configuration (#1636)

* Kline: Fix Raw Short, Marshal and Unmarshal

* Deribit: Rename GenerateDefaultSubs

* Deribit: Remove custom GetDefaultConfig

Moved to exchange base by #1472

* Deribit: Straight Rename of eps to endpoints

Since I had to ask what this abbreviation meant, I think we should
abandon it

* Deribit: Add Subscription configuration

* Deribit: Fix race on Setup with optionsRegex

Calling Setup twice would race on the assignment to this package var.

There was an option to just move the assignment to the package var declaration, but this
change improves the performance and allocations:
```
BenchmarkOptionPairToString-8            1000000              1239 ns/op             485 B/op         10 allocs/op
BenchmarkOptionPairToString2-8           3473804               656.2 ns/op           348 B/op          7 allocs/op
```

I've also removed the t.Run because even success the -v output from
tests would be very noisy, and I don't think we were getting any benefit
from it at all:
```
=== RUN   TestOptionPairToString
=== PAUSE TestOptionPairToString
=== CONT  TestOptionPairToString
=== RUN   TestOptionPairToString/BTC-30MAY24-61000-C
=== PAUSE TestOptionPairToString/BTC-30MAY24-61000-C
=== RUN   TestOptionPairToString/ETH-1JUN24-3200-P
=== PAUSE TestOptionPairToString/ETH-1JUN24-3200-P
=== RUN   TestOptionPairToString/SOL_USDC-31MAY24-162-P
=== PAUSE TestOptionPairToString/SOL_USDC-31MAY24-162-P
=== RUN   TestOptionPairToString/MATIC_USDC-6APR24-0d98-P
=== PAUSE TestOptionPairToString/MATIC_USDC-6APR24-0d98-P
=== CONT  TestOptionPairToString/BTC-30MAY24-61000-C
=== CONT  TestOptionPairToString/SOL_USDC-31MAY24-162-P
=== CONT  TestOptionPairToString/ETH-1JUN24-3200-P
=== CONT  TestOptionPairToString/MATIC_USDC-6APR24-0d98-P
--- PASS: TestOptionPairToString (0.00s)
    --- PASS: TestOptionPairToString/BTC-30MAY24-61000-C (0.00s)
    --- PASS: TestOptionPairToString/ETH-1JUN24-3200-P (0.00s)
    --- PASS: TestOptionPairToString/SOL_USDC-31MAY24-162-P (0.00s)
    --- PASS: TestOptionPairToString/MATIC_USDC-6APR24-0d98-P (0.00s)
```

( And that got worse with me adding more tests )
This commit is contained in:
Gareth Kirwan
2025-01-02 21:55:58 +00:00
committed by GitHub
parent b209b0e1a1
commit 4fcee8489e
9 changed files with 308 additions and 528 deletions

View File

@@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"regexp"
"sort"
"strconv"
"strings"
@@ -34,27 +33,6 @@ import (
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
)
// GetDefaultConfig returns a default exchange config
func (d *Deribit) GetDefaultConfig(ctx context.Context) (*config.Exchange, error) {
d.SetDefaults()
exchCfg, err := d.GetStandardConfig()
if err != nil {
return nil, err
}
err = d.SetupDefaults(exchCfg)
if err != nil {
return nil, err
}
if d.Features.Supports.RESTCapabilities.AutoPairUpdates {
err := d.UpdateTradablePairs(ctx, true)
if err != nil {
return nil, err
}
}
return exchCfg, nil
}
// SetDefaults sets the basic defaults for Deribit
func (d *Deribit) SetDefaults() {
d.Name = "Deribit"
@@ -148,6 +126,7 @@ func (d *Deribit) SetDefaults() {
GlobalResultLimit: 500,
},
},
Subscriptions: defaultSubscriptions.Clone(),
}
d.Requester, err = request.New(d.Name,
common.NewHTTPClientWithTimeout(exchange.DefaultHTTPTimeout),
@@ -197,7 +176,7 @@ func (d *Deribit) Setup(exch *config.Exchange) error {
Connector: d.WsConnect,
Subscriber: d.Subscribe,
Unsubscriber: d.Unsubscribe,
GenerateSubscriptions: d.GenerateDefaultSubscriptions,
GenerateSubscriptions: d.generateSubscriptions,
Features: &d.Features.Supports.WebsocketCapabilities,
OrderbookBufferConfig: buffer.Config{
SortBuffer: true,
@@ -208,9 +187,6 @@ func (d *Deribit) Setup(exch *config.Exchange) error {
return err
}
// setup option decimal regex at startup to make constant checks more efficient
optionRegex = regexp.MustCompile(optionDecimalRegex)
return d.Websocket.SetupNewConnection(&stream.ConnectionSetup{
URL: d.Websocket.GetWebsocketURL(),
ResponseCheckTimeout: exch.WebsocketResponseCheckTimeout,