aboutsummarylogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api.h52
-rw-r--r--portfolio.h77
-rw-r--r--rc4.h68
-rw-r--r--string-tick.h15
4 files changed, 142 insertions, 70 deletions
diff --git a/api.h b/api.h
index a7f5ffc834d9..20262330e670 100644
--- a/api.h
+++ b/api.h
@@ -29,14 +29,21 @@ struct info {
typedef struct info Info;
/**
- * Creates and returns an Info object
+ * Creates and returns an Info object. name and symbol are allocated 64 bytes. the doubles and long are set to EMPTY
* @return Info object
*/
Info* api_info_init(void);
/**
- * GETs data from API server and returns it in a String
- * @param url API url to GET
+ * writefunction for cURL HTTP GET/POST
+ * stolen from a nice man on stackoverflow
+ */
+size_t api_string_writefunc(void* ptr, size_t size, size_t nmemb, String* hString);
+
+/**
+ * If post_field is not NULL, performs a HTTP POST with the given parameters. Otherwise, performs a HTTP GET. Response
+ * data is stored and returned in a String.
+ * @param url API url to GET/POST
* @param post_field data needed for POST
* @return NULL if no response from server. Otherwise, String containing data.
*/
@@ -46,22 +53,17 @@ String* api_curl_data(char* url, char* post_field);
* Returns a double* containing the current price and yesterday's price of a stock or cryptocurrency.
* [0] = current intraday price
* [1] = last close price
- * Order:
+ * The function will first query IEX. If no response, it will query Morningstar. If no response, it will query
+ * Coinmarketcap. If Coinmarketcap returns NULL, the function returns NULL.
* 1. IEX -- NASDAQ/NYSE/NYSEARCA
* 2. Morningstar -- MUTF/OTCMKTS
* 3. Coinmarketcap -- CRYPTO
- * @param ticker_name_string symbol
+ * @param ticker_name_string security symbol or name to get prices of
* @return price data or NULL if invalid symbol
*/
double* api_get_current_price(const 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 and yesterday's price of a stock with data from IEX.
* Tested for NASDAQ, NYSE, and NYSEARCA listed stocks/ETFs.
* @param ticker_name_string symbol
@@ -87,26 +89,29 @@ double* morningstar_get_price(const char* ticker_name_string);
double* coinmarketcap_get_price(const char* ticker_name_string);
/**
- * Prints top three news articles in the past week based on the given string
- * @param ticker_name_string the string
+ * Prints the top three news articles by popularity pertaining to the given string, ticker_name_string. Spaces and
+ * underscores will be url-encoded (replaced by "%20"). News API will be used for data.
+ * @param ticker_name_string the string to query
*/
void news_print_top_three(const char* ticker_name_string);
/**
- * Given a JSON formatted string, print title, source, author, and url of articles
- * @param data the json formatted data
+ * Prints relevant information about up to three articles given a News API JSON formatted response object. Title, source,
+ * and URL will always be printed. The URL will be shortened by Google's URL-shortener API. If the author and date
+ * are specified, those will be printed as well.
+ * @param jobj the JSON array
*/
void json_print_news(Json* jobj);
/**
- * Prints info about the given symbol
- * @param ticker_name_string the symbol
+ * Prints information about the symbol ticker_name_string by calling the function json_print_news.
+ * @param ticker_name_string
*/
void api_print_info(const char* ticker_name_string);
/**
* Returns a pointer to an Info object containing info pertaining
- * to the given symbol
+ * to the given symbol with data from IEX.
* @param ticker_name_string stock/etf symbol
* @return Info object
*/
@@ -114,31 +119,30 @@ Info* iex_get_info(const char* ticker_name_string);
/**
* Returns a pointer to an Info object containing info pertaining
- * to the given symbol
+ * to the given symbol with data from Morningstar
* @param ticker_name_string mutf/otc symbol
* @return Info object
*/
Info* morningstar_get_info(const char* ticker_name_string);
/**
- * Returns a pointer to an Info object containing info pertaining
- * to the given crypto
+ * Returns a pointer to an Info object containing info pertaining to the given cryptocurrency from Coinmarketcap.
* @param ticker_name_string the crypto's name
* @return Info object
*/
Info* coinmarketcap_get_info(const char* ticker_name_string);
/**
- * Given a url, returns a shorter link using goo.gl
+ * Given a url, returns a shorter link using Google's URL-shortener API.
* @param url_string the link to shorten
* @return the shortened link
*/
char* google_shorten_link(const char* url_string);
/**
- * Destroys Info object and frees memory
+ * Destroys Info object and frees memory. Sets the pointer to the Info to NULL
* @param phInfo the Info to destroy
*/
-void api_info_destroy(Info** phString);
+void api_info_destroy(Info** phInfo);
#endif \ No newline at end of file
diff --git a/portfolio.h b/portfolio.h
index fe50b16ff1c7..8e3d6cfadd8f 100644
--- a/portfolio.h
+++ b/portfolio.h
@@ -12,49 +12,80 @@
extern char* portfolio_file;
/**
- * Sets portfolio_file to $HOME/.tick_portfolio.json
+ * Postcondition: the char* portfolio_file (the "portfolio") is allocated on the heap and contains the
+ * path "$HOME/.tick_portfolio.json"
*/
void portfolio_file_init(void);
/**
- * Stores the given file in a string and returns it
- * @param fp the file
- * @param len sets *len to the size of the string -- used for decryption (some chars will be encrypted to '\0', so
- * the returned string will be null terminated somewhere in the middle several times
- * @return the string containing the file
+ * Precondition: portfolio_file has been initialized
+ * @return pointer to a allocated String containing the contents of the portfolio or NULL on error opening
+ * or reading portfolio
*/
String* portfolio_file_get_string(void);
/**
- * Adds quantity_shares of given symbol at given price to portfolio
- * @param id name of currency
- * @param quantity_shares quantity_shares of currency
- * @param purchase_price quantity_shares of money spent
- * @param fp portfolio file
+ * Precondition: portfolio_file has been initialized
+ * Postcondition: the portoflio has been modified according to the functions arguments
+ *
+ * The portfolio is formatted in JSON. Each security is an object in an array. Each object contains the following
+ * keys: "Symbol" (string), "Shares" (double), and "USD_Spent" (double).
+ *
+ * If the portfolio is empty, creates a new JSON array with it's only index being a JSON object containing
+ * ticker_name_string, quantity_shares, and usd_spent as it's attributes.
+ *
+ * If the security is NOT already in the portfolio, checks if ticker_name_string is a valid security. If it is,
+ * appends to the JSON array a new object containing the keys specified above.
+ *
+ * If the security IS already in the portfolio, modifies the values "Shares" and "USD_Spent" according to
+ * the parameter option. SET will set the values to the parameters quantity_shares and usd_spent, REMOVE will
+ * subtract the parameters from the values already in the portfolio, and ADD will add the parameters to the values
+ * already in the portfolio.
+ *
+ * Adding or removing when quantity_shares and usd_spent are both 0 will abort the function, as well as trying to
+ * remove more than is already contained in the portfolio. Negative numbers aren't allowed either.
+ *
+ * If the portfolio is encrypted, ask for the password to decrypt it. If invalid password, abort the function. If
+ * valid password, perform the functions specified above. After this, re-encrypt the portfolio using the already
+ * given password.
+ *
+ * After all this, overwrite the portfolio with the (encrypted or not) created/modified JSON array.
+ *
+ * @param ticker_name_string string containing the symbol of the security to add or name of the cryptocurrency
+ * @param quantity_shares the number of shares to modify the portfolio by
+ * @param usd_spent the amount of USD to modify the portfolio by
+ * @param option SET, REMOVE, or ADD
*/
void portfolio_modify(const char* ticker_name_string, double quantity_shares, double usd_spent, int option);
/**
- * Prints current holdings of all symbols
- * @param api_data STRING to hold data in
- * @param crypto_data JSON to hold STRING data in
- * @param fp portfolio file
+ * Precondition: portfolio_file has been initialized
+ * Prints to stdout information about every security contained in the portfolio: symbol, number of shares, USD spent,
+ * current value, profit, and 24h profit. Additionally, print a grand total with info from all securities.
+ *
+ * If the portfolio is encrypted, ask for the password and store the decrypted portfolio, but do not write to the file.
*/
void portfolio_print_all(void);
/**
- * Prints current holdings of a symbol
- * @param id name of currency, NULL if printing all
- * @param fp portfolio file, NULL if printing all
- * @param current_index portfolio file index, NULL if printing one
+ * Precondition: portfolio_file has been initialized
+ * Prints to stdout information about every security contained in the portfolio: symbol, number of shares, USD spent,
+ * current value, profit, and 24h profit.
+ * @param ticker_name_string the security to print or NULL is passing in JSON index
+ * @param current_index JSON index to print or NULL if passing in security's name or symbol
+ * @return double array containing the indices:
+ * [0] -- current balance
+ * [1] -- amount spent
+ * [2] -- 24h gain
*/
double* portfolio_print_stock(char* ticker_name_string, Json* current_index);
/**
- * Returns the index in the Json array of the given symbol
- * @param ticker_name_string the symbol
- * @param jarray the array
- * @return -1 if not found, the index otherwise
+ * Goes through the given JSON array until the JSON object at the given index's key "Symbol" contains
+ * the string ticker_name_string, then returns that index number.
+ * @param ticker_name_string the security to return the index of
+ * @param jarray the JSON array
+ * @return -1 if not found, the index number otherwise
*/
int portfolio_symbol_index(const char* ticker_name_string, Json* jarray);
diff --git a/rc4.h b/rc4.h
index 5e864db0f39b..7f6a9eec428f 100644
--- a/rc4.h
+++ b/rc4.h
@@ -13,43 +13,77 @@
#include "string-tick.h"
/**
- * Takes a password from user input and returns it (max 32 chars)
- * @return password
+ * Returns a password string taken from user input with a maximum of 32 characters. The user's input
+ * should not be echoed in the terminal, so ncurses noecho() function should be used.
+ * @return the password taken from input
*/
char* rc4_getPassword(void);
/**
- * Performs key exchange
- * @param keySchedule
- * @param key password
+ * Precondition: keySchedule is an int array of size 256 and key is a valid string
+ * Postcondition: keySchedule values have been initialized by the RC4 key-scheduling algorithm.
+ * Performs the RC4 key exchange with keylength 256. Pseudocode example:
+ * for i from 0 to 255
+ * S[i] := i
+ * endfor
+ * j := 0
+ * for i from 0 to 255
+ * j := (j + S[i] + key[i mod keylength]) mod 256
+ swap values of S[i] and S[j]
+ * endfor
+ *
+ * @param keySchedule int array of size keylength
+ * @param key user given password
*/
void rc4_key_exchange(int keySchedule[KEY_SCHEDULE_LENGTH], char* key);
/**
- * Performs pseudo-random generation algorithm
- * @param keySchedule
+ * Precondition: keySchedule is an int array of size 256 already initialized by the RC4 key-scheduling algorithm
+ * Performs the RC4 pseudo-random generation algorithm with keylength 256. Returns a string of length len with output
+ * frm this algorithm. Pseudocode example:
+ * i := 0
+ * j := 0
+ * while GeneratingOutput:
+ * i := (i + 1) mod 256
+ * j := (j + S[i]) mod 256
+ * swap values of S[i] and S[j]
+ * K := S[(S[i] + S[j]) mod 256]
+ * output K
+ * endwhile
+ *
+ * @param keySchedule int array of size keylength (already initialized)
* @param len size of portfolio in bytes
- * @return string that can be XOR'ed with message to be en/decoded
+ * @return string of size len that can be XOR'ed with message to be en/decoded
*/
char* rc4_prga(int keySchedule[KEY_SCHEDULE_LENGTH], size_t len);
/**
- * XOR's the string created by prga by the portfolio to encrypt or decrypt it
- * @param output string to be XOR'ed
- * @param message portoflio string
- * @param len length of portfolio in bytes
+ * Precondition: output is a string containing the output of the RC4 pseudo-random generation algorithm. pString
+ * is a String object containing the portfolio.
+ * XOR's the each index of output by each index of the char* in pString and stores that in the index of output
+ * @param output string
+ * @param message portoflio String
*/
void rc4_execute(char* output, String* pString);
/**
- * Returns an either encrypted or decrypted string of the input
- * @param input the string to encrypt or decrypt
- * @param input_len the length of the string
- * @param password the password to encrypt or decrypt with
- * @return encrypted or decrypted string
+ * Returns an encoded string given a String object and password used to encode it.
+ * @param pString The String to encode.
+ * @param password the key used to encode
+ * @return encoded string
*/
char* rc4_encode_string(String* pString, char* password);
+/**
+ * Given input input_pString, returns an encrypted or decrypted version of it. If trying to encrypt a non-JSON
+ * formatted input_pString, abort. Similarly, if trying to decrypt a JSON-formatted input_pString, abort. password may
+ * be a string or NULL. If NULL, get a password from the user if encrypting, ask for the password again to confirm
+ * inputs are the same. If decrypting and the decrypted String is not JSON formatted, abort (wrong password).
+ * @param input_pString the String to encrypt/decrypt
+ * @param password the key or NULL
+ * @param option ENCRYPT or DECRYPT
+ * @return encrypted or decrypted String
+ */
String* rc4_get_crypted_string(String* input_pString, char* password, int option);
#endif \ No newline at end of file
diff --git a/string-tick.h b/string-tick.h
index 1397ee3fb2ef..7f6785a8e970 100644
--- a/string-tick.h
+++ b/string-tick.h
@@ -16,36 +16,39 @@ typedef struct string String;
typedef struct json_object Json;
/**
- * Creates and returns a STRING
- * object with size 1 and no data
+ * Creates and returns a String object with len 1 and no data
* @return STRING object
*/
String* string_init(void);
/**
- * Changes letters in a string to lowercase
+ * Changes letters in a string to lowercase in place
* @param str the string
*/
void strtolower(char* str);
/**
- * Changes letters in a string to uppercase
+ * Changes letters in a string to uppercase in place
* @param str the string
*/
void strtoupper(char* str);
/**
- * Returns the input string, stripped of the given char
+ * Returns the input string, stripped of the given char c in place
* @param string the string to strip the char from
* @param c the char to strip
* @return input string
*/
char* strip_char(char* string, char c);
+/**
+ * Overwrites the portfolio with the given pString
+ * @param pString the String to overwrite with
+ */
void string_write_portfolio(String* pString);
/**
- * Destroys String object and frees memory
+ * Destroys String object and frees memory. Points the String to NULL.
* @param phString the String to destroy
*/
void string_destroy(String** phString);