forked from hurisheng/go-futu-api
/
trd_placeorder.go
52 lines (48 loc) · 1.49 KB
/
trd_placeorder.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
package futuapi
import (
"context"
"github.com/headshot289/go-futu-api/pb/trdcommon"
"github.com/headshot289/go-futu-api/pb/trdplaceorder"
"github.com/headshot289/go-futu-api/protocol"
)
const (
ProtoIDTrdPlaceOrder = 2202 //Trd_PlaceOrder 下单
)
// 下单
func (api *FutuAPI) PlaceOrder(ctx context.Context, header *TrdHeader, trdSide trdcommon.TrdSide, orderType trdcommon.OrderType, code string, qty float64, price float64,
adjustPrice bool, sideAndLimit float64, secMarket trdcommon.TrdSecMarket, remark string, timeInForce trdcommon.TimeInForce, fillOutsideRTH bool) (uint64, error) {
req := trdplaceorder.Request{
C2S: &trdplaceorder.C2S{
PacketID: api.packetID().pb(),
Header: header.pb(),
TrdSide: (*int32)(&trdSide),
OrderType: (*int32)(&orderType),
Code: &code,
Qty: &qty,
Price: &price,
AdjustPrice: &adjustPrice,
AdjustSideAndLimit: &sideAndLimit,
Remark: &remark,
FillOutsideRTH: &fillOutsideRTH,
},
}
if secMarket != 0 {
req.C2S.SecMarket = (*int32)(&secMarket)
}
if timeInForce != 0 {
req.C2S.TimeInForce = (*int32)(&timeInForce)
}
ch := make(trdplaceorder.ResponseChan)
if err := api.get(ProtoIDTrdPlaceOrder, &req, ch); err != nil {
return 0, err
}
select {
case <-ctx.Done():
return 0, ErrInterrupted
case resp, ok := <-ch:
if !ok {
return 0, ErrChannelClosed
}
return resp.GetS2C().GetOrderID(), protocol.Error(resp)
}
}