-
Notifications
You must be signed in to change notification settings - Fork 156
/
main.go
82 lines (66 loc) · 1.71 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
package main
import (
. "github.com/coinrust/crex"
"github.com/coinrust/crex/backtest"
"github.com/coinrust/crex/dataloader"
"github.com/coinrust/crex/exchanges/exsim"
"time"
)
type BasicStrategy struct {
StrategyBase
}
func (s *BasicStrategy) OnInit() error {
return nil
}
func (s *BasicStrategy) OnTick() error {
//ts, _ := s.Exchange.GetTime()
//log.Infof("OnTick %v", ts)
currency := "BTC"
symbol := "BTC-PERPETUAL"
s.Exchange.GetBalance(currency)
s.Exchange.GetBalance(currency)
s.Exchange.GetOrderBook(symbol, 10)
s.Exchange.GetOrderBook(symbol, 10)
//s.Exchange.PlaceOrder(symbol, Buy, OrderTypeLimit, 1000.0, 10, OrderPostOnlyOption(true))
s.Exchange.GetOpenOrders(symbol)
s.Exchange.GetPositions(symbol)
return nil
}
func (s *BasicStrategy) Run() error {
return nil
}
func (s *BasicStrategy) OnExit() error {
return nil
}
func main() {
loader := dataloader.NewMongoDBDataLoader("mongodb://localhost:27017",
"tick_db", "deribit", "BTC-PERPETUAL")
data := dataloader.NewData(loader)
start, _ := time.Parse("2006-01-02 15:04:05", "2019-10-01 00:00:00")
end, _ := time.Parse("2006-01-02 15:04:05", "2019-10-02 00:00:00")
var datas []*dataloader.Data
var exchanges []ExchangeSim
for i := 0; i < 2; i++ {
datas = append(datas, data)
ex := exsim.NewExSim(data,
5.0, -0.00025, 0.00075, 1.0, false, false)
exchanges = append(exchanges, ex)
}
s := &BasicStrategy{}
outputDir := "./output"
bt := backtest.NewBacktest(datas,
"BTC",
start,
end,
s,
exchanges,
outputDir)
bt.Run()
//logs := bt.GetLogs()
//for _, v := range logs {
// fmt.Printf("Time: %v Price: %v Equity: %v\n", v.Time, v.Price(), v.TotalEquity())
//}
bt.ComputeStats().PrintResult()
bt.Plot()
bt.HtmlReport()
}