-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgateio.go
50 lines (40 loc) · 1.38 KB
/
gateio.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
package main
import (
"context"
"log"
"strconv"
"github.com/antihax/optional"
"github.com/gateio/gateapi-go/v6"
)
func getTradesGate(from int64, to int64, chMessagesCex chan MessageCex) {
client := gateapi.NewAPIClient(gateapi.NewConfiguration())
// uncomment the next line if your are testing against testnet
// client.ChangeBasePath("https://fx-api-testnet.gateio.ws/api/v4")
ctx := context.Background()
currencyPair := "ALPH_USDT" // string - Currency pair
result, _, err := client.SpotApi.ListTrades(ctx, currencyPair, &gateapi.ListTradesOpts{From: optional.NewInt64(from), To: optional.NewInt64(to), Limit: optional.NewInt32(1000)})
if err != nil {
if e, ok := err.(gateapi.GateAPIError); ok {
log.Printf("gate api error: %s\n", e.Error())
return
} else {
log.Printf("generic error: %s\n", err.Error())
return
}
}
for _, v := range result {
amountToFloat, err := strconv.ParseFloat(v.Amount, 64)
if err != nil {
log.Printf("Cannot convert gateio amount, err: %s\n", err)
}
priceToFloat, err := strconv.ParseFloat(v.Price, 64)
if err != nil {
log.Printf("Cannot convert gateio price, err: %s\n", err)
}
fiatQty := amountToFloat * priceToFloat
if fiatQty >= parameters.MinAmountCexTriggerUsd {
chMessagesCex <- MessageCex{v.Side, Amount{amountToFloat, "ALPH"}, Amount{fiatQty, "USDT"}, "Gateio", priceToFloat}
cexQueueMetrics.Inc()
}
}
}