-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbttto.go
72 lines (57 loc) · 1.31 KB
/
bttto.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
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"os"
"strconv"
)
var (
tickerList [9]string
m float64
)
type symbolPrice struct {
Price string `json:"price"`
}
func checkErr(err error) {
if err != nil {
log.Fatal(err)
}
}
func main() {
tickerList[0] = "BTTBNB"
tickerList[1] = "BTTBRL"
tickerList[2] = "BTTBUSD"
tickerList[3] = "BTTEUR"
tickerList[4] = "BTTTRX"
tickerList[5] = "BTTTRY"
tickerList[6] = "BTTTUSD"
tickerList[7] = "BTTUSDC"
tickerList[8] = "BTTUSDT"
if len(os.Args) > 1 {
howMatch := os.Args[1]
if s, err := strconv.ParseFloat(howMatch, 64); err == nil {
m = s
}
} else {
fmt.Println("Sorry, but you are not set how tokens need to count, as sample ./bttto.exe 11.11")
fmt.Println("Here default price for 1 (one token): ")
m = 1.00
}
for l := 0; l < len(tickerList); l++ {
getAvgPricebySymbol(tickerList[l], m)
}
}
func getAvgPricebySymbol(symbol string, countTokens float64) {
resp, err := http.Get("https://api.binance.com/api/v3/avgPrice?symbol=" + symbol)
checkErr(err)
body, err := io.ReadAll(resp.Body)
checkErr(err)
var getSymbolPriceRecord symbolPrice
json.Unmarshal(body, &getSymbolPriceRecord)
if s, err := strconv.ParseFloat(getSymbolPriceRecord.Price, 64); err == nil {
fmt.Println(symbol+" : ", countTokens*s)
}
}