-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.go
49 lines (45 loc) · 937 Bytes
/
demo.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
package main
var btcUsdtTickers = []ExTick{
{"coinbase", "BTC-USD"},
{"binance", "BTCUSDT"},
{"kraken", "XBTUSDT"},
{"bitstamp", "btcusdt"},
{"huobi", "btcusdt"},
{"kucoin", "BTC-USDT"},
{"gateio", "BTC_USDT"},
{"bitfinex", "btcust"},
}
func floatSliceMean(slice []float64) float64 {
sum := 0.0
i := 0
for _, v := range slice {
if v == 0 {
continue
}
sum += v
i++
}
return sum / float64(i)
}
/*
func getBtcUsdt() float64 {
prices := []float64{}
for _, et := range btcUsdtTickers {
price := getExchangeTickerPrice(et)
prices = append(prices, price)
}
return floatSliceMean(prices)
}
func getBtcUsdtAsync() float64 {
prices := []float64{}
resultChan := make(chan float64)
for _, et := range btcUsdtTickers {
go getExchangeTickerPriceAsync(et, resultChan)
}
for i := 0; i < len(btcUsdtTickers); i++ {
price := <-resultChan
prices = append(prices, price)
}
return floatSliceMean(prices)
}
*/