26 lines
625 B
Python
26 lines
625 B
Python
|
import csv
|
||
|
from pathlib import Path
|
||
|
|
||
|
import fin_depo
|
||
|
|
||
|
|
||
|
class CsvFileLogger:
|
||
|
def __init__(self, path: Path):
|
||
|
self.path = path
|
||
|
|
||
|
def __call__(self, trade_order: fin_depo.data.TradeOrderDetails):
|
||
|
fieldnames: list[str] = [
|
||
|
'input_asset',
|
||
|
'input_amount',
|
||
|
'output_asset',
|
||
|
'output_amount',
|
||
|
'fee_asset',
|
||
|
'fee_amount',
|
||
|
'order_id',
|
||
|
'raw_order_details',
|
||
|
]
|
||
|
|
||
|
with open(self.path, 'a') as f:
|
||
|
writer = csv.DictWriter(f, fieldnames=fieldnames)
|
||
|
writer.writerow(trade_order.__dict__)
|