aboutsummarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntony Kellermann2018-08-21 14:59:10 -0400
committerAntony Kellermann2018-08-21 14:59:10 -0400
commit0a2d44a19c65890a11081404c41b4b45d1e25003 (patch)
treed3d1a262afd64128a25de3349e397594e93e526e
parent2ffe874448a3a98eaff68c8a3fa996a313a92459 (diff)
downloadaur-0a2d44a19c65890a11081404c41b4b45d1e25003.tar.gz
Changed all functions to use batch
-rw-r--r--api.c15
-rw-r--r--api.h4
-rw-r--r--curses_win.c16
-rw-r--r--portfolio.c3
4 files changed, 27 insertions, 11 deletions
diff --git a/api.c b/api.c
index b29daab097cd..e904a58f8869 100644
--- a/api.c
+++ b/api.c
@@ -130,7 +130,7 @@ void iex_batch_store_data_info_array(Info_Array* pInfo_Array, Data_Level data_le
void iex_batch_store_data_info(Info* pInfo, Data_Level data_level) {
char* symbol_array = malloc(SYMBOL_MAX_LENGTH);
- free(symbol_array);
+ pointer_alloc_check(symbol_array);
strcpy(symbol_array, pInfo->symbol);
String* pString = iex_batch_get_data_string(&symbol_array, 1, data_level);
Json* jobj = json_tokener_parse(pString->data);
@@ -158,7 +158,9 @@ String* iex_batch_get_data_string(char* symbol_array[SYMBOL_MAX_LENGTH], size_t
strcpy(endpoints, "quote,chart,company,stats,peers,news,earnings&range=5y");
else if (data_level == CHECK)
strcpy(endpoints, "quote,chart");
- else strcpy(endpoints, "company,stats,peers,news,earnings&range=5y");
+ else if (data_level == MISC)
+ strcpy(endpoints, "company,stats,peers,news,earnings&range=5y");
+ else strcpy(endpoints, "news");
sprintf(iex_api_string,
"https://api.iextrading.com/1.0/stock/market/batch?symbols=%s&types=%s",
symbol_list_string, endpoints);
@@ -327,6 +329,15 @@ void api_info_array_store_data_batch(Info_Array* pInfo_Array, Data_Level data_le
info_array_store_totals(pInfo_Array);
}
+void api_info_store_data_batch(Info* pInfo, Data_Level data_level) {
+ iex_batch_store_data_info(pInfo, data_level);
+ if (pInfo->api_provider == EMPTY && alphavantage_store_info(pInfo) == NULL &&
+ coinmarketcap_store_info(pInfo) == NULL)
+ return;
+
+ info_store_check_data(pInfo);
+}
+
void info_store_check_data(Info* pInfo) {
if (pInfo->amount == EMPTY)
return;
diff --git a/api.h b/api.h
index 2fb01168b9c3..4192c8b65319 100644
--- a/api.h
+++ b/api.h
@@ -14,7 +14,7 @@
#define COINMARKETCAP 3
typedef enum data_level {
- ALL, CHECK, MISC
+ ALL, CHECK, MISC, NEWS
} Data_Level;
#define DATA_ALL 0
@@ -245,6 +245,8 @@ void* coinmarketcap_store_info(void* vpInfo);
*/
void api_info_array_store_data_batch(Info_Array* pInfo_Array, Data_Level data_level);
+void api_info_store_data_batch(Info* pInfo, Data_Level data_level);
+
/**
* After API data and portfolio have already been collected, uses them to populate the Info fields current_value and
* all the profit fields.
diff --git a/curses_win.c b/curses_win.c
index 6f1db2fca085..dc1fc9aa2738 100644
--- a/curses_win.c
+++ b/curses_win.c
@@ -162,7 +162,7 @@ void portfolio_print_stock(const char* symbol) {
Info* info = api_info_init();
strcpy(info->symbol, symbol);
- api_store_check_info(info);
+ api_info_store_data_batch(info, CHECK);
info->amount = json_object_get_double(json_object_object_get(json_object_array_get_idx(jobj, i), "Shares"));
info->total_spent = json_object_get_double(json_object_object_get(json_object_array_get_idx(jobj, i), "USD_Spent"));
@@ -181,10 +181,9 @@ void portfolio_print_stock(const char* symbol) {
}
void interface_print(const char* symbol) {
- Info_Array* pInfo_Array = api_info_array_init_from_length(1);
- Info* symbol_info = pInfo_Array->array[0];
+ Info* symbol_info = api_info_init();
strcpy(symbol_info->symbol, symbol);
- api_info_array_store_data_batch(pInfo_Array, ALL);
+ api_info_store_data_batch(symbol_info, ALL);
if (symbol_info->api_provider == EMPTY) {
api_info_destroy(&symbol_info);
RET_MSG("Invalid symbol.")
@@ -359,7 +358,8 @@ void news_print(const char* symbol, int num_articles) {
Info* symbol_info = api_info_init();
strcpy(symbol_info->symbol, symbol);
symbol_info->num_articles = num_articles;
- if (iex_store_news(symbol_info) == NULL) {
+ api_info_store_data_batch(symbol_info, NEWS);
+ if (symbol_info->api_provider == EMPTY) {
api_info_destroy(&symbol_info);
RET_MSG("Invalid symbol");
}
@@ -398,7 +398,8 @@ void peers_printw(WINDOW* window, const Info* symbol_info) {
void graph_print(const char* symbol, const char* symbol2) {
Info* symbol_info = api_info_init(), * symbol_info2 = NULL;
strcpy(symbol_info->symbol, symbol);
- if (api_store_check_info(symbol_info) == NULL) {
+ api_info_store_data_batch(symbol_info, CHECK);
+ if (symbol_info->api_provider == EMPTY) {
api_info_destroy(&symbol_info);
RET_MSG("Invalid symbol")
}
@@ -406,7 +407,8 @@ void graph_print(const char* symbol, const char* symbol2) {
if (symbol2 != NULL) {
symbol_info2 = api_info_init();
strcpy(symbol_info2->symbol, symbol2);
- if (api_store_check_info(symbol_info2) == NULL) {
+ api_info_store_data_batch(symbol_info2, CHECK);
+ if (symbol_info2->api_provider == EMPTY) {
api_info_destroy(&symbol_info);
api_info_destroy(&symbol_info2);
RET_MSG("Invalid symbol")
diff --git a/portfolio.c b/portfolio.c
index ed80b9ee1bc4..3d516bd4617c 100644
--- a/portfolio.c
+++ b/portfolio.c
@@ -82,7 +82,8 @@ int portfolio_modify_string(String* pString, const char* symbol, double quantity
if (strcmp("USD$", symbol) != 0) { // Check that the symbol is valid, except if it's USD
Info* data = api_info_init();
strcpy(data->symbol, symbol);
- if (api_store_check_info(data) == NULL) {// If NULL response from APIs, it's invalid
+ api_info_store_data_batch(data, CHECK);
+ if (data->api_provider == EMPTY) {// If NULL response from APIs, it's invalid
api_info_destroy(&data);
status = 1;
GOTO_CLEAN_MSG("Invalid symbol.")