configurable txt separator
This commit is contained in:
@@ -7043,7 +7043,8 @@ class TradingOrchestrator:
|
||||
'ref1_symbol': self.ref_symbols[0] if self.ref_symbols else 'BTC/USDT',
|
||||
'ref2_symbol': 'SPX', # Default to SPX for now
|
||||
'ref3_symbol': 'SOL/USDT',
|
||||
'export_dir': 'NN/training/samples/txt'
|
||||
'export_dir': 'NN/training/samples/txt',
|
||||
'export_format': 'PIPE'
|
||||
}
|
||||
|
||||
self.text_export_manager.export_config.update(export_config)
|
||||
|
@@ -45,7 +45,8 @@ class TextDataExporter:
|
||||
main_symbol: str = "ETH/USDT",
|
||||
ref1_symbol: str = "BTC/USDT",
|
||||
ref2_symbol: str = "SPX",
|
||||
ref3_symbol: str = "SOL/USDT"):
|
||||
ref3_symbol: str = "SOL/USDT",
|
||||
export_format: str = "PIPE"):
|
||||
"""
|
||||
Initialize text data exporter
|
||||
|
||||
@@ -62,6 +63,7 @@ class TextDataExporter:
|
||||
self.ref1_symbol = ref1_symbol
|
||||
self.ref2_symbol = ref2_symbol
|
||||
self.ref3_symbol = ref3_symbol
|
||||
self.export_format = export_format.upper() if isinstance(export_format, str) else "PIPE"
|
||||
|
||||
# Timeframes to export
|
||||
self.timeframes = ['1s', '1m', '1h', '1d']
|
||||
@@ -224,8 +226,10 @@ class TextDataExporter:
|
||||
grouped_data = self._group_data_by_symbol(export_data)
|
||||
|
||||
with open(filepath, 'w', encoding='utf-8') as txtfile:
|
||||
# Write in the format specified in readme.md sample
|
||||
self._write_tab_format(txtfile, grouped_data)
|
||||
if self.export_format == 'TAB':
|
||||
self._write_tab_format(txtfile, grouped_data)
|
||||
else:
|
||||
self._write_pipe_format(txtfile, grouped_data)
|
||||
|
||||
logger.debug(f"Exported {len(export_data)} data points to {filepath}")
|
||||
|
||||
@@ -299,10 +303,10 @@ class TextDataExporter:
|
||||
rows.append(row)
|
||||
return rows
|
||||
|
||||
def _write_tab_format(self, txtfile, grouped_data: Dict[str, Dict[str, Dict[str, Any]]]):
|
||||
def _write_tab_format(self, txtfile, grouped_data: Dict[str, Dict[str, Dict[str, Any]]] ):
|
||||
"""Write data in tab-separated format like readme.md sample"""
|
||||
# Write header structure
|
||||
txtfile.write("symbol\tMAIN SYMBOL (ETH)\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tREF1 (BTC)\t\t\t\t\t\tREF2 (SPX)\t\t\t\t\t\tREF3 (SOL)\n")
|
||||
txtfile.write("symbol\tMAIN SYMBOL (ETH)\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tREF1 (BTC)\t\t\t\t\t\t\tREF2 (SPX)\t\t\t\t\t\t\tREF3 (SOL)\n")
|
||||
txtfile.write("timeframe\t1s\t\t\t\t\t\t1m\t\t\t\t\t\t1h\t\t\t\t\t\t1d\t\t\t\t\t\t1s\t\t\t\t\t\t1s\t\t\t\t\t\t1s\n")
|
||||
txtfile.write("datapoint\tO\tH\tL\tC\tV\tTimestamp\tO\tH\tL\tC\tV\tTimestamp\tO\tH\tL\tC\tV\tTimestamp\tO\tH\tL\tC\tV\tTimestamp\tO\tH\tL\tC\tV\tTimestamp\tO\tH\tL\tC\tV\tTimestamp\tO\tH\tL\tC\tV\tTimestamp\n")
|
||||
|
||||
@@ -375,6 +379,29 @@ class TextDataExporter:
|
||||
row_parts.extend(["0", "0", "0", "0", "0", ts_str])
|
||||
|
||||
txtfile.write("\t".join(row_parts) + "\n")
|
||||
|
||||
def _write_pipe_format(self, txtfile, grouped_data: Dict[str, Dict[str, Dict[str, Any]]] ):
|
||||
"""Write data in pipe-delimited console-friendly grid."""
|
||||
from io import StringIO
|
||||
buffer = StringIO()
|
||||
self._write_tab_format(buffer, grouped_data)
|
||||
content = buffer.getvalue().splitlines()
|
||||
if not content:
|
||||
return
|
||||
headers = [line.split('\t') for line in content[:3]]
|
||||
data_rows = [line.split('\t') for line in content[3:]]
|
||||
|
||||
def to_pipe(row: List[str]) -> str:
|
||||
return "|" + "|".join(str(col) for col in row) + "|"
|
||||
|
||||
# Render header rows with separators
|
||||
for hdr in headers:
|
||||
txtfile.write(to_pipe(hdr) + "\n")
|
||||
txtfile.write("|" + "|".join(["-" * max(3, len(str(c))) for c in hdr]) + "|\n")
|
||||
|
||||
# Render data
|
||||
for row in data_rows:
|
||||
txtfile.write(to_pipe(row) + "\n")
|
||||
|
||||
def get_current_filename(self) -> Optional[str]:
|
||||
"""Get current export filename"""
|
||||
|
@@ -34,7 +34,8 @@ class TextExportManager:
|
||||
'ref1_symbol': 'BTC/USDT',
|
||||
'ref2_symbol': 'SPX', # Will need to be mapped to available data
|
||||
'ref3_symbol': 'SOL/USDT',
|
||||
'export_dir': 'NN/training/samples/txt'
|
||||
'export_dir': 'NN/training/samples/txt',
|
||||
'export_format': 'PIPE' # PIPE (default) or TAB
|
||||
}
|
||||
|
||||
def initialize_exporter(self, config: Optional[Dict[str, Any]] = None):
|
||||
@@ -56,7 +57,8 @@ class TextExportManager:
|
||||
main_symbol=self.export_config['main_symbol'],
|
||||
ref1_symbol=self.export_config['ref1_symbol'],
|
||||
ref2_symbol=self.export_config['ref2_symbol'],
|
||||
ref3_symbol=self.export_config.get('ref3_symbol', 'SOL/USDT')
|
||||
ref3_symbol=self.export_config.get('ref3_symbol', 'SOL/USDT'),
|
||||
export_format=self.export_config.get('export_format', 'PIPE')
|
||||
)
|
||||
|
||||
logger.info("Text data exporter initialized successfully")
|
||||
|
Reference in New Issue
Block a user