1- import axios from " axios" ;
2-
3- export const FETCH_FOREX_SUCCESS = " FETCH_FOREX_SUCCESS" ;
4- export const FETCH_CHART_ERROR = " FETCH_CHART_ERROR" ;
5- export const SET_LOADING = " SET_LOADING" ;
6- export const SET_LOADING_TRUE = " SET_LOADING_TRUE" ;
7- export const CHANGE_MARKET_TYPE = " CHANGE_MARKET_TYPE" ;
8- export const CHANGE_MARKET_NAME = " CHANGE_MARKET_NAME" ;
9- export const SET_MARKET_DETAIL = " SET_MARKET_DETAIL" ;
10- export const SET_CHART_DATA = " SET_CHART_DATA" ;
11- export const CLEAN_CHART_DATA = " CLEAN_CHART_DATA" ;
12- export const SET_CHART_TIME_FRAME = " SET_CHART_TIME_FRAME" ;
13- export const SET_RATING = " SET_RATING" ;
14- export const SET_HOME_CHART_DATA = " SET_HOME_CHART_DATA" ;
15- export const CLEAN_STATE = " CLEAN_STATE" ;
16- export const GET_SEARCH_RESULTS = " GET_SEARCH_RESULTS" ;
17- export const SET_SEARCH_MARKET_DETAIL = " SET_SEARCH_MARKET_DETAIL" ;
18- export const CLEAR_SEARCH_RESULTS = " CLEAR_SEARCH_RESULTS" ;
19- export const OPEN_SEARCH_MODAL = " OPEN_SEARCH_MODAL" ;
20- export const CLOSE_SEARCH_MODAL = " CLOSE_SEARCH_MODAL" ;
21- export const TOGGLE_SEARCH_MODAL = " TOGGLE_SEARCH_MODAL" ;
1+ import axios from ' axios' ;
2+
3+ export const FETCH_FOREX_SUCCESS = ' FETCH_FOREX_SUCCESS' ;
4+ export const FETCH_CHART_ERROR = ' FETCH_CHART_ERROR' ;
5+ export const SET_LOADING = ' SET_LOADING' ;
6+ export const SET_LOADING_TRUE = ' SET_LOADING_TRUE' ;
7+ export const CHANGE_MARKET_TYPE = ' CHANGE_MARKET_TYPE' ;
8+ export const CHANGE_MARKET_NAME = ' CHANGE_MARKET_NAME' ;
9+ export const SET_MARKET_DETAIL = ' SET_MARKET_DETAIL' ;
10+ export const SET_CHART_DATA = ' SET_CHART_DATA' ;
11+ export const CLEAN_CHART_DATA = ' CLEAN_CHART_DATA' ;
12+ export const SET_CHART_TIME_FRAME = ' SET_CHART_TIME_FRAME' ;
13+ export const SET_RATING = ' SET_RATING' ;
14+ export const SET_HOME_CHART_DATA = ' SET_HOME_CHART_DATA' ;
15+ export const CLEAN_STATE = ' CLEAN_STATE' ;
16+ export const GET_SEARCH_RESULTS = ' GET_SEARCH_RESULTS' ;
17+ export const SET_SEARCH_MARKET_DETAIL = ' SET_SEARCH_MARKET_DETAIL' ;
18+ export const CLEAR_SEARCH_RESULTS = ' CLEAR_SEARCH_RESULTS' ;
19+ export const OPEN_SEARCH_MODAL = ' OPEN_SEARCH_MODAL' ;
20+ export const CLOSE_SEARCH_MODAL = ' CLOSE_SEARCH_MODAL' ;
21+ export const TOGGLE_SEARCH_MODAL = ' TOGGLE_SEARCH_MODAL' ;
2222
2323export const toggleSearchModal = ( ) => ( {
2424 type : TOGGLE_SEARCH_MODAL ,
@@ -107,22 +107,22 @@ export const fetchChartError = (error) => ({
107107 payload : error ,
108108} ) ;
109109
110- export const fetchForex = ( market ) => async ( dispatch ) => {
110+ export const fetchForex = ( markets ) => async ( dispatch ) => {
111+ const marketArray = markets . split ( ',' ) . sort ( ) ;
112+ let forexList = [ ] ;
113+
114+ // FMP API changed its services. Before I could make a batch request
115+ // for getting quites. Now they dont let free account do it.
116+ // So I had to find a workaround for that with looping the free endpoint.
111117 try {
112- const response = await axios . get (
113- `https://financialmodelingprep.com/api/v3/quote/${ market } ?apikey=${ process . env . REACT_APP_CHART_KEY } `
114- ) ;
115- const data = await response . data ;
116- // FinancialModel API doesn't send error if it's about limit reach.
117- // In that sense, they send an error message with 200 status. Weird.
118- // Thats why I am catching that error here and dispatching it.
119- if ( data . length ) {
120- return data . length === 1
121- ? [ dispatch ( setSearchMarketDetail ( data ) ) ]
122- : [ dispatch ( fetchForexSuccess ( data ) ) ] ;
123- } else {
124- return dispatch ( fetchChartError ( data ) ) ;
118+ for ( let market of marketArray ) {
119+ const response = await axios . get (
120+ `https://financialmodelingprep.com/api/v3/quote/${ market } ?apikey=${ process . env . REACT_APP_CHART_KEY } `
121+ ) ;
122+ const data = await response . data ;
123+ forexList . push ( data ) ;
125124 }
125+ return dispatch ( fetchForexSuccess ( forexList ) ) ;
126126 } catch ( error ) {
127127 return dispatch ( fetchChartError ( error ) ) ;
128128 }
@@ -161,12 +161,13 @@ Plus, its so clean!
161161Yet another homerun for me! 😁😎
162162*/
163163export const fetchHomeChart = ( symbols ) => async ( dispatch ) => {
164- const symbolsArray = symbols . split ( "," ) . sort ( ) ;
164+ const symbolsArray = symbols . split ( ',' ) . sort ( ) ;
165165
166166 let charts = [ ] ;
167167
168168 dispatch ( cleanState ( ) ) ;
169169 dispatch ( setLoadingTrue ( ) ) ;
170+
170171 try {
171172 for ( let symbol of symbolsArray ) {
172173 const response = await axios . get (
@@ -175,7 +176,6 @@ export const fetchHomeChart = (symbols) => async (dispatch) => {
175176 const data = await response . data ;
176177 charts . push ( data ) ;
177178 }
178-
179179 return [ dispatch ( setHomeChartData ( charts ) ) , dispatch ( setLoading ( ) ) ] ;
180180 } catch ( error ) {
181181 return dispatch ( fetchChartError ( error ) ) ;
0 commit comments