1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5#[repr(i32)]
6pub enum TrdEnv {
7 Simulate = 0,
8 Real = 1,
9}
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13#[repr(i32)]
14pub enum TrdMarket {
15 Unknown = 0,
16 HK = 1,
17 US = 2,
18 CN = 3,
19 HKCC = 4,
20}
21
22#[derive(Debug, Clone, Copy, PartialEq, Eq)]
24#[repr(i32)]
25pub enum TrdSide {
26 Unknown = 0,
27 Buy = 1,
28 Sell = 2,
29 SellShort = 3,
30 BuyBack = 4,
31}
32
33#[derive(Debug, Clone, Copy, PartialEq, Eq)]
35#[repr(i32)]
36pub enum OrderType {
37 Unknown = 0,
38 Normal = 1,
39 Market = 2,
40 AbsoluteLimit = 5,
41 Auction = 6,
42 AuctionLimit = 7,
43 SpecialLimit = 8,
44}
45
46#[derive(Debug, Clone, Copy, PartialEq, Eq)]
48#[repr(i32)]
49pub enum ModifyOrderOp {
50 Unknown = 0,
51 Normal = 1,
52 Cancel = 2,
53 Disable = 3,
54 Enable = 4,
55 Delete = 5,
56}
57
58#[derive(Debug, Clone)]
60pub struct TrdHeader {
61 pub trd_env: TrdEnv,
62 pub acc_id: u64,
63 pub trd_market: TrdMarket,
64}
65
66impl TrdHeader {
67 pub fn to_proto(&self) -> futu_proto::trd_common::TrdHeader {
68 futu_proto::trd_common::TrdHeader {
69 trd_env: self.trd_env as i32,
70 acc_id: self.acc_id,
71 trd_market: self.trd_market as i32,
72 jp_acc_type: None,
73 }
74 }
75}
76
77#[derive(Debug, Clone)]
79pub struct Funds {
80 pub power: f64,
81 pub total_assets: f64,
82 pub cash: f64,
83 pub market_val: f64,
84 pub frozen_cash: f64,
85 pub debt_cash: f64,
86 pub avl_withdrawal_cash: f64,
87}
88
89impl Funds {
90 pub fn from_proto(f: &futu_proto::trd_common::Funds) -> Self {
91 Self {
92 power: f.power,
93 total_assets: f.total_assets,
94 cash: f.cash,
95 market_val: f.market_val,
96 frozen_cash: f.frozen_cash,
97 debt_cash: f.debt_cash,
98 avl_withdrawal_cash: f.avl_withdrawal_cash,
99 }
100 }
101}
102
103#[derive(Debug, Clone)]
105pub struct Position {
106 pub position_id: u64,
107 pub position_side: i32,
108 pub code: String,
109 pub name: String,
110 pub qty: f64,
111 pub can_sell_qty: f64,
112 pub price: f64,
113 pub cost_price: f64,
114 pub val: f64,
115 pub pl_val: f64,
116 pub pl_ratio: f64,
117}
118
119impl Position {
120 pub fn from_proto(p: &futu_proto::trd_common::Position) -> Self {
121 Self {
122 position_id: p.position_id,
123 position_side: p.position_side,
124 code: p.code.clone(),
125 name: p.name.clone(),
126 qty: p.qty,
127 can_sell_qty: p.can_sell_qty,
128 price: p.price,
129 cost_price: p.cost_price.unwrap_or(0.0),
130 val: p.val,
131 pl_val: p.pl_val,
132 pl_ratio: p.pl_ratio.unwrap_or(0.0),
133 }
134 }
135}
136
137#[derive(Debug, Clone)]
139pub struct PlaceOrderParams {
140 pub header: TrdHeader,
141 pub trd_side: TrdSide,
142 pub order_type: OrderType,
143 pub code: String,
144 pub qty: f64,
145 pub price: Option<f64>,
146 pub adjust_price: Option<bool>,
147 pub adjust_side_and_limit: Option<f64>,
148}
149
150#[derive(Debug, Clone)]
152pub struct PlaceOrderResult {
153 pub order_id: u64,
154}
155
156#[derive(Debug, Clone)]
158pub struct ModifyOrderParams {
159 pub header: TrdHeader,
160 pub order_id: u64,
161 pub modify_order_op: ModifyOrderOp,
162 pub qty: Option<f64>,
163 pub price: Option<f64>,
164 pub for_all: Option<bool>,
165}