anchor.diff:    close
   }).
   
  --define(GRANULATION, 30000).
  +-define(DEFAULT_PERIOD, 30000).
   
   candle(Event, Candle) when not is_record(Event, md) andalso Event =/= eof ->
     {[Event], Candle};
  
positive.code: candle(Event, undefined) ->
    candle(Event, []);
  
  candle(#md{} = MD, Opts) when is_list(Opts) ->
    Granulation = proplists:get_value(granulation, Opts, ?GRANULATION),
    candle(MD, #candle{
      granulation = Granulation,
      current_segment = -1});
  
  candle(#md{timestamp = Timestamp} = MD, #candle{granulation = Granulation, current_segment = Seg} = Candle) 
    when Timestamp div Granulation > Seg ->
    {Events, Candle1} = flush_segment(Candle),
    {Events, Candle1#candle{
        current_segment = Timestamp div Granulation,
        open = MD,
        high_ask = MD,
        low_bid = MD,
        close = MD
      }};
  
  candle(eof, #candle{} = Candle) ->
    flush_segment(Candle);
  
negative.code: candle(#md{} = MD, #candle{} = Candle) ->
    {[], accumulate_md(MD, Candle)}.
  
  
  open_segment(MD, Segment, Candle) ->
    Candle#candle{
      current_segment = Segment,
      open = MD,
      high_ask = MD,
      low_bid = MD,
      close = MD
    }.
  
  flush_segment(#candle{open = Open, high_ask = HighAsk, low_bid = LowBid, close = Close} = Candle) ->
    Events = lists:usort([Open, HighAsk, LowBid, Close]),
  