Advertisement
joelmaxuel

Quotes

Jun 3rd, 2021 (edited)
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.37 KB | None | 0 0
  1. ~$ cat bin/quotes
  2. #!/bin/sh
  3.  
  4. curl -s https://ca.finance.yahoo.com/quote/BTC-CAD/ | grep -Po '(currency\W{3}CAD\W{3}regularMarketPrice\W{4}raw\W{2})([\d\.]+)(\W{2}fmt)' | cut -d":" -f 4 | cut -d"," -f 1 | tail -1 | sed 's/^/BTC   /'
  5. curl -s https://ca.finance.yahoo.com/quote/ETH-CAD/ | grep -Po '(currency\W{3}CAD\W{3}regularMarketPrice\W{4}raw\W{2})([\d\.]+)(\W{2}fmt)' | cut -d":" -f 4 | cut -d"," -f 1 | tail -1 | sed 's/^/ETH   /'
  6. curl -s https://ca.finance.yahoo.com/quote/ADA-CAD/ | grep -Po '(currency\W{3}CAD\W{3}regularMarketPrice\W{4}raw\W{2})([\d\.]+)(\W{2}fmt)' | cut -d":" -f 4 | cut -d"," -f 1 | tail -1 | sed 's/^/ADA   /'
  7. curl -s https://ca.finance.yahoo.com/quote/DOGE-CAD/ | grep -Po '(currency\W{3}CAD\W{3}regularMarketPrice\W{4}raw\W{2})([\d\.]+)(\W{2}fmt)' | cut -d":" -f 4 | cut -d"," -f 1 | tail -1 | sed 's/^/DOGE /'
  8. curl -s https://ca.finance.yahoo.com/quote/XMR-CAD/ | grep -Po '(currency\W{3}CAD\W{3}regularMarketPrice\W{4}raw\W{2})([\d\.]+)(\W{2}fmt)' | cut -d":" -f 4 | cut -d"," -f 1 | tail -1 | sed 's/^/XMR   /'
  9.  
  10.  
  11. ~$ cat bin/wallets
  12. #!/bin/sh
  13.  
  14. # Update the current pricing; don't use file if there are errors
  15. quotes > /tmp/quotes.dl && cp /tmp/quotes.dl /tmp/quotes.txt
  16.  
  17. # This script is to be a cronjob; the display execution will be queued by `agenda`
  18.  
  19.  
  20. ~$ cat bin/wallets.R
  21. suppressMessages(library(tibble))
  22. suppressMessages(library(dplyr))
  23. suppressMessages(library(readr))
  24. suppressMessages(library(magrittr))
  25. #suppressWarnings()
  26. #suppressMessages()
  27.  
  28. suppressMessages(quotes <- read_tsv('/tmp/quotes.txt', col_names = c("Asset", "Now")))
  29. suppressMessages(balances <- read_tsv('/home/joel/bin/balances.txt', col_names = c("Asset", "Balance", "Then", "Wallet", "Seq")))
  30.  
  31. wallets <- balances %>% inner_join(quotes, by = 'Asset') %>% mutate(Value = Now * Balance) %>% mutate(Diff = (Now - Then) * Balance)
  32.  
  33. summary <- select(wallets, Asset, Balance, Value, Diff) %>% group_by(Asset) %>%
  34.   summarise(Balance = sum(Balance), Value = scales::dollar(sum(Value)), Diff = scales::dollar(sum(Diff))) %>% arrange(desc(Value))
  35.  
  36. print(summary)
  37.  
  38.  
  39. ~$ cat bin/balances.txt
  40. BTC 0.01234567  45073   Live    1
  41. BTC 0.00123456  45037   Cold    1
  42. ETH 0.12345678  1614    Live    1
  43. ADA 23.456789   2.13    Live    1
  44. ADA 12.345678   2.10    Live    2
  45. XMR 0.12345678  499.32  Live    1
  46. DOGE    12.34   0.6647  Live    1
  47.  
  48.  
  49. ~$ cat /tmp/quotes.txt
  50. BTC 45660.125
  51. ETH 3292.012
  52. ADA 2.0895991
  53. DOGE    0.45860082
  54. XMR 360.37152
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement