-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
92 lines (73 loc) · 1.88 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
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
90
91
92
package main
import (
"math/rand/v2"
"time"
"github.com/EggsyOnCode/velho-exchange/api"
"github.com/EggsyOnCode/velho-exchange/client"
"github.com/EggsyOnCode/velho-exchange/core"
mm "github.com/EggsyOnCode/velho-exchange/market_maker"
)
const (
ethPrice = 1000.0
)
func startServer() {
exchange := core.NewExchange()
server := api.NewServer(exchange)
server.Start(":3000")
}
func initMMs(c *client.Client) []string {
pvkeys := []string{
"2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6",
"4bbbf85ce3377467afe5d46f804f221813b2bb87f24d81f60f1fcdbf7cbf4356",
"dbda1821b80551c9d65939329250298aa3472ba22feea921c0cf5d620ea67b97",
}
usd := 100_000_000.0
users := make([]string, 0)
for i := 0; i < len(pvkeys); i++ {
userId := c.RegisterUser(pvkeys[i], usd)
users = append(users, userId)
}
return users
}
func main() {
go startServer()
time.Sleep(1 * time.Second)
client := client.NewClient()
mmUsers := initMMs(client)
time.Sleep(1 * time.Second)
cfg := mm.Config{
UserID: mmUsers[0],
OrderSize: 100,
MarketInterval: 1 * time.Second,
SeedOffset: 40,
ExClient: client,
MinSpread: 20,
PriceOffset: 10,
}
mm := mm.NewMarketMaker(cfg)
go mm.Start()
time.Sleep(2 * time.Second)
go marketPlacer(client)
select {}
}
func marketPlacer(client *client.Client) {
ticker := time.NewTicker(3 * time.Second)
userPk := "5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a"
user := client.RegisterUser(userPk, 100_000.0)
for {
randInt := rand.IntN(10)
var bid bool
// more chances of placing a bid
// 30 % chance of placing an ask
// 70 % chance of placing a bid
if randInt > 7 {
bid = false
} else {
bid = true
}
// price doesn't matter in market orders
client.PlaceOrder("MARKET", 0, 3, bid, "ETH", user)
client.PlaceOrder("MARKET", 0, 4, bid, "ETH", user)
<-ticker.C
}
}