Skip to content
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: shift GetDefaultConfig wrapper function to exchange.go #1472

Merged
merged 6 commits into from
Apr 12, 2024

Conversation

shazbert
Copy link
Collaborator

@shazbert shazbert commented Feb 7, 2024

PR Description

Shifts GetDefaultConfig wrapper function to exchange.go

Mitigates potential issue when its called in a wrapper test and overwrites memory after initial SetDefault method func is called.

Also RMs a bunch of code wrapper side which is nice but its signature is a tad janky. Optionally we can disconnect it as a method and just have an exported function.

Type of change

Please delete options that are not relevant and add an x in [] as item is complete.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How has this been tested

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration and
also consider improving test coverage whilst working on a certain feature or package.

  • go test ./... -race
  • golangci-lint run
  • Test X

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation and regenerated documentation via the documentation tool
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally and on Github Actions with my changes
  • Any dependent changes have been merged and published in downstream modules

@shazbert shazbert added low priority This enhancement or update will be implemented at a later date. review me This pull request is ready for review labels Feb 7, 2024
@shazbert shazbert requested a review from a team February 7, 2024 05:28
@shazbert shazbert self-assigned this Feb 7, 2024
Copy link

codecov bot commented Feb 7, 2024

Codecov Report

Attention: Patch coverage is 66.66667% with 10 lines in your changes are missing coverage. Please review.

Project coverage is 35.96%. Comparing base (d679a76) to head (bbd1f09).
Report is 8 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1472      +/-   ##
==========================================
+ Coverage   35.89%   35.96%   +0.06%     
==========================================
  Files         411      411              
  Lines      177595   177227     -368     
==========================================
- Hits        63752    63734      -18     
+ Misses     106058   105705     -353     
- Partials     7785     7788       +3     
Files Coverage Δ
backtester/engine/live.go 83.08% <100.00%> (+0.20%) ⬆️
backtester/engine/setup.go 57.84% <100.00%> (ø)
engine/helpers.go 80.10% <100.00%> (ø)
exchanges/alphapoint/alphapoint_wrapper.go 23.64% <ø> (+0.29%) ⬆️
exchanges/binance/binance_wrapper.go 38.45% <ø> (+0.23%) ⬆️
exchanges/binanceus/binanceus_wrapper.go 40.90% <ø> (+0.83%) ⬆️
exchanges/bitfinex/bitfinex_wrapper.go 37.16% <ø> (+0.58%) ⬆️
exchanges/bitflyer/bitflyer_wrapper.go 35.66% <ø> (+1.80%) ⬆️
exchanges/bithumb/bithumb_wrapper.go 38.61% <ø> (+0.92%) ⬆️
exchanges/bitmex/bitmex_wrapper.go 44.67% <ø> (-0.54%) ⬇️
... and 21 more

... and 10 files with indirect coverage changes

Copy link
Collaborator

@gloriousCode gloriousCode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice simplification 🤙

@@ -188,3 +189,11 @@ type MarginManagement interface {
futures.PNLCalculation
GetFuturesContractDetails(ctx context.Context, item asset.Item) ([]futures.Contract, error)
}

// LimitedScope defines a subset of the exchange interface
type LimitedScope interface {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to rename it to be more relevant to its limited scope. ConfigGeneration

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I purged it, I was being lazy, you can see why in recent update.

@@ -1943,3 +1944,37 @@ func (b *Base) Bootstrap(_ context.Context) (continueBootstrap bool, err error)
func (b *Base) IsVerbose() bool {
return b.Verbose
}

// GetDefaultConfig returns a default exchange config
func (b *Base) GetDefaultConfig(ctx context.Context, instance LimitedScope) (*config.Exchange, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with your PR assessment that its a bit jank. I think this can become an exported function instead
func GetDefaultConfig(ctx context.Context, instance IBotExchange) (*config.Exchange, error) {
That or LimitedScope, but I don't see much problem with using IBotExchange

@gloriousCode gloriousCode removed the review me This pull request is ready for review label Mar 17, 2024
@gloriousCode gloriousCode added the review me This pull request is ready for review label Apr 9, 2024
Copy link
Collaborator

@gloriousCode gloriousCode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK! Thank you for improving the jank from last time 🎉

if err != nil {
log.Errorln(common.LiveStrategy, err)
}
log.Errorln(common.LiveStrategy, err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log.Errorln(common.LiveStrategy, err)
if err != nil {
if err != nil {
if err == nil {
} else {
log.Errorln(common.LiveStrategy, err)
}
}
}

😄

Comment on lines +1953 to +1967
if exch.GetName() == "" {
exch.SetDefaults()
}

b := exch.GetBase()

exchCfg, err := b.GetStandardConfig()
if err != nil {
return nil, err
}

err = b.SetupDefaults(exchCfg)
if err != nil {
return nil, err
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is so weird! "get me the default config" means setup some parts of the exchange, reset some exchange values to the default config's and then make REST calls.

I'm not going to make you refactor this, it's how its been and refactoring isn't really going to improve much right now. Just a fun function

@gloriousCode gloriousCode added the gcrc GloriousCode Review Complete label Apr 10, 2024
@thrasher- thrasher- merged commit 9657a57 into thrasher-corp:master Apr 12, 2024
8 of 12 checks passed
@shazbert shazbert deleted the default_config branch May 3, 2024 00:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gcrc GloriousCode Review Complete low priority This enhancement or update will be implemented at a later date. review me This pull request is ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants