aboutsummarylogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api.c23
-rw-r--r--api.h6
2 files changed, 29 insertions, 0 deletions
diff --git a/api.c b/api.c
index d686e373270d..108a7fffb926 100644
--- a/api.c
+++ b/api.c
@@ -546,6 +546,29 @@ Info* api_get_info(const char* symbol) {
return coinmarketcap_get_info(symbol);
}
+Info_Array* iex_get_valid_symbols(void) {
+ char* iex_api_string = "https://api.iextrading.com/1.0/ref-data/symbols";
+ String* pString = api_curl_data(iex_api_string);
+ if (pString == NULL)
+ return NULL;
+
+ Json* jobj = json_tokener_parse(pString->data), * idx;
+ Info_Array* list = api_info_array_init();
+ list->length = json_object_array_length(jobj);
+ list->array = malloc(sizeof(Info*) * list->length);
+ pointer_alloc_check(list->array);
+ for (size_t i = 0; i < list->length; i++) {
+ list->array[i] = api_info_init();
+ idx = json_object_array_get_idx(jobj, i);
+ strcpy(list->array[i]->symbol, json_object_get_string(json_object_object_get(idx, "symbol")));
+ strcpy(list->array[i]->name, json_object_get_string(json_object_object_get(idx, "name")));
+ }
+
+ json_object_put(jobj);
+ string_destroy(&pString);
+ return list;
+}
+
void api_news_destroy(News** phNews) {
free(*phNews);
*phNews = NULL;
diff --git a/api.h b/api.h
index 3dd07c159dd5..6b76676a89b4 100644
--- a/api.h
+++ b/api.h
@@ -290,6 +290,12 @@ Info* api_get_check_info(const char* symbol);
Info* api_get_info(const char* symbol);
/**
+ * Returns a pointer to an Info_Array containing a list of all iex listed securities.
+ * @return Info_Array*
+ */
+Info_Array* iex_get_valid_symbols(void);
+
+/**
* Destroys News object and frees memory. Sets the pointer of the News to NULL
* @param phNews the News to destroy
*/