Skip to content

Commit

Permalink
add log support
Browse files Browse the repository at this point in the history
  • Loading branch information
f0cii committed Sep 25, 2018
1 parent 129f181 commit e341181
Show file tree
Hide file tree
Showing 6 changed files with 273 additions and 21 deletions.
3 changes: 2 additions & 1 deletion algo/goexstrategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type GoExStrategy struct {
}

func (s *GoExStrategy) Setup(params []goalgo.ExchangeParams) error {
log.Printf("GoExStrategy Setup")
s.Exchanges = []goex.API{}
for _, p := range params {
log.Print(p)
Expand All @@ -52,7 +53,7 @@ func (s *GoExStrategy) Setup(params []goalgo.ExchangeParams) error {

func (s *GoExStrategy) createExchange(params goalgo.ExchangeParams) goex.API {
b := builder.NewAPIBuilder()
exName, ok := goExExchangeNameMap[params.Exchange]
exName, ok := goExExchangeNameMap[params.Name]
if !ok {
return nil
}
Expand Down
25 changes: 23 additions & 2 deletions basestrategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,32 @@ func (s *BaseStrategy) run() {
s.state = RStateStopped
return
}
s.state = RStateRunning

strategy.Init()
strategy.Setup(nil)
s.state = RStateInitialized

client := GetClient()
exchanges, err := client.GetRobotExchangeInfo("", id)
if err != nil {
log.Printf("GetRobotExchangeInfo error: %v", err)
} else {
params := []ExchangeParams{}
for _, ex := range exchanges {
params = append(params, ExchangeParams{
Label: ex.Label,
Name: ex.Name,
AccessKey: ex.AccessKey,
SecretKey: ex.SecretKey,
})
}
log.Printf("Setup...")
strategy.Setup(params)
log.Printf("Setup.")
}

s.state = RStateRunning
strategy.Run()

log.Printf("Run done")
s.state = RStateStopped
}
Expand Down
229 changes: 212 additions & 17 deletions grpc_broker.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions grpc_broker.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,29 @@ package goalgo;

// The robot control service definition.
service RobotCtl {
// 获取交易所配置
rpc GetRobotExchangeInfo (RobotExchangeInfoRequest) returns (RobotExchangeInfoReply) {}

// 写入日志
rpc Log (LogRequest) returns (LogReply) {}
}

message RobotExchangeInfoRequest {
string uid = 1;
string robot_id = 2;
}

message RobotExchangeInfo {
string label = 1;
string name = 2;
string access_key = 3;
string secret_key = 4;
}

message RobotExchangeInfoReply {
repeated RobotExchangeInfo exchanges = 1;
}

message LogRequest {
int32 sid = 1;
uint64 id = 2;
Expand Down
Loading

0 comments on commit e341181

Please sign in to comment.