def write_trade_trace(strategy_name, asset, amount, style): file_path = PathMgr.get_strategies_tradetrace_file(strategy_name) time = datetime.datetime.now( tz=pytz.timezone('US/Eastern')).strftime('%Y-%m-%d %H:%M:%S') if style == OrderStyle.MarketOrder: price = Data().current(asset) else: price = style[1] content = ','.join(map(str, [time, asset, amount, price])) append_to_file(file_path, '%s\r\n' % content)
def read_trade_trace(strategy_name): file_path = PathMgr.get_strategies_tradetrace_file(strategy_name) content = read_file_to_string(file_path) lines = content.split('\r\n')[:-1] return map(TradeRecord.read_from_line, lines)