ARKAISW commited on
Commit
5b8d71e
·
1 Parent(s): 8489eaa

Final manual tweaks to server imports

Browse files
Files changed (3) hide show
  1. api/server.py +2 -0
  2. ui/src/App.jsx +6 -0
  3. ui/src/store.js +18 -2
api/server.py CHANGED
@@ -29,6 +29,8 @@ from env.multi_agent_env import (
29
  # TradingEnv kept for backward compat data generation only (not used in endpoints)
30
  from training.config import TrainingConfig
31
  from training.train_multi_agent import (
 
 
32
  RuleTraderPolicy,
33
  )
34
  try:
 
29
  # TradingEnv kept for backward compat data generation only (not used in endpoints)
30
  from training.config import TrainingConfig
31
  from training.train_multi_agent import (
32
+ RulePortfolioManagerPolicy,
33
+ RuleRiskManagerPolicy,
34
  RuleTraderPolicy,
35
  )
36
  try:
ui/src/App.jsx CHANGED
@@ -14,6 +14,7 @@ function App() {
14
  priceHistory,
15
  lastPortfolioDelta,
16
  lastPriceDelta,
 
17
  toggleSimulation,
18
  fetchState,
19
  stepSimulation,
@@ -45,6 +46,11 @@ function App() {
45
  </div>
46
 
47
  <div className="flex flex-wrap items-center gap-3">
 
 
 
 
 
48
  <div className="rounded-full bg-white/85 px-4 py-2 text-[11px] font-semibold uppercase tracking-[0.24em] text-stone-500 shadow-sm">
49
  Step {simState.current_step}
50
  </div>
 
14
  priceHistory,
15
  lastPortfolioDelta,
16
  lastPriceDelta,
17
+ lastError,
18
  toggleSimulation,
19
  fetchState,
20
  stepSimulation,
 
46
  </div>
47
 
48
  <div className="flex flex-wrap items-center gap-3">
49
+ {lastError ? (
50
+ <div className="rounded-full border border-rose-200 bg-rose-50 px-4 py-2 text-[11px] font-semibold uppercase tracking-[0.18em] text-rose-600 shadow-sm">
51
+ Demo error: {lastError}
52
+ </div>
53
+ ) : null}
54
  <div className="rounded-full bg-white/85 px-4 py-2 text-[11px] font-semibold uppercase tracking-[0.24em] text-stone-500 shadow-sm">
55
  Step {simState.current_step}
56
  </div>
ui/src/store.js CHANGED
@@ -44,9 +44,13 @@ export const useSimulationStore = create((set, get) => ({
44
  priceHistory: [{ step: 0, price: initialState.chart.price }],
45
  lastPortfolioDelta: 0,
46
  lastPriceDelta: 0,
 
47
  fetchState: async () => {
48
  try {
49
  const res = await fetch(`${API_BASE}/state`);
 
 
 
50
  const data = await res.json();
51
 
52
  set((state) => {
@@ -67,27 +71,39 @@ export const useSimulationStore = create((set, get) => ({
67
  price: data.chart.price,
68
  })
69
  : state.priceHistory,
 
70
  };
71
  });
72
  } catch (error) {
73
  console.error('Error fetching state:', error);
 
74
  }
75
  },
76
  toggleSimulation: async (isRunning) => {
77
  const endpoint = isRunning ? '/stop' : '/start';
78
  try {
79
- await fetch(`${API_BASE}${endpoint}`, { method: 'POST' });
 
 
 
 
80
  get().fetchState();
81
  } catch (error) {
82
  console.error(`Error toggling simulation to ${!isRunning}:`, error);
 
83
  }
84
  },
85
  stepSimulation: async () => {
86
  try {
87
- await fetch(`${API_BASE}/step`, { method: 'POST' });
 
 
 
 
88
  get().fetchState();
89
  } catch (error) {
90
  console.error('Error stepping simulation:', error);
 
91
  }
92
  },
93
  }));
 
44
  priceHistory: [{ step: 0, price: initialState.chart.price }],
45
  lastPortfolioDelta: 0,
46
  lastPriceDelta: 0,
47
+ lastError: '',
48
  fetchState: async () => {
49
  try {
50
  const res = await fetch(`${API_BASE}/state`);
51
+ if (!res.ok) {
52
+ throw new Error(`State request failed (${res.status})`);
53
+ }
54
  const data = await res.json();
55
 
56
  set((state) => {
 
71
  price: data.chart.price,
72
  })
73
  : state.priceHistory,
74
+ lastError: '',
75
  };
76
  });
77
  } catch (error) {
78
  console.error('Error fetching state:', error);
79
+ set({ lastError: error.message || 'Unable to fetch simulator state.' });
80
  }
81
  },
82
  toggleSimulation: async (isRunning) => {
83
  const endpoint = isRunning ? '/stop' : '/start';
84
  try {
85
+ const res = await fetch(`${API_BASE}${endpoint}`, { method: 'POST' });
86
+ if (!res.ok) {
87
+ throw new Error(`${isRunning ? 'Stop' : 'Start'} request failed (${res.status})`);
88
+ }
89
+ set({ lastError: '' });
90
  get().fetchState();
91
  } catch (error) {
92
  console.error(`Error toggling simulation to ${!isRunning}:`, error);
93
+ set({ lastError: error.message || 'Unable to toggle the demo.' });
94
  }
95
  },
96
  stepSimulation: async () => {
97
  try {
98
+ const res = await fetch(`${API_BASE}/step`, { method: 'POST' });
99
+ if (!res.ok) {
100
+ throw new Error(`Step request failed (${res.status})`);
101
+ }
102
+ set({ lastError: '' });
103
  get().fetchState();
104
  } catch (error) {
105
  console.error('Error stepping simulation:', error);
106
+ set({ lastError: error.message || 'Unable to step the demo.' });
107
  }
108
  },
109
  }));