-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
95 lines (82 loc) · 2.44 KB
/
main.go
File metadata and controls
95 lines (82 loc) · 2.44 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
90
91
92
93
94
95
package main
import (
"flag"
"fmt"
"example.com/predictionMarketCentralized/markets"
"example.com/predictionMarketCentralized/players"
simulatedplayer "example.com/predictionMarketCentralized/simulatedPlayer"
)
func main() {
typePtr := flag.String("type", "basic", "basic or simulated")
verbosePtr := flag.Bool("v", false, "a bool")
flag.Parse()
if *typePtr == "basic" {
cs := markets.NewContractSet("coin flip", []string{"heads", "tails"}, []float64{.5, .5}, 20, *verbosePtr)
mp1 := players.NewMarketPlayer(1, 10, *verbosePtr)
if *verbosePtr {
mp1.PrintState()
cs.PrintState()
}
mp1.BuyContract(&cs, &cs.Markets[0], 2, *verbosePtr)
mp1.SellContract(&cs, &cs.Markets[0], 2, *verbosePtr)
mp1.BuySet(&cs, 2, *verbosePtr)
mp1.SellSet(&cs, 2, *verbosePtr)
mp1.AddLiquidity(&cs, &cs.Markets[0], 2, *verbosePtr)
mp1.RemoveLiquidity(&cs, &cs.Markets[0], 2, *verbosePtr)
cs.Validate(cs.Markets[0], *verbosePtr)
mp1.Redeem(&cs, &cs.Markets[0], *verbosePtr)
if !(*verbosePtr) {
mp1.PrintState()
cs.PrintState()
}
} else if *typePtr == "simulated" {
cs := markets.NewContractSet("coin flip", []string{"heads", "tails"}, []float64{.5, .5}, 200, false)
bots := make([]simulatedplayer.SimulatedPlayer, 0)
if *verbosePtr {
fmt.Println("Creating 100 simulated players")
fmt.Println()
}
for i := 0; i < 100; i++ {
bots = append(bots, simulatedplayer.NewSimulatedPlayer(i, 70, false))
}
if *verbosePtr {
fmt.Println("Simulating trading")
fmt.Println()
}
for round := 0; round < 800; round++ {
for i := range bots {
for j := range cs.Markets {
bots[i].BuyOrSell(&cs, &cs.Markets[j], false)
bots[i].AddOrRemove(&cs, &cs.Markets[j], false)
}
}
}
if *verbosePtr {
fmt.Println("Ordering removal of all liquidity")
fmt.Println()
}
//remove all liquidity
for i := range bots {
bots[i].RemoveAll(&cs, false)
}
if *verbosePtr {
fmt.Println("Determining outcome and redeeming all contracts")
fmt.Println()
}
//validate the outcome that is above .97 percent
simulatedplayer.SimulateValidation(&cs)
//redeem all votes
for i := range bots {
for j := range cs.Markets {
bots[i].Redeem(&cs, &cs.Markets[j], false)
}
}
//print total player money
fmt.Println("Total player money:", simulatedplayer.SumPlayersBalance(bots))
fmt.Println()
//print total contracts minted
fmt.Println("Total contracts minted:", cs.Mints)
fmt.Println()
cs.PrintState()
}
}