aboutsummarylogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.SRCINFO2
-rw-r--r--PKGBUILD2
-rw-r--r--README.md11
-rw-r--r--main.c2
-rw-r--r--portfolio.c27
-rw-r--r--tick.131
6 files changed, 57 insertions, 18 deletions
diff --git a/.SRCINFO b/.SRCINFO
index c4b045a63769..e69c78bdf892 100644
--- a/.SRCINFO
+++ b/.SRCINFO
@@ -1,6 +1,6 @@
pkgbase = tick
pkgdesc = Command line stock and cryptocurrency portfolio tracker.
- pkgver = 1.7.0
+ pkgver = 1.7.1
pkgrel = 1
url = https://github.com/aokellermann/tick
arch = x86_64
diff --git a/PKGBUILD b/PKGBUILD
index b4c906ba8ae1..761047e0d487 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -1,7 +1,7 @@
# Maintainer: Antony Kellermann <aokellermann@gmail.com>
pkgname=tick
-pkgver=1.7.0
+pkgver=1.7.1
pkgrel=1
pkgdesc="Command line stock and cryptocurrency portfolio tracker."
arch=('x86_64')
diff --git a/README.md b/README.md
index 31d00e80647c..d189ee2ce6ef 100644
--- a/README.md
+++ b/README.md
@@ -20,6 +20,11 @@ For example, to add 3 shares of Tesla bought for $918.12 total, run
```bash
$ tick add tsla 3 918.12
```
+You can also specify the price per share instead of total spent:
+```bash
+$ tick add tsla 3 306.04ea
+```
+
The parameter "add" will add your input to the current portfolio, "rm" will
subtract from your current portfolio, and "set" will set your portfolio to
the input, discarding any existing data about that security. Trading costs/fees
@@ -33,7 +38,7 @@ To get info about your current holdings, run
$ tick check [symbol/crypto_id/all]
```
The string "all" will list your entire portfolio, as well as produce a grand
-total.
+total. Running "check" with no other arguments will also list your entire portfolio.
To get the top three news articles on a specific stock or cryptocurrency,
you can run
@@ -67,4 +72,6 @@ license for more information.
* Look for API to replace Morningstar for MUTF/OTCMKTS data, preferably with
intraday data
* Encrypt data
-* Debian/RPM package \ No newline at end of file
+* Debian/RPM package
+* List whether stock/etf/mutual fund/crypto/etc. in portfolio for less API calls
+and portfolio distribution \ No newline at end of file
diff --git a/main.c b/main.c
index cc765d3e0fc3..67d8cd4c9101 100644
--- a/main.c
+++ b/main.c
@@ -31,7 +31,7 @@ int main(int argc, char* argv[]) {
}
//Convert legacy porfolio
- if (argc == 2 && strcmp(argv[1], "convert") == 0){
+ if (argc == 2 && strcmp(argv[1], "convert") == 0) {
portfolio_legacy_convert();
free((void*) portfolio_file);
fclose(fp);
diff --git a/portfolio.c b/portfolio.c
index 89386ab5184a..8888ebff2def 100644
--- a/portfolio.c
+++ b/portfolio.c
@@ -18,11 +18,11 @@ char* portfolio_file_get_string(FILE* fp) {
}
void portfolio_modify(char* ticker_name_string, double quantity_shares, double usd_spent, FILE* fp, int option) {
- if (quantity_shares < 0 || usd_spent < 0){
+ if (quantity_shares < 0 || usd_spent < 0) {
printf("You must use positive values.\n");
return;
}
- if (option != SET && quantity_shares == 0 && usd_spent == 0){
+ if (option != SET && quantity_shares == 0 && usd_spent == 0) {
printf("You cannot add or remove values of 0.\n");
return;
}
@@ -41,7 +41,7 @@ void portfolio_modify(char* ticker_name_string, double quantity_shares, double u
json_object_put(jobj);
return;
}
- if (api_get_current_price(ticker_name_string) == NULL){
+ if (strcmp("USD$", ticker_name_string) != 0 && api_get_current_price(ticker_name_string) == NULL) {
printf("Invalid symbol.\n");
json_object_put(jobj);
free(portfolio_string);
@@ -62,7 +62,8 @@ void portfolio_modify(char* ticker_name_string, double quantity_shares, double u
if (option == SET) {
current_shares = quantity_shares;
current_spent = usd_spent;
- printf("Set amount of %s in portfolio to %lf bought for %lf.\n", ticker_name_string, quantity_shares, usd_spent);
+ printf("Set amount of %s in portfolio to %lf bought for %lf.\n", ticker_name_string, quantity_shares,
+ usd_spent);
} else if (option == ADD) {
current_shares += quantity_shares;
current_spent += usd_spent;
@@ -81,8 +82,10 @@ void portfolio_modify(char* ticker_name_string, double quantity_shares, double u
if (current_shares == 0 && usd_spent == 0) //deletes index from portfolio if values are 0
json_object_array_del_idx(jobj, (size_t) index, 1);
else {
- json_object_object_add(current_index, "Shares", json_object_new_double(round(current_shares * 100) / 100)); //adds computed values to index
- json_object_object_add(current_index, "USD_Spent", json_object_new_double(round(current_spent * 100) / 100));
+ json_object_object_add(current_index, "Shares", json_object_new_double(
+ round(current_shares * 100) / 100)); //adds computed values to index
+ json_object_object_add(current_index, "USD_Spent",
+ json_object_new_double(round(current_spent * 100) / 100));
}
}
fp = fopen(portfolio_file, "w");
@@ -185,7 +188,7 @@ char* portfolio_legacy_get_next_val(FILE* fp) {
char c;
for (int i = 0; i < 16; i++) {
c = (char) fgetc(fp);
- if (c == ' ' || c == '\n'|| feof(fp))
+ if (c == ' ' || c == '\n' || feof(fp))
break;
val[i] = c;
}
@@ -197,14 +200,16 @@ void portfolio_legacy_convert() {
char c = 0;
while (c != 'y' && c != 'n')
scanf("%c", &c);
- if (c == 'n'){
+ if (c == 'n') {
printf("Aborted.\n");
return;
}
- FILE* fp = fopen(portfolio_file, "a+");
+ FILE* fp = fopen(portfolio_file, "w");
char* pf = portfolio_file_get_string(fp);
if (strcmp(pf, "") != 0)
remove(portfolio_file);
+ fclose(fp);
+ fp = fopen(portfolio_file, "a+");
free(pf);
char* legacy_path = malloc(64);
strcpy(legacy_path, portfolio_file);
@@ -217,8 +222,6 @@ void portfolio_legacy_convert() {
}
char* symbol, * amount, * spent;
while (1) {
- if (feof(fp_legacy))
- break;
symbol = portfolio_legacy_get_next_val(fp_legacy);
amount = portfolio_legacy_get_next_val(fp_legacy);
spent = portfolio_legacy_get_next_val(fp_legacy);
@@ -226,6 +229,8 @@ void portfolio_legacy_convert() {
free(symbol);
free(amount);
free(spent);
+ if (feof(fp_legacy))
+ break;
}
printf("Successfully converted portfolio!\n");
fclose(fp_legacy);
diff --git a/tick.1 b/tick.1
index ff517f678448..a1fa83171a7d 100644
--- a/tick.1
+++ b/tick.1
@@ -13,7 +13,7 @@ Create your portfolio by adding your current holdings. Then, use the option "che
Portfolio:
.TP
-[add/rm/set] [symbol/crypto_id/USD$] [quantity of shares] [USD spent]
+[add/rm/set] [symbol/crypto_id/USD$] [quantity of shares] [USD spent/SharePriceEA]
Either adds, removes, or sets the amount of the given stock with respect to the given values. The parameter "add" will add
your input to the current portfolio, "rm" will subtract from your current portfolio, and "set" will set your portfolio to
the input, discarding any existing data about that security. Trading fees should be factored into "USD SPENT". As an exception,
@@ -22,11 +22,13 @@ US stock market and the cryptocurrency market. You may also input as "usd$" for
track of how much money is unallocated in your brokerage account. Typically, your initial amount of USD can be added as
"tick add USD$ [amount] [amount]", where [amount] is the same number. When you are paid dividends or capital gains that
are not reinvested into a specific security, you should update your portfolio with "tick add USD$ [dividend/capital gain amount] 0".
+You may also specify the share price instead of the total amount you spent by appending "ea" to the end of the share price.
.TP
[check] [currency name/crypto_id/all]
Prints information about your current portfolio holdings. Either a symbol or the keyword 'all' can be used. The keyword "all"
-will print information about all your current holdings, as well as a grand total.
+will print information about all your current holdings, as well as a grand total. Running only 'tick check' will do the same
+thing as 'tick check all'.
.TP
[convert]
@@ -43,6 +45,31 @@ will be displayed. If you would like to use a space in your search, you must eit
your phrase in double quotes. Technically, the input may be something completely unrelated to investing. This may be amended
in the future.
+.SH EXAMPLES
+To add 3 shares of Tesla bought for $918.12 total, run
+.RS
+$ tick add tsla 3 918.12
+
+.RE
+You can also specify the price per share instead of total spent:
+.RS
+$ tick add tsla 3 306.04ea
+
+.RE
+To get info about your current holdings in a Tesla, run
+.RS
+$ tick check tsla
+
+.RE
+Or to get info about all your holdings, run
+.RS
+$ tick check all
+
+.RE
+To get the top three news articles on Tesla in the past two weeks, run
+.RS
+$ tick news tesla
+
.SH FILES
.I ~/.tick_portfolio.json
.RS