summaryrefslogtreecommitdiff
path: root/config.lua
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2021-05-31 06:11:22 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2021-05-31 06:11:22 -0700
commit18bde7391efb9c6bd6ea7846891ab5d16276a809 (patch)
tree237cc152edbdf934ed32e4c8c54c5ce97535e57f /config.lua
downloadstonks-18bde7391efb9c6bd6ea7846891ab5d16276a809.tar.gz
stonks-18bde7391efb9c6bd6ea7846891ab5d16276a809.tar.xz
initial importHEADmaster
A bit messy and missing error handling in some places.
Diffstat (limited to 'config.lua')
-rw-r--r--config.lua96
1 files changed, 96 insertions, 0 deletions
diff --git a/config.lua b/config.lua
new file mode 100644
index 0000000..8af2a1a
--- /dev/null
+++ b/config.lua
@@ -0,0 +1,96 @@
+stock = {
+ SPY = 100,
+ VTI = 10
+}
+crypto = {
+ BTC = 1.1,
+ ETH = 11,
+ LTC = 111
+}
+tda = {
+ account_id = "x",
+ client_id = "x",
+ token_path = "/path/to/token"
+}
+
+columns = {
+ {
+ "symbol", function(str, asset)
+ return colour_symbol(str, asset)
+ end
+ },
+ {
+ "usd_price", function(str, asset)
+ return colour_zeros(group_thousands(string.format("%.4f", str)))
+ end
+ },
+ {
+ "usd_change", function(str, asset)
+ return colour_change(string.format("%.2f%%", str))
+ end
+ },
+ {
+ "usd_total", function(str, asset)
+ return colour_zeros(group_thousands(string.format("%.2f", str)))
+ end
+ },
+ {
+ "btc_price", function(str, asset)
+ return colour_zeros(string.format("%.8f", str))
+ end
+ },
+ {
+ "btc_change", function(str, asset)
+ return colour_change(string.format("%.2f%%", str))
+ end
+ },
+ {
+ "btc_total", function(str, asset)
+ return colour_zeros(string.format("%.4f", str))
+ end
+ }
+}
+
+function group_thousands (str)
+ local n
+ repeat
+ str, n = string.gsub(str, "^(%d+)(%d%d%d)", "%1,%2")
+ until n == 0
+
+ return str
+end
+
+function colour_zeros (str)
+ local x, y = string.match(str, "(.*%.0?.-)(0*)$")
+ if y == "" then
+ return str
+ else
+ return x .. colour(y, "90")
+ end
+end
+
+function colour (str, code)
+ return string.format("\27[%sm%s\27[0m", code, str)
+end
+
+function colour_change (str)
+ if str:sub(1, 1) == "-" then
+ return colour(str, "31")
+ else
+ return colour(str, "32")
+ end
+end
+
+function colour_symbol (str, asset)
+ local t = get_asset_field(asset, "type")
+
+ if t == "STOCK" then
+ return colour(str, "1;36")
+ elseif t == "OPTION" then
+ return colour(str, "1;34")
+ elseif t == "CRYPTO" then
+ return colour(str, "1;33")
+ else
+ return colour(str, "1;35")
+ end
+end