-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmexc.go
65 lines (55 loc) · 1.7 KB
/
mexc.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
package main
import (
"encoding/json"
"fmt"
"log"
"strconv"
)
type MexcAggTrades []struct {
ID interface{} `json:"id"`
Price string `json:"price"`
Qty string `json:"qty"`
QuoteQty string `json:"quoteQty"`
Time int64 `json:"time"`
IsBuyerMaker bool `json:"isBuyerMaker"`
IsBestMatch bool `json:"isBestMatch"`
TradeType string `json:"tradeType"`
}
func getTradesMexc(from int64, to int64, chMessagesCex chan MessageCex, symbols []string) {
for _, symbol := range symbols {
getTrades(from, to, chMessagesCex, symbol)
}
}
func getTrades(from int64, to int64, chMessagesCex chan MessageCex, symbol string) {
var trades MexcAggTrades
dataBytes, _, err := getHttp(fmt.Sprintf("https://api.mexc.com/api/v3/trades/?symbol=%sUSDT", symbol))
if err != nil {
log.Printf("Error getting price\n%s\n", err)
return
}
if len(dataBytes) > 0 {
json.Unmarshal(dataBytes, &trades)
}
for _, v := range trades {
amountToFloat, err := strconv.ParseFloat(v.Qty, 64)
if err != nil {
log.Printf("Cannot convert mexc amount, err: %s\n", err)
}
priceToFloat, err := strconv.ParseFloat(v.Price, 64)
if err != nil {
log.Printf("Cannot convert mexc price, err: %s\n", err)
}
quoteQtyToFloat, err := strconv.ParseFloat(v.QuoteQty, 64)
if err != nil {
log.Printf("Cannot convert mexc quote quantity, err: %s\n", err)
}
side := "buy"
if v.IsBuyerMaker {
side = "sell"
}
if quoteQtyToFloat >= parameters.MinAmountCexTriggerUsd && v.Time >= from && v.Time <= to {
chMessagesCex <- MessageCex{side, Amount{amountToFloat, symbol}, Amount{quoteQtyToFloat, "USDT"}, "Mexc", priceToFloat}
cexQueueMetrics.Inc()
}
}
}