Skip to content

FEATURE: [xfundingv2] strategy state persistence support#2485

Merged
dboyliao merged 7 commits into
mainfrom
dboy/strategy/xfundingv2-sync
May 11, 2026
Merged

FEATURE: [xfundingv2] strategy state persistence support#2485
dboyliao merged 7 commits into
mainfrom
dboy/strategy/xfundingv2-sync

Conversation

@dboyliao
Copy link
Copy Markdown
Collaborator

@dboyliao dboyliao commented May 8, 2026

strategy state persistence support

@dboyliao dboyliao requested a review from c9s as a code owner May 8, 2026 15:38
@dboyliao dboyliao force-pushed the dboy/strategy/xfundingv2-sync branch 2 times, most recently from 0dd9f64 to 82895c7 Compare May 9, 2026 04:37
@dboyliao dboyliao force-pushed the dboy/strategy/xfundingv2-sync branch 3 times, most recently from 1df1029 to 4719b58 Compare May 9, 2026 05:20
@dboyliao dboyliao changed the title FEATURE: [xfundingv2] Custom Sync FEATURE: [xfundingv2] strategy state persistence support May 9, 2026
@dboyliao dboyliao changed the title FEATURE: [xfundingv2] strategy state persistence support FEATURE: [xfundingv2] strategy state persistency support May 9, 2026
@dboyliao dboyliao changed the title FEATURE: [xfundingv2] strategy state persistency support FEATURE: [xfundingv2] strategy state persistence support May 9, 2026
@dboyliao dboyliao force-pushed the dboy/strategy/xfundingv2-sync branch 5 times, most recently from 2b95c18 to 3d0a03a Compare May 9, 2026 09:32
@dboyliao dboyliao force-pushed the dboy/strategy/xfundingv2-sync branch from 3d0a03a to 9953ce4 Compare May 9, 2026 09:36
Comment thread pkg/strategy/xfundingv2/arb_round.go Outdated
r.spotWorker.Stop()
r.futuresWorker.Stop()
r.syncState.SpotWorker.Stop()
r.syncState.FuturesWorker.Stop()
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

is there a reason to add SpotWorker and FuturesWorker under the syncState?

You should place them under the ArbitrageRound?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed.

}

func (r *ArbitrageRound) retryTransferWorker(ctx context.Context) {
func (r *ArbitrageRound) retryTransferWorker(ctx context.Context, tickC <-chan time.Time) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

maybe not another worker for the transfer, you can do it everytime when the tick is happened??

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Because the transfer API call is blocking and I don't want it to block the main event loop of xfundingv2.
That's why I put the transfer work into dedicated goroutine.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Especially we are planning to support multiple arbitrage rounds in the future.
I don't want the elapsed time to build up when there are multiple pending rounds.

"github.com/c9s/bbgo/pkg/types"
)

func (r *ArbitrageRound) LoadStrategy(ctx context.Context, s *Strategy) error {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Perhaps call it Initialize(ctx, strategy)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

done.


Symbol string `json:"symbol"`
SpotWorker *TWAPWorker `json:"spotWorker,omitempty"`
FuturesWorker *TWAPWorker `json:"futuresWorker,omitempty"`
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Workers can't be serialized?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, it does.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It's state will be serialized.
The underlying general executor will be set by Initialize(ctx, *Strategy).

@dboyliao dboyliao requested a review from c9s May 11, 2026 12:43
@dboyliao dboyliao enabled auto-merge May 11, 2026 12:52
@dboyliao dboyliao merged commit 413b4b2 into main May 11, 2026
3 of 4 checks passed
@dboyliao dboyliao deleted the dboy/strategy/xfundingv2-sync branch May 11, 2026 12:56
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.

2 participants