summaryrefslogtreecommitdiff
path: root/modeline/bitcoin/README.org
blob: 7d0d386999f6df56961142909e5b96dfa1f3d6fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
* Bitcoin

*THIS MODULE IS DEPRECATED, AND SUPERSEDED BY THE* =ticker= *MODULE*.

Show Bitcoin (₿) value in the modeline.

** Usage

Place the following in your =~/.stumpwmrc= file:

#+BEGIN_SRC lisp
  (load-module "bitcoin")
#+END_SRC

Then you can use =%b= in your mode line
format:

#+BEGIN_SRC lisp
  (setf *screen-mode-line-format*
        (list "[%n]"                      ; Groups
              "%v"                        ; Windows
              "^>"                        ; Push right
              " | %b"                     ; Bitcoin
              " | %d"))                   ; Clock
#+END_SRC

And define some parameters:

#+BEGIN_SRC lisp
  (setf bitcoin:*modeline-use-colors* t     ; use colors
        bitcoin:*threshold*           0.001 ; 0.001 is a 0.1% deviation from average
        bitcoin:*time-delay*          30    ; seconds
        bitcoin:*decimals*            2     ; number of decimal digits
        bitcoin:*local-code*          2     ; formatting code to use
        bitcoin:*modeline-gauge*      t     ; show gauge bar
        bitcoin:*gauge-width*         9)    ; width of the gauge bar in characters
#+END_SRC

It gets actual price through API, so needs =dexador= and =yason=. Also, the price getter is asynchronous with the =lparallel= machinery.

#+BEGIN_SRC lisp
  (ql:quickload '("dexador" "yason" "lparallel"))
#+END_SRC

** Notes

Price format is colorized depending on =*modeline-use-colors*=
flag. You can customize setting =t= or =nil= in =~/.stumpwmrc=:

#+BEGIN_SRC lisp
  (setf bitcoin:*modeline-use-colors* t) ; use colors
#+END_SRC

Colors depends on a comparison between actual value and the last
values average:

| Color         | Code    | Description                       |
|---------------+---------+-----------------------------------|
| Bright yellow | =^B^3*= | Price is higher than average      |
| Red           | =^1*=   | Price is below average            |
| White         | =^7*=   | Price is similar to average       |
| Default color | =^**=   | When *modeline-use-colors* is nil |

There is a threshold around average, so the increasing or decreasing
color is only applied if =*threshold*= is passed, can be customized too:

#+BEGIN_SRC lisp
  (setf bitcoin:*threshold* 0.001) ; 0.001 is a 0.1% deviation from average
#+END_SRC

Last values average is calculated over a 3 hours values list
=*values*=, where values are stored on every modeline refresh in a
FIFO fashion.

Connection to =*url*= price server is limited by a =*time-delay*=
interval, in seconds.  So connection attempts between interval time
are blocked. Interval can be customized too:

#+BEGIN_SRC lisp
  (setf bitcoin:*time-delay* 30) ; seconds
#+END_SRC

The number of decimal places is set by =*decimals*=, when =0= there is
no decimals.

#+BEGIN_SRC lisp
  (setf bitcoin:*decimals* 2) ; number of decimal digits
#+END_SRC

The localization format is set by =*local-code*=, when =0= there is no
thousand separator, gives =1234.56= and the =*decimals*= parameter
does not work, when =1= the thousand separator is =comma= and gives
=1,234.56=, when =2= the thousand separator is =period= and gives
=1.234,56=, and when =3= the thousand separator is =space= and gives
=1 234,56=. Can be customized too:

#+BEGIN_SRC lisp
  (setf bitcoin:*local-code* 2) ; formatting code to use
#+END_SRC

It is possible to add a gauge bar with the tendency of the actual value
between the low and high in the last 24 hours with =*modeline-gauge*=.
The gauge bar width is set by =*gauge-width*=.

#+BEGIN_SRC lisp
  (setf bitcoin:*modeline-gauge* t) ; show gauge bar
  (setf bitcoin:*gauge-width* 9)    ; width of the gauge bar in characters
#+END_SRC

** Issues

Try to use conditions' =handler-case= machinery to avoid the internet
timeouts or the computer sleeping process, to stuck the modeline.

The =truncate= function is used when formatting the values, so some
precission loss is expected.