forked from hurisheng/go-futu-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trd_updateorder.go
49 lines (40 loc) · 1.09 KB
/
trd_updateorder.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
package futuapi
import (
"context"
"github.com/Lawrence93Ho/go-futu-api/pb/trdupdateorder"
"github.com/Lawrence93Ho/go-futu-api/protocol"
"google.golang.org/protobuf/proto"
)
const (
ProtoIDTrdUpdateOrder = 2208 //Trd_UpdateOrder 推送订单状态变动通知
)
// 响应订单推送回调
func (api *FutuAPI) UpdateOrder(ctx context.Context) (<-chan *UpdateOrderResp, error) {
ch := make(updateOrderChan)
if err := api.update(ProtoIDTrdUpdateOrder, ch); err != nil {
return nil, err
}
return ch, nil
}
type UpdateOrderResp struct {
Header *TrdHeader //交易公共参数头
Order *Order //订单结构
Err error
}
type updateOrderChan chan *UpdateOrderResp
var _ protocol.RespChan = make(updateOrderChan)
func (ch updateOrderChan) Send(b []byte) error {
var resp trdupdateorder.Response
if err := proto.Unmarshal(b, &resp); err != nil {
return err
}
ch <- &UpdateOrderResp{
Header: trdHeaderFromPB(resp.GetS2C().GetHeader()),
Order: orderFromPB(resp.GetS2C().GetOrder()),
Err: protocol.Error(&resp),
}
return nil
}
func (ch updateOrderChan) Close() {
close(ch)
}