Skip to content

Commit 9e08c79

Browse files
feat: hooks implemented (#76)
Closes #75
1 parent e30aaa6 commit 9e08c79

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { useState, useEffect } from 'react';
2+
import { api } from '../utils/api';
3+
export const useQuantData = () => {
4+
const [assets, setAssets] = useState([]);
5+
const [loading, setLoading] = useState(false);
6+
const [backtestResults, setBacktestResults] = useState(null);
7+
useEffect(() => {
8+
loadAssets();
9+
}, []);
10+
const loadAssets = async () => {
11+
try {
12+
const data = await api.getAssets();
13+
setAssets(data);
14+
}
15+
catch (error) {
16+
console.error('Failed to load assets:', error);
17+
}
18+
};
19+
const runBacktest = async (config) => {
20+
setLoading(true);
21+
try {
22+
const results = await api.runBacktest(config);
23+
setBacktestResults(results);
24+
}
25+
catch (error) {
26+
console.error('Backtest failed:', error);
27+
}
28+
finally {
29+
setLoading(false);
30+
}
31+
};
32+
return {
33+
assets,
34+
loading,
35+
backtestResults,
36+
runBacktest
37+
};
38+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { useState, useEffect } from 'react';
2+
3+
export const useQuantData = () => {
4+
const [assets, setAssets] = useState<any[]>([]);
5+
6+
useEffect(() => {
7+
loadAssets();
8+
}, []);
9+
10+
const loadAssets = async () => {
11+
// Mock data
12+
const mockAssets = [
13+
{ symbol: 'AAPL', name: 'Apple Inc.', sector: 'Technology', marketCap: 2800000000000, price: 182.63 },
14+
{ symbol: 'MSFT', name: 'Microsoft Corp.', sector: 'Technology', marketCap: 2750000000000, price: 370.73 },
15+
{ symbol: 'GOOGL', name: 'Alphabet Inc.', sector: 'Technology', marketCap: 1750000000000, price: 138.21 },
16+
];
17+
setAssets(mockAssets);
18+
};
19+
20+
return {
21+
assets,
22+
loading: false,
23+
backtestResults: null,
24+
runBacktest: async () => {} // Empty function for now
25+
};
26+
};

0 commit comments

Comments
 (0)