Skip to content

Commit

Permalink
Handle too many market data requests gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
bleunguts committed Jan 27, 2024
1 parent 8cc6010 commit 45e5ecf
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions Web/src/TradingStrategyStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,43 @@ export class TradingStrategyStore
);
}

error = () => {
this.symbol = `ERROR LOADING SYMBOL..`;
this.data = FakeStrategyPlaceholder;
};

loadChartData(symbol: string) {
try {
this.isLoading = true;
runInAction(() => {
this.transport
.fetchLongShortStrategy(symbol)
.then((res) => this.data = ((res as AxiosResponse<never, never>).data as ChartData[]))
.then((res) => {
const resp = (res as AxiosResponse<never, never>);
switch(resp.status) {
case 204: {
const cache = cachedData(symbol);
if(cache != undefined){
this.data = cache as ChartData[];
} else {
this.error();
}
break;
}
case 500: {
this.error();
break;
}
default: {
this.data = (resp.data as ChartData[]);
break;
}
}
})
.catch((e) => {
console.log(`Error occurred whilst loading new symbol... ${e}`);
console.log(e);
const cache = cachedData(symbol);
if (cache != undefined){
this.data = cache as ChartData[];

} else {
this.symbol = `ERROR LOADING SYMBOL..`;
this.data = FakeStrategyPlaceholder;
}
this.error();
});

console.log(`Symbol: ${symbol} loaded, data length: ${this.data.length}`);
Expand Down

0 comments on commit 45e5ecf

Please sign in to comment.