-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathtrd_modifyorder.go
80 lines (73 loc) · 2.28 KB
/
trd_modifyorder.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
package futuapi
import (
"context"
"github.com/hurisheng/go-futu-api/pb/trdcommon"
"github.com/hurisheng/go-futu-api/pb/trdmodifyorder"
"github.com/hurisheng/go-futu-api/protocol"
"google.golang.org/protobuf/proto"
)
const ProtoIDTrdModifyOrder = 2205 //Trd_ModifyOrder
func init() {
workers[ProtoIDTrdModifyOrder] = protocol.NewGetter()
}
// 改单撤单
func (api *FutuAPI) ModifyOrder(ctx context.Context, header *trdcommon.TrdHeader, orderID uint64, op trdcommon.ModifyOrderOp, forAll bool,
trdMarket trdcommon.TrdMarket, qty *OptionalDouble, price *OptionalDouble,
adjust *OptionalBool, sideAndLimit *OptionalDouble, auxPrice *OptionalDouble,
trailType trdcommon.TrailType, trailValue *OptionalDouble, trailSpread *OptionalDouble, orderIDEx string) (*trdmodifyorder.S2C, error) {
if header == nil || op == trdcommon.ModifyOrderOp_ModifyOrderOp_Unknown {
return nil, ErrParameters
}
req := &trdmodifyorder.Request{
C2S: &trdmodifyorder.C2S{
PacketID: api.packetID(),
Header: header,
OrderID: proto.Uint64(orderID),
ModifyOrderOp: proto.Int32(int32(op)),
ForAll: proto.Bool(forAll),
},
}
if trdMarket != trdcommon.TrdMarket_TrdMarket_Unknown {
req.C2S.TrdMarket = proto.Int32(int32(trdMarket))
}
if qty != nil {
req.C2S.Qty = proto.Float64(qty.Value)
}
if price != nil {
req.C2S.Price = proto.Float64(price.Value)
}
if adjust != nil {
req.C2S.AdjustPrice = proto.Bool(adjust.Value)
}
if sideAndLimit != nil {
req.C2S.AdjustSideAndLimit = proto.Float64(sideAndLimit.Value)
}
if auxPrice != nil {
req.C2S.AuxPrice = proto.Float64(auxPrice.Value)
}
if trailType != trdcommon.TrailType_TrailType_Unknown {
req.C2S.TrailType = proto.Int32(int32(trailType))
}
if trailValue != nil {
req.C2S.TrailValue = proto.Float64(trailValue.Value)
}
if trailSpread != nil {
req.C2S.TrailSpread = proto.Float64(trailSpread.Value)
}
if orderIDEx != "" {
req.C2S.OrderIDEx = proto.String(orderIDEx)
}
ch := make(chan *trdmodifyorder.Response)
if err := api.proto.RegisterGet(ProtoIDTrdModifyOrder, req, protocol.NewProtobufChan(ch)); err != nil {
return nil, err
}
select {
case <-ctx.Done():
return nil, ErrInterrupted
case resp, ok := <-ch:
if !ok {
return nil, ErrChannelClosed
}
return resp.GetS2C(), protocol.Error(resp)
}
}