Skip to content

Commit

Permalink
Make update! return completed candles
Browse files Browse the repository at this point in the history
  • Loading branch information
g-gundam committed Nov 21, 2024
1 parent 4f78ec7 commit ecff322
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ end
""" $(SIGNATURES)
Update a chart with a candle.
When a candle is completed, return it.
Otherwise, return nothing on update.
"""
function update!(chart::Chart, c::Candle)
# aggregation when tf > Minute(1)
Expand All @@ -169,10 +171,12 @@ function update!(chart::Chart, c::Candle)
chart.ts = floor(c.ts, chart.tf)
chart.candle = Candle(c.ts, c.o, c.h, c.l, c.c, c.v) # clone tf boundary candle to start fresh candle aggregation
push_new_candle!(chart, c)
return Candle(c.ts, c.o, c.h, c.l, c.c, c.v) # clone it again to return the most recent completed candle
else
# normal case
chart.candle = merge_candle!(chart.candle, c)
update_last_candle!(chart, chart.candle)
return
end
end

Expand Down

0 comments on commit ecff322

Please sign in to comment.