-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitor.go
More file actions
89 lines (70 loc) · 1.94 KB
/
Copy pathmonitor.go
File metadata and controls
89 lines (70 loc) · 1.94 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"log"
"monitor/monitor/discord"
"monitor/monitor/markets"
"strconv"
)
func FindBestPair(orders map[string]markets.Order, garantex markets.Order) (discord.BestOrderPair, bool) {
bestPair := discord.BestOrderPair{SellOrderInfo: garantex}
spread := 0.
for _, orderBuy := range orders {
curSpread := garantex.SellPrice - orderBuy.BuyPrice
quantityBuy, _ := strconv.ParseFloat(orderBuy.Quantity, 64)
if curSpread > spread && orderBuy.BuyPrice*quantityBuy > 1000. {
bestPair.BuyOrderInfo = orderBuy
spread = curSpread
}
}
return bestPair, spread > 1.0
}
func main() {
discordOrders := make(chan discord.BestOrderPair)
go discord.DiscordSender(discordOrders)
allOrders := make(chan markets.Order)
go markets.MonitorGarantexPrice(allOrders)
go markets.MonitorBinancePrice(allOrders)
go markets.MonitorByBitPrice(allOrders)
go markets.MonitorHuobiPrice(allOrders)
prevBuyOrder := markets.Order{}
orders := make(map[string]markets.Order)
for {
currentOrder := <-allOrders
switch currentOrder.Market {
case "Garantex":
orders["garantex"] = currentOrder
case "Binance":
orders["binance"] = currentOrder
case "ByBit":
orders["bybit"] = currentOrder
case "Huobi":
orders["huobi"] = currentOrder
}
bestPair, report := FindBestPair(orders, orders["garantex"])
if report {
for name, order := range orders {
log.Printf("%s: %g,", name, order.BuyPrice)
}
log.Println()
}
if report && prevBuyOrder != bestPair.BuyOrderInfo {
prevBuyOrder = bestPair.BuyOrderInfo
discordOrders <- bestPair
}
}
}
// discordOrders <- discord.BestOrderPair{
// BuyOrderInfo: markets.Order{
// Market: "TestSource",
// SellerName: "TestSeller",
// Price: 50.0,
// Quantity: "123.4",
// MinAmount: "228.0",
// MaxAmount: "1337.0",
// Url: "https://www.google.com",
// },
// SellOrderInfo: markets.Order{
// Market: "TestOutput",
// Price: 121.0,
// },
// }