-
Notifications
You must be signed in to change notification settings - Fork 822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
exchanges: Add Deribit exchange support #1082
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey! While I'm awaiting you to fix the OKx comments. I did a quick review here. Its very exciting having another exchange up for review!
I think you've gone too heavy handed on the API validation. By making the checks so strict, if Derebit ever changes anything, as you can see, you would need to update well over 100 functions. Some validation is fine for API requests, like instrument != ""
or "price <= 0", but looking for specific candles intervals, or currencies is too much. Let the API fail the user. I understand that I haven't really emphasised this with the OKx reviews, but the things that you check there are less likely to change than something like a currency, or a candle interval
If you do have repeating validation checks that are specific, such as the time checks, please create validation functions. That way there is only one place where the validation goes and it can be easily updated and is repeated. As a result of this, I've needed to add many comments (not exhaustive) and you've created more work for yourself to address them. As you can see with the time start and end checks, they've also be inconsistently applied, having one function handle all instances reduces the amount of work you need to do
Also looks like there are some implementation issues to work out,see the lint logs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding the additional test coverage + other changes! Found these additional things:
exchanges/asset/asset_test.go
Outdated
t.Run(testScenario.item.String(), func(t *testing.T) { | ||
t.Parallel() | ||
if testScenario.item.IsOptions() != testScenario.isOptions { | ||
t.Errorf("expected %v isFutures to be %v", testScenario.item, testScenario.isOptions) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
t.Errorf("expected %v isFutures to be %v", testScenario.item, testScenario.isOptions) | |
t.Errorf("expected %v isOptions to be %v", testScenario.item, testScenario.isOptions) |
CONTRIBUTORS
Outdated
TaltaM | https://github.com/TaltaM | ||
dackroyd | https://github.com/dackroyd | ||
cranktakular | https://github.com/cranktakular | ||
khcchiu | https://github.com/khcchiu | ||
yangrq1018 | https://github.com/yangrq1018 | ||
woshidama323 | https://github.com/woshidama323 | ||
crackcomm | https://github.com/crackcomm | ||
azhang | https://github.com/azhang | ||
mshogin | https://github.com/mshogin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mshogin, herenow, soxipy, azhang are duplicated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basic things on new changes
exchanges/deribit/deribit.go
Outdated
@@ -2393,6 +2393,9 @@ func (d *Deribit) ExecuteBlockTrade(ctx context.Context, timestampMS time.Time, | |||
if len(trades) == 0 { | |||
return nil, errNoArgumentPassed | |||
} | |||
if timestampMS.IsZero() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VerifiyBlockTrade is called below so there are a double up on these checks, can probably remove them and also target coverage for trade data.
@@ -2192,7 +2192,7 @@ func (d *Deribit) WSExecuteBlockTrade(timestampMS time.Time, nonce, role, symbol | |||
if timestampMS.IsZero() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same doubling up affect as the other function as this calls WSVerifyBlockTrade
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all those changes!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes ACK. Thanks sir.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making those changes!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tACK!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last batch of nits, I swear 😆
exchanges/deribit/deribit_types.go
Outdated
errInvalidAPIKeyID = errors.New("invalid api key id") | ||
errMaxScopeIsRequired = errors.New("max scope is required") | ||
errTradeModeIsRequired = errors.New("self trading mode is required") | ||
errInvalidSubaccountPassword = errors.New("subaccount password can not be empty") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unused
exchanges/deribit/deribit_wrapper.go
Outdated
if err != nil { | ||
log.Errorln(log.ExchangeSys, err) | ||
} | ||
err = d.DisableAssetWebsocketSupport(asset.Options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
err = d.DisableAssetWebsocketSupport(asset.Options) | |
for _, assetType := range []asset.Item{asset.Options, asset.OptionCombo, asset.FutureCombo} { | |
if err = d.DisableAssetWebsocketSupport(assetType); err != nil { | |
log.Errorln(log.ExchangeSys, err) | |
} | |
} |
exchanges/deribit/deribit_wrapper.go
Outdated
if err != nil { | ||
log.Errorln(log.ExchangeSys, err) | ||
} | ||
if err = d.StoreAssetPairFormat(asset.Futures, currency.PairStore{RequestFormat: requestFmt, ConfigFormat: configFmt}); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if err = d.StoreAssetPairFormat(asset.Futures, currency.PairStore{RequestFormat: requestFmt, ConfigFormat: configFmt}); err != nil { | |
for _, assetType := range []asset.Item{asset.Futures, asset.Options, asset.OptionCombo, asset.FutureCombo} { | |
if err = d.StoreAssetPairFormat(assetType, currency.PairStore{RequestFormat: requestFmt, ConfigFormat: configFmt}); err != nil { | |
log.Errorln(log.ExchangeSys, err) | |
} | |
} |
exchanges/deribit/deribit_test.go
Outdated
) | ||
|
||
func TestMain(m *testing.M) { | ||
d.SetDefaults() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can take advtange of the internal test exchange Setup helper, like:
d = new(Deribit)
if err := testexch.Setup(d); err != nil {
log.Fatal(err)
}
To rid a lot of the TestMain boilerplate
exchanges/deribit/deribit_test.go
Outdated
|
||
var ( | ||
d = &Deribit{} | ||
futuresTradablePair, optionsTradablePair, optionComboTradablePair, futureComboTradablePair, spotTradablePair currency.Pair |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can hardcode spotTradablePair to currency.NewPairWithDelimiter("BTC", "USDC", "_")
and futuresTradablePair to currency.NewPairWithDelimiter("BTC", "PERPETUAL", "-")
thus eliminating the need to use NewPairFromString
in instantiateTradablePairs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work on the cleanup! One thing I found on recent changes that could be a problem.
also can you add these lines to fix codespell reference here. Your PR will be merged first. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes ACK. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tACK! Thanks for the test updates
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making those changes, some further ones I've found
} | ||
} | ||
case instrumentStateChannel, | ||
rawUsersOrdersKindCurrencyChannel: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This case statement contains string formatting directives
} | ||
case incrementalTickerChannel, | ||
quoteChannel, | ||
rawUserOrdersChannel: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This string contains string format directives
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These strings differentiate channels selected for subscription and are not used in handling the incoming stream data messages.
PR Description
This pull request Included a code implementation for the Deribit exchange version 2; with REST and web-socket support. All the Websocket and Wrapper functions are tested. My code follows the style guidelines of other exchanges of GCT.
Fixed some errors with the help of golangci-lint. Endpoint methods that have no support from the GCT wrapper are also implemented for future use.
Fixes # (issue)
Type of change
Please delete options that are not relevant and add an
x
in[]
as item is complete.How has this been tested
For testing the exchange with your own API Credentials you can use your own API key { } and passphrase fields in the unit test deribit_test.go file, or directly add credential information to the config file you will be using for running.
Checklist