configurable txt separator

This commit is contained in:
Dobromir Popov
2025-08-27 01:48:29 +03:00
parent fc1ac2061f
commit d49a473ed6
4 changed files with 42 additions and 15 deletions

View File

@@ -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)

View File

@@ -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"""

View File

@@ -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")

View File

@@ -2979,7 +2979,7 @@ class CleanTradingDashboard:
hold_predictions = []
for pred in dqn_predictions[-30:]: # Last 30 DQN predictions
action = pred.get('action', 2) # 0=BUY, 1=SELL, 2=HOLD
action = pred.get('action', 2) # 0=SELL, 1=HOLD, 2=BUY
confidence = pred.get('confidence', 0)
timestamp = pred.get('timestamp', datetime.now())
price = pred.get('price', 0)
@@ -2996,9 +2996,10 @@ class CleanTradingDashboard:
'q_values': pred.get('q_values', [0, 0, 0])
}
if action == 0: # BUY
# Correct mapping: 2 -> BUY, 0 -> SELL, 1 -> HOLD
if action == 2: # BUY
buy_predictions.append(pred_data)
elif action == 1: # SELL
elif action == 0: # SELL
sell_predictions.append(pred_data)
else: # HOLD
hold_predictions.append(pred_data)
@@ -3409,10 +3410,6 @@ class CleanTradingDashboard:
try:
predictions = []
# Generate sample predictions if needed (for display purposes)
if hasattr(self.orchestrator, 'generate_sample_predictions_for_display'):
self.orchestrator.generate_sample_predictions_for_display(symbol)
# Get REAL predictions from orchestrator
if hasattr(self.orchestrator, 'recent_dqn_predictions'):
predictions.extend(list(self.orchestrator.recent_dqn_predictions.get(symbol, [])))