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