Skip to content

Commit fadbe71

Browse files
committed
Revert backtest manager
1 parent b6f2806 commit fadbe71

File tree

1 file changed

+12
-28
lines changed

1 file changed

+12
-28
lines changed

neurons/backtest_manager.py

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@
2424
test_single_hotkey = '5HDmzyhrEco9w6Jv8eE3hDMcXSE4AGg1MuezPR4u2covxKwZ'
2525
"""
2626
import copy
27+
import logging
2728
import os
2829
import time
2930

3031
import bittensor as bt
3132

33+
# Set up logger for this module
34+
logger = logging.getLogger(__name__)
35+
3236
# Set environment variables for database access
3337
os.environ["TAOSHI_TS_DEPLOYMENT"] = "DEVELOPMENT"
3438
os.environ["TAOSHI_TS_PLATFORM"] = "LOCAL"
@@ -201,16 +205,16 @@ def update_current_hk_to_positions(self, cutoff_ms):
201205
assert len(existing_positions) <= 1, f"Found multiple positions with the same UUID: {existing_positions}"
202206
existing_position = existing_positions[0] if existing_positions else None
203207
if existing_position:
204-
print(f'OQU: Added order to existing position ({position.position_uuid}) with tp {position.trade_pair.trade_pair_id} at {time_formatted}')
208+
logger.debug(f'OQU: Added order to existing position ({position.position_uuid}) with tp {position.trade_pair.trade_pair_id} at {time_formatted}')
205209
assert all(o.order_uuid != order.order_uuid for o in existing_position.orders), \
206210
f"Order {order.order_uuid} already exists in position {existing_position.position_uuid}"
207211
existing_position.orders.append(order)
208-
existing_position.rebuild_position_with_updated_orders()
212+
existing_position.rebuild_position_with_updated_orders(self.live_price_fetcher)
209213
self.position_manager.save_miner_position(existing_position)
210214
else: # first order. position must be inserted into list
211-
print(f'OQU: Created new position ({position.position_uuid}) with tp {position.trade_pair.trade_pair_id} at {time_formatted} for hk {position.miner_hotkey}')
215+
logger.debug(f'OQU: Created new position ({position.position_uuid}) with tp {position.trade_pair.trade_pair_id} at {time_formatted} for hk {position.miner_hotkey}')
212216
position.orders = [order]
213-
position.rebuild_position_with_updated_orders()
217+
position.rebuild_position_with_updated_orders(self.live_price_fetcher)
214218
self.position_manager.save_miner_position(position)
215219

216220
def init_order_queue_and_current_positions(self, cutoff_ms, positions_at_t_f, rebuild_all_positions=False):
@@ -219,7 +223,7 @@ def init_order_queue_and_current_positions(self, cutoff_ms, positions_at_t_f, re
219223
for position in positions:
220224
if position.orders[-1].processed_ms <= cutoff_ms:
221225
if rebuild_all_positions:
222-
position.rebuild_position_with_updated_orders()
226+
position.rebuild_position_with_updated_orders(self.live_price_fetcher)
223227
self.position_manager.save_miner_position(position)
224228
continue
225229
orders_to_keep = []
@@ -231,12 +235,12 @@ def init_order_queue_and_current_positions(self, cutoff_ms, positions_at_t_f, re
231235
if orders_to_keep:
232236
if len(orders_to_keep) != len(position.orders):
233237
position.orders = orders_to_keep
234-
position.rebuild_position_with_updated_orders()
238+
position.rebuild_position_with_updated_orders(self.live_price_fetcher)
235239
self.position_manager.save_miner_position(position)
236240

237241
self.order_queue.sort(key=lambda x: x[0].processed_ms, reverse=True)
238242
current_hk_to_positions = self.position_manager.get_positions_for_all_miners()
239-
print(f'Order queue size: {len(self.order_queue)},'
243+
logger.debug(f'Order queue size: {len(self.order_queue)},'
240244
f' Current positions n hotkeys: {len(current_hk_to_positions)},'
241245
f' Current positions n total: {sum(len(v) for v in current_hk_to_positions.values())}')
242246

@@ -363,10 +367,10 @@ def debug_print_ledgers(self, perf_ledger_bundles):
363367
use_slippage=use_slippage, fetch_slippage_data=False, recalculate_slippage=False,
364368
parallel_mode=parallel_mode,
365369
build_portfolio_ledgers_only=build_portfolio_ledgers_only)
370+
366371
perf_ledger_bundles = {}
367372
interval_ms = 1000 * 60 * 60 * 24
368373
prev_end_time_ms = None
369-
print(f"DEBUG: Starting backtest loop from {start_time_ms} to {end_time_ms}")
370374
for t_ms in range(start_time_ms, end_time_ms, interval_ms):
371375
btm.validate_last_update_ms(prev_end_time_ms)
372376
btm.update(t_ms, run_challenge=run_challenge, run_elimination=run_elimination)
@@ -380,25 +384,5 @@ def debug_print_ledgers(self, perf_ledger_bundles):
380384
#btm.debug_print_ledgers(perf_ledger_bundles)
381385
btm.perf_ledger_manager.debug_pl_plot(test_single_hotkey)
382386

383-
print("DEBUG: About to generate miner statistics...")
384-
385-
# Generate miner statistics and ZK proofs
386-
print("\n" + "="*80)
387-
print("GENERATING MINER STATISTICS & ZK PROOFS")
388-
print("="*80)
389-
390-
try:
391-
bt.logging.info("Calling generate_miner_statistics_data...")
392-
result = btm.miner_statistics_manager.generate_miner_statistics_data(
393-
bypass_confidence=True
394-
)
395-
bt.logging.success("✅ Miner statistics and ZK proofs generated successfully!")
396-
bt.logging.info(f"Generated statistics for {len(result.get('main', {}))} miners")
397-
except Exception as e:
398-
bt.logging.error(f"❌ Error generating miner statistics: {e}")
399-
import traceback
400-
traceback.print_exc()
401-
402387
tf = time.time()
403388
bt.logging.success(f'Finished backtesting in {tf - t0} seconds')
404-
print("DEBUG: Script completed!")

0 commit comments

Comments
 (0)