[taffybar] Add coinbase pro widgets

This commit is contained in:
Ivan Malison 2021-07-04 01:32:53 -06:00
parent 018cf09776
commit be87dc9dee
No known key found for this signature in database
GPG Key ID: 62530EFBE99DC2F8
3 changed files with 30 additions and 2 deletions

View File

@ -17,8 +17,9 @@ executable imalison-taffybar
-- ghc-options: -threaded -g -rtsopts
ghc-prof-options: -fprof-auto
build-depends: base
, X11>=1.8
, X11
, bytestring
, coinbase-pro
, containers
, directory
, filepath
@ -30,6 +31,8 @@ executable imalison-taffybar
, hslogger
, process
, split
, text
, time
, taffybar>=3.2.0
, transformers
, xdg-basedir

View File

@ -1,6 +1,12 @@
_: super: {
haskellPackages = super.haskellPackages.override (old: {
overrides = super.lib.composeExtensions (old.overrides or (_: _: {})) (self: _: {
coinbase-pro = self.callCabal2nix "coinbase-pro" (super.fetchFromGitHub {
owner = "IvanMalison";
repo = "coinbase-pro";
rev = "8ac93b7905150c8cbd6957102a730ecceb8b4dba";
sha256 = "0v0xw593xczvvalh24bz37v2zbfz92dhz71f04m08abgphqmjvxq";
}) { };
imalison-taffybar =
self.callCabal2nix "imalison-taffybar"
(

View File

@ -1,6 +1,11 @@
{-# LANGUAGE OverloadedStrings #-}
module Main where
import qualified CoinbasePro.Environment as CB
import qualified CoinbasePro.Headers as CB
import qualified CoinbasePro.Request as CB
import qualified CoinbasePro.Types as CB
import qualified CoinbasePro.Unauthenticated.API as CB
import Control.Exception.Base
import Control.Monad
import Control.Monad.IO.Class
@ -11,10 +16,13 @@ import Data.List
import Data.List.Split
import qualified Data.Map as M
import Data.Maybe
import qualified Data.Text
import Data.Time
import Network.HostName
import StatusNotifier.Tray
import System.Directory
import System.Environment
import System.Environment.XDG.BaseDir
import System.FilePath.Posix
import System.IO
import System.Log.Handler.Simple
@ -30,7 +38,6 @@ import System.Taffybar.Information.CPU
import System.Taffybar.Information.EWMHDesktopInfo
import System.Taffybar.Information.Memory
import System.Taffybar.Information.X11DesktopInfo
import System.Environment.XDG.BaseDir
import System.Taffybar.SimpleConfig
import System.Taffybar.Util
import System.Taffybar.Widget
@ -41,6 +48,14 @@ import System.Taffybar.Widget.Workspaces
import Text.Printf
import Text.Read hiding (lift)
getDaysCandles productString = do
oneDayAgo <- addUTCTime(-60*60*24) <$> getCurrentTime
let candles = CB.candles (CB.ProductId productString) (Just oneDayAgo) Nothing CB.Minute
CB.run CB.Production (candles CB.userAgent)
coinbaseProductLabel productString =
pollingLabelNew 60.0 $ Data.Text.pack . ((productString ++ ": ") ++) . show . CB.unPrice . CB.close . head <$> getDaysCandles (Data.Text.pack productString)
mkRGBA (r, g, b, a) = (r/256, g/256, b/256, a/256)
blue = mkRGBA (42, 99, 140, 256)
yellow1 = mkRGBA (242, 163, 54, 256)
@ -153,6 +168,10 @@ main = do
map (>>= buildContentsBox)
[ myClock
, sniTrayNew
, coinbaseProductLabel "ICP-USD"
, coinbaseProductLabel "ICP-BTC"
, coinbaseProductLabel "BTC-USD"
, coinbaseProductLabel "ETH-USD"
, cpuGraph
, memoryGraph
, networkGraphNew netCfg Nothing