From be87dc9dee3b59c4f6587289421bb4faf0d6adc0 Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Sun, 4 Jul 2021 01:32:53 -0600 Subject: [PATCH] [taffybar] Add coinbase pro widgets --- .../config/taffybar/imalison-taffybar.cabal | 5 ++++- dotfiles/config/taffybar/overlay.nix | 6 ++++++ dotfiles/config/taffybar/taffybar.hs | 21 ++++++++++++++++++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/dotfiles/config/taffybar/imalison-taffybar.cabal b/dotfiles/config/taffybar/imalison-taffybar.cabal index 4545bae1..ad64687b 100644 --- a/dotfiles/config/taffybar/imalison-taffybar.cabal +++ b/dotfiles/config/taffybar/imalison-taffybar.cabal @@ -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 diff --git a/dotfiles/config/taffybar/overlay.nix b/dotfiles/config/taffybar/overlay.nix index cc2b1d2f..a5ea0580 100644 --- a/dotfiles/config/taffybar/overlay.nix +++ b/dotfiles/config/taffybar/overlay.nix @@ -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" ( diff --git a/dotfiles/config/taffybar/taffybar.hs b/dotfiles/config/taffybar/taffybar.hs index a69b9d26..2f66469f 100644 --- a/dotfiles/config/taffybar/taffybar.hs +++ b/dotfiles/config/taffybar/taffybar.hs @@ -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