-
Notifications
You must be signed in to change notification settings - Fork 820
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
Config: AssetEnabled upgrade #1735
base: master
Are you sure you want to change the base?
Conversation
3697ede
to
5fb08d2
Compare
026f88f
to
272827a
Compare
942b49b
to
e2d81d0
Compare
This became more messy with Disabling something that's defaulted to disabled. Taking an idealogical stance against erroring that what you want to have done is already done.
Previously we were calling it "Format", but accepting everything from the PairStore. We were also defaulting to turning the Asset on. Now callers need to get their AssetEnabled set as they want it, so there's no magic This change also moves responsibility for error wrapping outside to the caller.
Previously we ignored the field and just turned on everything. I think that was because we couldn't get at the old value. In either case, we have the option to do better, and respect the assetEnabled value
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.
Quick test on gateio, when I set everything but spot assets to false for asset enabled it still fetches and subscribes all assets. Doesn't seem to be happening on master, once resolved I will do a more in-depth check.
c092bfa
to
65c05a0
Compare
Fixed gbjk@65c05a063 |
65c05a0
to
4a4fb99
Compare
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.
great cleanup! tested and runs great. Just some minor nits.
if err != nil { | ||
log.Errorln(log.ExchangeSys, err) | ||
log.Errorf(log.ExchangeSys, "%s error storing `%s` default asset formats: %s", {{.Variable}}.Name, asset.Spot, err) |
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.
Can you wrap all these details on the error paths in StoreAssetPairStore
? That way we don't need to have this.
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.
The whole direction here was the opposite of this change request.
The ideology I'm following is that functions return the error they encounter, without their own context.
If you call a go standard library function, you'll get the same thing.
It's down to the caller to decide if it wants to give context to that error, and what that context looks like from it's perspective.
From the perspective of the function caller, they know what they called, and so the error returned should be undecorated.
Case in point: StoreAssetPairStore
is not default asset formats
so these callers all needed to clarify the context they were calling that function in.
This is why you'll often see me decorate errors one level above where GCT has previously been doing it.
Sometimes it can feel slightly weighty, in this example where we copy the same context everywhere.
We could definitely add a common error for errStoringDefaultAssetFormats
though, and I think that's warranted.
I'll circle back to this after the others and see if you've replied :)
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.
Adding one more bit of context:
This implies that functions must also add their own context.
e.g. If StoreAssetPairStore encountered some error interacting with a database, like "Record not found", We'd expect that error to come without context.
So StoreAssetPairStore
should add the context error searching for glove size in database: %w
.
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.
From an implementation perspective, maintaining this standard can introduce toil during implementation and reviews, especially since any failure in SetDefaults would inherently cause the exchange to malfunction. Differentiating between errors in this context seems redundant. Still suggest wrapping asset and exchange for the exchange method.
But I will leave this open for other peoples perspective. @thrasher- @gloriousCode
config/config_test.go
Outdated
c.Exchanges[0].CurrencyPairs.Pairs[asset.Spot].Available = currency.Pairs{ | ||
p1, | ||
} | ||
pm.Pairs[asset.Spot].Available = currency.Pairs{p1} | ||
|
||
// LTC_USD is only found in the available pairs list and should therefore | ||
// be added to the enabled pairs list due to the atLestOneEnabled code |
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.
// be added to the enabled pairs list due to the atLestOneEnabled code | |
// be added to the enabled pairs list due to the atLeastOneEnabled code |
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.
Imma fixup into 4d32d83 cos I obviously can't fixup into 14c72c9
Fixed gbjk@36e3dffbc
if err == nil { | ||
t.Fatal("unexpected result") | ||
} | ||
assert.NoError(t, err, "Setting to disabled twice should not error") |
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.
Suggestion: I usually return an error on no-op because I find it easier to track my own whoopsies, I also like the fact if I change it by CLI it then returns that it failed. I do see the idempotency aspect of the new behaviour though. Keep this unresolved for other peoples input if you want to pass on this.
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.
I believe if something wants to error on it already being disabled/enabled, that's it's problem.
The responsibility of this function is to do what it's told 😃
So I'm happy to add a check in api server or CLI for you to see if it's already enabled/disabled and error there.
Would you like that?
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.
No thanks, if it's going to stay like this, having that check would need to go to all potential API calls cli, scripting etc. State change responsibility is not a major concern 🤷 just easier here but it's such a minor thing.
engine/rpcserver_test.go
Outdated
b := e.GetBase() | ||
|
||
for _, a := range []asset.Item{asset.Spot, asset.Margin, asset.CoinMarginedFutures, asset.USDTMarginedFutures} { | ||
fmt := currency.PairStore{ |
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.
fmt
conflicts with a package name maybe just ps
?
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.
Agreed, Thanks! 🙏
Fixed gbjk@d6c896634
exchanges/bitmex/bitmex_wrapper.go
Outdated
ConfigFormat: ¤cy.PairFormat{Uppercase: true, Delimiter: currency.DashDelimiter}, | ||
} | ||
if a == asset.Spot { | ||
ps.RequestFormat = ¤cy.PairFormat{Uppercase: true, Delimiter: currency.UnderscoreDelimiter} |
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.
ps.RequestFormat = ¤cy.PairFormat{Uppercase: true, Delimiter: currency.UnderscoreDelimiter} | |
ps.RequestFormat.Delimiter = currency.UnderscoreDelimiter |
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.
Fixed gbjk@bfa72e20a
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1735 +/- ##
==========================================
+ Coverage 37.13% 37.38% +0.24%
==========================================
Files 414 416 +2
Lines 180198 178480 -1718
==========================================
- Hits 66925 66723 -202
+ Misses 105413 104001 -1412
+ Partials 7860 7756 -104
|
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.
Current changes tACK. 🚀
Config:
Exchanges:
StoreAssetPairFormat
toStoreAssetPairStore
SetAssetEnabled
will not error on no-op (already disabled or enabled)Bitfinex:
Type of change
Please delete options that are not relevant and add an
x
in[]
as item is complete.How has this been tested