forked from thrasher-corp/gocryptotrader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ticker.go
61 lines (53 loc) · 1.62 KB
/
ticker.go
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
package main
import (
"strconv"
)
type TickerPrice struct {
CryptoCurrency string
FiatCurrency string
Last float64
High float64
Low float64
Bid float64
Ask float64
Volume float64
}
type Ticker struct {
Price map[string]map[string]TickerPrice
ExchangeName string
}
func (t *Ticker) PriceToString(cryptoCurrency, fiatCurrency, priceType string) string {
switch priceType {
case "last":
return strconv.FormatFloat(t.Price[cryptoCurrency][fiatCurrency].Last, 'f', -1, 64)
case "high":
return strconv.FormatFloat(t.Price[cryptoCurrency][fiatCurrency].High, 'f', -1, 64)
case "low":
return strconv.FormatFloat(t.Price[cryptoCurrency][fiatCurrency].Low, 'f', -1, 64)
case "bid":
return strconv.FormatFloat(t.Price[cryptoCurrency][fiatCurrency].Bid, 'f', -1, 64)
case "ask":
return strconv.FormatFloat(t.Price[cryptoCurrency][fiatCurrency].Ask, 'f', -1, 64)
case "volume":
return strconv.FormatFloat(t.Price[cryptoCurrency][fiatCurrency].Volume, 'f', -1, 64)
default:
return ""
}
}
func AddTickerPrice(m map[string]map[string]TickerPrice, cyrptocurrency, fiatcurrency string, price TickerPrice) {
mm, ok := m[cyrptocurrency]
if !ok {
mm = make(map[string]TickerPrice)
m[cyrptocurrency] = mm
}
mm[fiatcurrency] = price
}
func NewTicker(exchangeName string, prices []TickerPrice) *Ticker {
ticker := &Ticker{}
ticker.ExchangeName = exchangeName
ticker.Price = make(map[string]map[string]TickerPrice, 0)
for x, _ := range prices {
AddTickerPrice(ticker.Price, prices[x].CryptoCurrency, prices[x].FiatCurrency, prices[x])
}
return ticker
}