@@ -112,7 +112,7 @@ impl Display for TimeInForce {
112112 }
113113}
114114
115- struct OrderRequest {
115+ pub struct OrderRequest {
116116 pub symbol : String ,
117117 pub side : OrderSide ,
118118 pub position_side : Option < PositionSide > ,
@@ -129,21 +129,119 @@ struct OrderRequest {
129129 pub price_protect : Option < f64 > ,
130130}
131131
132- pub struct CustomOrderRequest {
133- pub symbol : String ,
134- pub side : OrderSide ,
135- pub position_side : Option < PositionSide > ,
136- pub order_type : OrderType ,
137- pub time_in_force : Option < TimeInForce > ,
138- pub qty : Option < f64 > ,
139- pub reduce_only : Option < bool > ,
140- pub price : Option < f64 > ,
141- pub stop_price : Option < f64 > ,
142- pub close_position : Option < bool > ,
143- pub activation_price : Option < f64 > ,
144- pub callback_rate : Option < f64 > ,
145- pub working_type : Option < WorkingType > ,
146- pub price_protect : Option < f64 > ,
132+ impl OrderRequest {
133+ pub fn limit_buy (
134+ symbol : impl Into < String > , qty : impl Into < f64 > , price : f64 , time_in_force : TimeInForce ,
135+ ) -> Self {
136+ Self {
137+ symbol : symbol. into ( ) ,
138+ side : OrderSide :: Buy ,
139+ position_side : None ,
140+ order_type : OrderType :: Limit ,
141+ time_in_force : Some ( time_in_force) ,
142+ qty : Some ( qty. into ( ) ) ,
143+ reduce_only : None ,
144+ price : Some ( price) ,
145+ stop_price : None ,
146+ close_position : None ,
147+ activation_price : None ,
148+ callback_rate : None ,
149+ working_type : None ,
150+ price_protect : None ,
151+ }
152+ }
153+ pub fn limit_sell (
154+ symbol : impl Into < String > , qty : impl Into < f64 > , price : f64 , time_in_force : TimeInForce ,
155+ ) -> Self {
156+ Self {
157+ symbol : symbol. into ( ) ,
158+ side : OrderSide :: Sell ,
159+ position_side : None ,
160+ order_type : OrderType :: Limit ,
161+ time_in_force : Some ( time_in_force) ,
162+ qty : Some ( qty. into ( ) ) ,
163+ reduce_only : None ,
164+ price : Some ( price) ,
165+ stop_price : None ,
166+ close_position : None ,
167+ activation_price : None ,
168+ callback_rate : None ,
169+ working_type : None ,
170+ price_protect : None ,
171+ }
172+ }
173+ pub fn market_buy ( symbol : impl Into < String > , qty : impl Into < f64 > ) -> Self {
174+ Self {
175+ symbol : symbol. into ( ) ,
176+ side : OrderSide :: Buy ,
177+ position_side : None ,
178+ order_type : OrderType :: Market ,
179+ time_in_force : None ,
180+ qty : Some ( qty. into ( ) ) ,
181+ reduce_only : None ,
182+ price : None ,
183+ stop_price : None ,
184+ close_position : None ,
185+ activation_price : None ,
186+ callback_rate : None ,
187+ working_type : None ,
188+ price_protect : None ,
189+ }
190+ }
191+ pub fn market_sell ( symbol : impl Into < String > , qty : impl Into < f64 > ) -> Self {
192+ Self {
193+ symbol : symbol. into ( ) ,
194+ side : OrderSide :: Sell ,
195+ position_side : None ,
196+ order_type : OrderType :: Market ,
197+ time_in_force : None ,
198+ qty : Some ( qty. into ( ) ) ,
199+ reduce_only : None ,
200+ price : None ,
201+ stop_price : None ,
202+ close_position : None ,
203+ activation_price : None ,
204+ callback_rate : None ,
205+ working_type : None ,
206+ price_protect : None ,
207+ }
208+ }
209+ pub fn stop_market_close_buy ( symbol : impl Into < String > , stop_price : impl Into < f64 > ) -> Self {
210+ Self {
211+ symbol : symbol. into ( ) ,
212+ side : OrderSide :: Buy ,
213+ position_side : None ,
214+ order_type : OrderType :: StopMarket ,
215+ time_in_force : None ,
216+ qty : None ,
217+ reduce_only : None ,
218+ price : None ,
219+ stop_price : Some ( stop_price. into ( ) ) ,
220+ close_position : Some ( true ) ,
221+ activation_price : None ,
222+ callback_rate : None ,
223+ working_type : None ,
224+ price_protect : None ,
225+ }
226+ }
227+ pub fn stop_market_close_sell ( symbol : impl Into < String > , stop_price : impl Into < f64 > ) -> Self {
228+ Self {
229+ symbol : symbol. into ( ) ,
230+ side : OrderSide :: Sell ,
231+ position_side : None ,
232+ order_type : OrderType :: StopMarket ,
233+ time_in_force : None ,
234+ qty : None ,
235+ reduce_only : None ,
236+ price : None ,
237+ stop_price : Some ( stop_price. into ( ) ) ,
238+ close_position : Some ( true ) ,
239+ activation_price : None ,
240+ callback_rate : None ,
241+ working_type : None ,
242+ price_protect : None ,
243+ }
244+ }
147245}
148246
149247pub struct IncomeRequest {
@@ -208,22 +306,7 @@ impl FuturesAccount {
208306 & self , symbol : impl Into < String > , qty : impl Into < f64 > , price : f64 ,
209307 time_in_force : TimeInForce ,
210308 ) -> Result < Transaction > {
211- let buy = OrderRequest {
212- symbol : symbol. into ( ) ,
213- side : OrderSide :: Buy ,
214- position_side : None ,
215- order_type : OrderType :: Limit ,
216- time_in_force : Some ( time_in_force) ,
217- qty : Some ( qty. into ( ) ) ,
218- reduce_only : None ,
219- price : Some ( price) ,
220- stop_price : None ,
221- close_position : None ,
222- activation_price : None ,
223- callback_rate : None ,
224- working_type : None ,
225- price_protect : None ,
226- } ;
309+ let buy = OrderRequest :: limit_buy ( symbol, qty, price, time_in_force) ;
227310 let order = self . build_order ( buy) ;
228311 let request = build_signed_request ( order, self . recv_window ) ?;
229312 self . client
@@ -234,22 +317,7 @@ impl FuturesAccount {
234317 & self , symbol : impl Into < String > , qty : impl Into < f64 > , price : f64 ,
235318 time_in_force : TimeInForce ,
236319 ) -> Result < Transaction > {
237- let sell = OrderRequest {
238- symbol : symbol. into ( ) ,
239- side : OrderSide :: Sell ,
240- position_side : None ,
241- order_type : OrderType :: Limit ,
242- time_in_force : Some ( time_in_force) ,
243- qty : Some ( qty. into ( ) ) ,
244- reduce_only : None ,
245- price : Some ( price) ,
246- stop_price : None ,
247- close_position : None ,
248- activation_price : None ,
249- callback_rate : None ,
250- working_type : None ,
251- price_protect : None ,
252- } ;
320+ let sell = OrderRequest :: limit_sell ( symbol, qty, price, time_in_force) ;
253321 let order = self . build_order ( sell) ;
254322 let request = build_signed_request ( order, self . recv_window ) ?;
255323 self . client
@@ -262,22 +330,7 @@ impl FuturesAccount {
262330 S : Into < String > ,
263331 F : Into < f64 > ,
264332 {
265- let buy = OrderRequest {
266- symbol : symbol. into ( ) ,
267- side : OrderSide :: Buy ,
268- position_side : None ,
269- order_type : OrderType :: Market ,
270- time_in_force : None ,
271- qty : Some ( qty. into ( ) ) ,
272- reduce_only : None ,
273- price : None ,
274- stop_price : None ,
275- close_position : None ,
276- activation_price : None ,
277- callback_rate : None ,
278- working_type : None ,
279- price_protect : None ,
280- } ;
333+ let buy = OrderRequest :: market_buy ( symbol, qty) ;
281334 let order = self . build_order ( buy) ;
282335 let request = build_signed_request ( order, self . recv_window ) ?;
283336 self . client
@@ -290,22 +343,7 @@ impl FuturesAccount {
290343 S : Into < String > ,
291344 F : Into < f64 > ,
292345 {
293- let sell = OrderRequest {
294- symbol : symbol. into ( ) ,
295- side : OrderSide :: Sell ,
296- position_side : None ,
297- order_type : OrderType :: Market ,
298- time_in_force : None ,
299- qty : Some ( qty. into ( ) ) ,
300- reduce_only : None ,
301- price : None ,
302- stop_price : None ,
303- close_position : None ,
304- activation_price : None ,
305- callback_rate : None ,
306- working_type : None ,
307- price_protect : None ,
308- } ;
346+ let sell = OrderRequest :: market_sell ( symbol, qty) ;
309347 let order = self . build_order ( sell) ;
310348 let request = build_signed_request ( order, self . recv_window ) ?;
311349 self . client
@@ -346,22 +384,7 @@ impl FuturesAccount {
346384 S : Into < String > ,
347385 F : Into < f64 > ,
348386 {
349- let sell = OrderRequest {
350- symbol : symbol. into ( ) ,
351- side : OrderSide :: Buy ,
352- position_side : None ,
353- order_type : OrderType :: StopMarket ,
354- time_in_force : None ,
355- qty : None ,
356- reduce_only : None ,
357- price : None ,
358- stop_price : Some ( stop_price. into ( ) ) ,
359- close_position : Some ( true ) ,
360- activation_price : None ,
361- callback_rate : None ,
362- working_type : None ,
363- price_protect : None ,
364- } ;
387+ let sell = OrderRequest :: stop_market_close_buy ( symbol, stop_price) ;
365388 let order = self . build_order ( sell) ;
366389 let request = build_signed_request ( order, self . recv_window ) ?;
367390 self . client
@@ -374,78 +397,31 @@ impl FuturesAccount {
374397 S : Into < String > ,
375398 F : Into < f64 > ,
376399 {
377- let sell = OrderRequest {
378- symbol : symbol. into ( ) ,
379- side : OrderSide :: Sell ,
380- position_side : None ,
381- order_type : OrderType :: StopMarket ,
382- time_in_force : None ,
383- qty : None ,
384- reduce_only : None ,
385- price : None ,
386- stop_price : Some ( stop_price. into ( ) ) ,
387- close_position : Some ( true ) ,
388- activation_price : None ,
389- callback_rate : None ,
390- working_type : None ,
391- price_protect : None ,
392- } ;
400+ let sell = OrderRequest :: stop_market_close_sell ( symbol, stop_price) ;
393401 let order = self . build_order ( sell) ;
394402 let request = build_signed_request ( order, self . recv_window ) ?;
395403 self . client
396404 . post_signed ( API :: Futures ( Futures :: Order ) , request)
397405 }
398406
399- // Custom order for for professional traders
400- pub fn custom_order ( & self , order_request : CustomOrderRequest ) -> Result < Transaction > {
401- let order = OrderRequest {
402- symbol : order_request. symbol ,
403- side : order_request. side ,
404- position_side : order_request. position_side ,
405- order_type : order_request. order_type ,
406- time_in_force : order_request. time_in_force ,
407- qty : order_request. qty ,
408- reduce_only : order_request. reduce_only ,
409- price : order_request. price ,
410- stop_price : order_request. stop_price ,
411- close_position : order_request. close_position ,
412- activation_price : order_request. activation_price ,
413- callback_rate : order_request. callback_rate ,
414- working_type : order_request. working_type ,
415- price_protect : order_request. price_protect ,
416- } ;
407+ // Custom order for professional traders
408+ pub fn custom_order ( & self , order : OrderRequest ) -> Result < Transaction > {
417409 let order = self . build_order ( order) ;
418410 let request = build_signed_request ( order, self . recv_window ) ?;
419411 self . client
420412 . post_signed ( API :: Futures ( Futures :: Order ) , request)
421413 }
422414
423- // Custom order for for professional traders
415+ // Custom batch orders for professional traders
424416 pub fn custom_batch_orders (
425- & self , order_requests : Vec < CustomOrderRequest > ,
417+ & self , order_requests : Vec < OrderRequest > ,
426418 ) -> Result < Vec < TransactionOrError > > {
427419 if order_requests. is_empty ( ) {
428420 return Ok ( Vec :: new ( ) ) ;
429421 }
430422 let mut parameters = BTreeMap :: new ( ) ;
431423 let mut orders = Vec :: new ( ) ;
432- for order_request in order_requests {
433- let order = OrderRequest {
434- symbol : order_request. symbol ,
435- side : order_request. side ,
436- position_side : order_request. position_side ,
437- order_type : order_request. order_type ,
438- time_in_force : order_request. time_in_force ,
439- qty : order_request. qty ,
440- reduce_only : order_request. reduce_only ,
441- price : order_request. price ,
442- stop_price : order_request. stop_price ,
443- close_position : order_request. close_position ,
444- activation_price : order_request. activation_price ,
445- callback_rate : order_request. callback_rate ,
446- working_type : order_request. working_type ,
447- price_protect : order_request. price_protect ,
448- } ;
424+ for order in order_requests {
449425 let order = self . build_order ( order) ;
450426 orders. push ( order) ;
451427 }
0 commit comments