1use crate::client::{DhanClient, required_path_segment};
4use crate::error::Result;
5use crate::types::orders::*;
6
7impl DhanClient {
8 pub async fn place_order(&self, req: &PlaceOrderRequest) -> Result<OrderResponse> {
12 self.post("/v2/orders", req).await
13 }
14
15 pub async fn modify_order(
19 &self,
20 order_id: &str,
21 req: &ModifyOrderRequest,
22 ) -> Result<OrderResponse> {
23 let order_id = required_path_segment("order_id", order_id)?;
24 self.put(&format!("/v2/orders/{order_id}"), req).await
25 }
26
27 pub async fn cancel_order(&self, order_id: &str) -> Result<OrderResponse> {
31 let order_id = required_path_segment("order_id", order_id)?;
32 self.delete(&format!("/v2/orders/{order_id}")).await
33 }
34
35 pub async fn slice_order(&self, req: &PlaceOrderRequest) -> Result<Vec<OrderResponse>> {
39 self.post("/v2/orders/slicing", req).await
40 }
41
42 pub async fn get_orders(&self) -> Result<Vec<OrderDetail>> {
46 self.get("/v2/orders").await
47 }
48
49 pub async fn get_order(&self, order_id: &str) -> Result<OrderDetail> {
53 let order_id = required_path_segment("order_id", order_id)?;
54 self.get(&format!("/v2/orders/{order_id}")).await
55 }
56
57 pub async fn get_order_by_correlation_id(&self, correlation_id: &str) -> Result<OrderDetail> {
61 let correlation_id = required_path_segment("correlation_id", correlation_id)?;
62 self.get(&format!("/v2/orders/external/{correlation_id}"))
63 .await
64 }
65
66 pub async fn get_trades(&self) -> Result<Vec<TradeDetail>> {
70 self.get("/v2/trades").await
71 }
72
73 pub async fn get_trades_for_order(&self, order_id: &str) -> Result<Vec<TradeDetail>> {
77 let order_id = required_path_segment("order_id", order_id)?;
78 self.get(&format!("/v2/trades/{order_id}")).await
79 }
80}