from decimal import Decimal as D
import json
a=[D(x) for x in ['100','101','99','100.5']]
b=[D(x) for x in ['100','99','101','100.5']]
def ohlc(x): return [str(x[0]),str(max(x)),str(min(x)),str(x[-1])]
assert ohlc(a)==ohlc(b)
entry=D('100');tp=D('100.8');stop=D('99.5')
def first_exit(path):
 for left,right in zip(path,path[1:]):
  if right>left and left<=tp<=right:return 'target',tp
  if right<left and right<=stop<=left:return 'stop',stop
 raise AssertionError('no exit')
assert first_exit(a)==('target',tp)
assert first_exit(b)==('stop',stop)
assert (tp/entry-1)*100==D('0.8')
assert (stop/entry-1)*100==D('-0.5')
assert (D('100')-D('99.5'))*3600/30==60
assert (D('100')-D('109.5'))*3600/30==-1140
refill_state='BLOCKED_REFILL' if D('10')>0 else 'ESTIMATE_VALID'
assert refill_state=='BLOCKED_REFILL'
print(json.dumps({'synthetic_only':True,'tests_passed':8,'identical_ohlc':ohlc(a),'target_first_percent':0.8,'stop_first_percent':-0.5,'average_feed_rate_kg_h':60,'invalid_refill_estimate_kg_h':-1140,'refill_state':refill_state},indent=2))
