aboutsummarylogtreecommitdiffstats
path: root/api.h
blob: 268568fafd219a221ff5eb7c445b8e43c01344d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
 * API data is taken from IEX Trading and Alpha Vantage
 * https://iextrading.com/developer/docs/
 * https://www.alphavantage.co/documentation/
 */

#ifndef IEX_H
#define IEX_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <curl/curl.h>
#include <stddef.h>

struct string {
    char* data;
    size_t len;
};

typedef struct string String;

/**
 * Creates and returns a STRING
 * object with size 1 and no data
 * @return STRING object
 */
String* api_string_init(void);

/**
 * GETs data from API server and returns it in a String
 * @param url API url to GET
 * @return NULL if no response from server. Otherwise, String containing data.
 */
String* api_curl_data(char* url);

/**
 * Returns current price of a stock
 * @param ticker_name_string symbol
 * @return current price of stock
 */
double api_get_current_price(char* ticker_name_string);

/**
 * writefunction for cURL HTTP GET
 * stolen from a nice man on stackoverflow
 */
size_t api_string_writefunc(void* ptr, size_t size, size_t nmemb, String* hString);

/**
 * Returns current price of a stock with data from IEX.
 * Tested for NASDAQ, NYSE, and NYSEARCA listed stocks/ETFs.
 * Fast -- should take less than one second per call
 * @param ticker_name_string symbol
 * @return current price of stock
 */
double iex_get_current_price(char* ticker_name_string);

/**
 * Returns current price of a stock.
 * If the symbol is not on IEX, Alpha Vantage will be used
 * Tested for MUTF and OTCMKTS listed securities.
 * Dreadfully slow -- may take up to ten seconds per call
 * @param ticker_name_string symbol
 * @return current price of stock
 */
double alphavantage_get_current_price(char* ticker_name_string);


double coinmarketcap_get_current_price(char* ticker_name_string);

/**
 * Destroys STRING object and frees memory
 * @param phString the String to destroy
 */
void api_string_destroy(String** phString);

#endif