-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
58 lines (48 loc) · 1.39 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
package main
import (
"context"
"log"
"time"
"github.com/ThreeDotsLabs/watermill"
"github.com/ThreeDotsLabs/watermill/pubsub/gochannel"
"github.com/jujili/exch"
"github.com/jujili/exch/backtest"
)
func main() {
pubSub := gochannel.NewGoChannel(
gochannel.Config{
// 没有下面这一行,会无法从 Payload 的数据是乱的
BlockPublishUntilSubscriberAck: true,
},
watermill.NewStdLogger(false, false),
)
interval := time.Hour
// 启动策略
log.Println("准备启动 策略")
strategyService(context.TODO(), pubSub, interval, "BTCUSDT", "BTC", "USDT")
log.Println("完成启动 策略")
// 启动帐户服务
log.Println("准备启动 帐户记录服务")
prices := make(map[string]float64, 2)
asset, capital := "BTC", "USDT"
prices[capital] = 1
backtest.BalanceService(context.TODO(), pubSub, prices, asset)
log.Println("完成启动 帐户记录服务")
// 启动 backtest 交易所
usdt := exch.NewAsset("USDT", 10000, 0)
bal := exch.NewBalances(usdt)
log.Println("初始化的 Balance", bal)
backtest.NewBackTest(context.TODO(), pubSub, bal)
// 启动 TickBarService
backtest.TickBarService(context.TODO(), pubSub, interval)
srcName := "./btcusdt.sqlite3"
// srcName := "./binance.sqlite3"
//
db := openToMemory(srcName)
defer db.Close()
//
tickPublishService(context.TODO(), pubSub, db)
//
log.Println("close after 1 minute")
time.Sleep(time.Minute)
}