-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
57 lines (50 loc) · 1.28 KB
/
main.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
package main
import (
"log"
"os"
"strconv"
"strings"
"time"
)
var (
fetcherExchange = os.Getenv("FETCHER_EXCHANGE")
fetcherKey = os.Getenv("FETCHER_API_KEY")
fetcherSecret = os.Getenv("FETCHER_API_SECRET")
ratioStr = os.Getenv("RATIO")
)
func main() {
client, err := NewClient(fetcherExchange, fetcherKey, fetcherSecret)
if err != nil {
log.Fatal(err)
}
config := &DefaultConfig
if ratioStr != "" {
r, err := strconv.ParseFloat(ratioStr, 64)
if err != nil {
log.Fatal(err)
}
config.Ratio = r
}
swiper := NewSwiper(client, config)
for {
res, err := swiper.Run()
if err != nil {
log.Printf("swiper: %s\n", err.Error())
if strings.Contains(err.Error(), "code=-1021") || strings.Contains(err.Error(), "code=-1000") {
continue
}
}
for order, copiedOrders := range res {
// TODO: print market price (now it's just "MARKET" given by Type)
log.Printf("copied: %s %s %f %s @ %s:%s\n",
order.ID, order.Side, order.Quantity, order.Symbol, order.Type, order.Price,
)
for _, copiedOrder := range copiedOrders {
log.Printf("\t-> %s %s %f %s @ %s:%s\n",
copiedOrder.ID, copiedOrder.Side, copiedOrder.Quantity, copiedOrder.Symbol, copiedOrder.Type, copiedOrder.Price,
)
}
}
time.Sleep(2100 * time.Millisecond)
}
}