/
trade.go
48 lines (38 loc) · 1.09 KB
/
trade.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
package main
import (
"time"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)
type TradeCmd struct {
Strategy string `short:"s" long:"strategy" default:"market_maker" description:"strategy to use"`
List bool `short:"l" long:"list" description:"list strategy"`
Interval int `long:"interval" default:"5" description:"tick interval in second"`
}
func (tc *TradeCmd) Execute(args []string) error {
log.Infof("trade command strategy: %v, args: %v", tc.Strategy, args)
switch tc.Strategy {
case "market_maker":
tc.marketMaker()
default:
return errors.New("strategy not supported")
}
return nil
}
func (tc *TradeCmd) onTick() {
log.Infof("on tick, interval: %v", tc.Interval)
// get balance
// get order book status
// limit trade
}
func (tc *TradeCmd) marketMaker() {
log.Infoln("use strategy market maker")
for {
tc.onTick()
time.Sleep(time.Duration(tc.Interval) * time.Second)
}
}
var tradeCmd TradeCmd
func init() {
parser.AddCommand("trade", "run trading bot against live market data", "The trade command runs trading bot against live market data", &tradeCmd)
}