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

FIX: move Initialize() call out, call it before the LoadState #1455

Merged
merged 1 commit into from
Dec 18, 2023

Conversation

c9s
Copy link
Owner

@c9s c9s commented Dec 18, 2023

The new generation of strategies introduces the use of common.Strategy, which is embedded as a struct to simplify the strategy implementation. This approach reduces the amount of code required for writing strategies. During the transition from YAML configuration to runtime instance, whenever any configuration field of common.Strategy is set, it initializes the common.Strategy structure to enable persistence. In other words, s.Strategy == &common.Strategy is established by the JSON unmarshal process. Conversely, if it's not set, s.Strategy becomes nil, preventing persistence from being loaded.

Inside the Run() function, we directly assign s.Strategy = &common.Strategy{}. This overwrites the object that was previously loaded from persistence, causing the strategy to start with zeroed data when it stops. Initially, the intention was to move s.Strategy = &common.Strategy{} inside the Initialize() method of the strategy. However, this phase still occurs after LoadState, resulting in persistence being cleared.

The original stages of the strategy launch were as follows:

  1. trader.Configure: Mount strategies.
  2. trader.LoadState: Load persistence.
  3. Run: Execute Strategy Initialize(), Defaults(), and Run().

The modified stages are as follows:

  1. trader.Configure: Mount strategies.
  2. trader.Initialize: Call strategy Initialize().
  3. trader.LoadState: Load persistence.
  4. Run: Execute strategy Defaults() and Run().

@bbgokarma-bot
Copy link

Welcome back! @c9s, This pull request may get 227 BBG.

Copy link

codecov bot commented Dec 18, 2023

Codecov Report

Merging #1455 (3e6d6e1) into main (0466165) will decrease coverage by 0.01%.
The diff coverage is 0.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1455      +/-   ##
==========================================
- Coverage   21.32%   21.32%   -0.01%     
==========================================
  Files         590      590              
  Lines       43434    43436       +2     
==========================================
  Hits         9262     9262              
- Misses      33497    33499       +2     
  Partials      675      675              
Files Coverage Δ
pkg/bbgo/trader.go 0.00% <0.00%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0466165...3e6d6e1. Read the comment docs.

@kbearXD kbearXD merged commit fe2fa19 into main Dec 18, 2023
2 of 4 checks passed
@kbearXD kbearXD deleted the c9s/fix-persistence-loading branch December 18, 2023 05:42
@bbgokarma-bot
Copy link

Hi @c9s,

Well done! 237 BBG has been sent to your polygon wallet. Please check the following tx:

https://polygonscan.com/tx/0x794ad54841480c151fc0713671a1b9ae883b90d1677b4fb2a9616762c6534f83

Thank you for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants