Skip to content

Commit

Permalink
Wire up strategize button to backend
Browse files Browse the repository at this point in the history
  • Loading branch information
bleunguts committed Jan 27, 2024
1 parent e78494b commit f5656de
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
29 changes: 16 additions & 13 deletions Web/src/TradingStrategyStore.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { RootStore } from "./RootStore";
import { BackenedApi } from "./api";
import { reaction, runInAction, makeAutoObservable } from 'mobx';
import { FakeStrategyBTCUSD as FakeStrategyBTCUSDData, FakeStrategyChartData, FakeStrategyIBMData, FakeStrategyPlaceholder } from "./components/layout/DummyData";
import { FakeStrategyPlaceholder } from "./components/layout/DummyData";
import { AxiosResponse } from "axios";

export interface ChartData {
time: string,
Expand Down Expand Up @@ -35,10 +36,12 @@ export class TradingStrategyStore
loadChartData(symbol: string) {
try {
this.isLoading = true;
const data = fetchData(symbol);
runInAction(() => {
console.log(`Symbol: ${symbol} loaded, data length: ${data.length}`);
this.data = data;
this.transport
.fetchLongShortStrategy(symbol)
.then((res) => this.data = ((res as AxiosResponse<never, never>).data as ChartData[]));

console.log(`Symbol: ${symbol} loaded, data length: ${this.data.length}`);
})
}
catch(e) {
Expand All @@ -52,13 +55,13 @@ export class TradingStrategyStore
}
}

function fetchData(symbol: string): ChartData[] {
switch(symbol)
{
case 'AAPL': return FakeStrategyChartData;
case 'IBM' : return FakeStrategyIBMData;
case 'BTCUSD' : return FakeStrategyBTCUSDData;
default: throw new Error(`Cannot load data for symbol ${symbol}`);
}
}
// function fetchData(symbol: string): ChartData[] {
// switch(symbol)
// {
// case 'AAPL': return FakeStrategyChartData;
// case 'IBM' : return FakeStrategyIBMData;
// case 'BTCUSD' : return FakeStrategyBTCUSDData;
// default: throw new Error(`Cannot load data for symbol ${symbol}`);
// }
// }

6 changes: 6 additions & 0 deletions Web/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface BackenedApi {
fetchHealthCheck(): Promise<string | AxiosResponse<unknown,unknown>>,
fetchHighestGainerStocks(limitRows: number): Promise<AxiosResponse<unknown,unknown>>,
fetchMostActiveStocks(limitRows: number): Promise<AxiosResponse<unknown,unknown>>,
fetchLongShortStrategy(ticker: string): Promise<AxiosResponse<unknown,unknown>>,
submitFxRateSubscribeRequest(ccyName: string): Promise<AxiosResponse<unknown,unknown>>,
submitFxRateUnsubscribeRequest(ccyName: string): Promise<AxiosResponse<unknown,unknown>>,
startHub(): void,
Expand All @@ -58,6 +59,11 @@ const api: BackenedApi = {
console.log(`Fetching from ${endpoint}`);
return await axios.get(endpoint);
},
fetchLongShortStrategy: async (ticker: string) => {
const endpoint = `${backendServer}/BacktestService/LongShortStrategy?ticker=${ticker}&fromDate=2023-05-01&toDate=2023-09-25&notional=10000`;
console.log(`Fetching from ${endpoint}`);
return await axios.get(endpoint);
},
submitFxRateSubscribeRequest: async (ccyName: string) => {
const requestId = uuidv1();
const body = {
Expand Down
1 change: 0 additions & 1 deletion Web/src/components/layout/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as React from 'react';
import Toolbar from '@mui/material/Toolbar';
import Button from '@mui/material/Button';
import IconButton from '@mui/material/IconButton';
import SearchIcon from '@mui/icons-material/Search';
import Typography from '@mui/material/Typography';
Expand Down
2 changes: 0 additions & 2 deletions Web/src/components/layout/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import * as React from 'react';
import Grid from '@mui/material/Grid';
import Stack from '@mui/material/Stack';
import Paper from '@mui/material/Paper';
import Typography from '@mui/material/Typography';
import Link from '@mui/material/Link';
import FxTicker from './FxTicker';
import StockNews from './StockNews';

Expand Down
3 changes: 2 additions & 1 deletion Web/src/components/layout/StockNews.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ export default function StockNews() {
getMostActiveStocks([]);
};
const handleStrategizeFrom = (symbol: string) => {
console.log(`Button clicked for ${symbol}.`);
setStockSymbol(symbol);
handleStrategize();
tradingStrategyStore.symbol = symbol;
};
const handleStrategize = () => {
console.log(`Strategizing target: ${stockSymbol} ...`);
Expand Down

0 comments on commit f5656de

Please sign in to comment.