forked from tensaix2j/cryptotickers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cryptotickers.tcl
117 lines (91 loc) · 2.51 KB
/
cryptotickers.tcl
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
#---------------------
proc response { sock } {
foreach curr [ list \
BTC \
ETH \
NEO \
BNB \
WTC \
DICE \
GNT \
OAX \
DGB \
CVC \
XLM \
STEEM \
XRP \
SC \
BET \
EOS \
SYS \
OMG \
PLR \
ETC \
LTC \
SALT \
QTUM \
ARK \
BCH \
PAY \
NAV \
LINK \
XMR \
BTG \
KCS \
CLUB \
] {
set price_in_btc 0.00000000
set price_in_usd 0.00
set price_in_eth 0.00000000
set price_in_sgd 0.00
if { [ info exists ::rate(last,BTCUSD) ] } {
set BTCUSD $::rate(last,BTCUSD)
} elseif { [ info exists ::rate(last,BTCUSDT) ] } {
set BTCUSD $::rate(last,BTCUSDT)
}
if { [ info exists ::rate(last,ETHBTC) ] } {
set ETHBTC $::rate(last,ETHBTC)
}
if { [ info exists ::rate(provider,${curr}BTC) ] } {
set provider $::rate(provider,${curr}BTC)
} elseif { [ info exists ::rate(provider,${curr}ETH) ] } {
set provider $::rate(provider,${curr}ETH)
} elseif { $curr == "BTC" } {
set provider "bittrex"
}
if { [ info exists BTCUSD ] } {
if { $curr == "BTC" } {
set price_in_btc 1.0
set price_in_usd $BTCUSD
set price_in_eth [ expr 1.0 / $ETHBTC ]
} elseif { [ info exists ::rate(last,${curr}BTC) ] } {
set price_in_btc $::rate(last,${curr}BTC)
set price_in_usd [ expr $price_in_btc * $BTCUSD ]
if { [ info exists ::rate(last,${curr}ETH) ] } {
set price_in_eth $::rate(last,${curr}ETH)
} else {
set price_in_eth [ expr $price_in_btc / $ETHBTC ]
}
} elseif { [ info exists ::rate(last,${curr}ETH) ] } {
set price_in_eth $::rate(last,${curr}ETH)
set price_in_btc [ expr $price_in_eth * $ETHBTC ]
set price_in_usd [ expr $price_in_btc * $BTCUSD ]
}
# Need to know in term of SGD too
if { [ info exists ::rate(last,USDSGD) ] } {
set price_in_sgd [ expr $price_in_usd * $::rate(last,USDSGD) ]
} else {
#in case fixer.io is down, use hardcoded rate
set price_in_sgd [ expr $price_in_usd * 1.35 ]
}
}
lappend arr "{\"symbol\":\"$curr\",\"provider\":\"$provider\",\"usd\":[ format %.4f $price_in_usd ],\"btc\":[ format %.8f $price_in_btc ],\"eth\":[ format %.8f $price_in_eth ],\"sgd\":[ format %.8f $price_in_sgd ]}"
}
set data "\[[ join $arr , ]\]"
set last_updated_ts ""
if { [info exists ::rate(updated) ] } {
set last_updated_ts [ clock format $::rate(updated) -format "%Y%m%d.%H%M%S" ]
}
set response "{\"data\":$data,\"last_updated\":\"$last_updated_ts\"}"
puts $sock $response
}