diff options
-rw-r--r-- | api.c | 23 | ||||
-rw-r--r-- | api.h | 6 |
2 files changed, 29 insertions, 0 deletions
@@ -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; @@ -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 */ |