Skip to content

Commit

Permalink
xnav: store asset snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Dec 16, 2024
1 parent b21f0ef commit cb018ce
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions pkg/strategy/xnav/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ func init() {
bbgo.RegisterStrategy(ID, &Strategy{})
}

type AllAssetSnapshot struct {
SessionAssets map[string]asset.Map
TotalAssets asset.Map
Time time.Time
}

type State struct {
Since int64 `json:"since"`
}
Expand Down Expand Up @@ -67,6 +73,8 @@ type Strategy struct {

ShowDebtDetails bool `json:"showDebtDetails"`

lastAllAssetSnapshot *AllAssetSnapshot

State *State `persistence:"state"`

cron *cron.Cron
Expand Down Expand Up @@ -95,7 +103,7 @@ func (s *Strategy) recordNetAssetValue(ctx context.Context, sessions map[string]
log.Infof("recording net asset value...")

priceTime := time.Now()
allAssets := map[string]asset.Map{}
sessionAssets := map[string]asset.Map{}

// iterate the sessions and record them
quoteCurrency := "USDT"
Expand Down Expand Up @@ -134,7 +142,7 @@ func (s *Strategy) recordNetAssetValue(ctx context.Context, sessions map[string]
as.Available.String())
}

allAssets[sessionName] = assets
sessionAssets[sessionName] = assets

if s.ShowBreakdown {
slackAttachment := assets.SlackAttachment()
Expand All @@ -144,7 +152,7 @@ func (s *Strategy) recordNetAssetValue(ctx context.Context, sessions map[string]
}

totalAssets := asset.Map{}
for _, assets := range allAssets {
for _, assets := range sessionAssets {
totalAssets = totalAssets.Merge(assets)
}

Expand All @@ -160,6 +168,12 @@ func (s *Strategy) recordNetAssetValue(ctx context.Context, sessions map[string]

bbgo.Notify(displayAssets)

s.lastAllAssetSnapshot = &AllAssetSnapshot{
SessionAssets: sessionAssets,
TotalAssets: totalAssets,
Time: priceTime,
}

if s.State != nil {
if s.State.IsOver24Hours() {
s.State.Reset()
Expand Down

0 comments on commit cb018ce

Please sign in to comment.