Skip to main content

jupiter_sdk/api/
recurring.rs

1use crate::{
2    api::TransactionRequest, common::ExecuteRes, recurring::{
3        CancelRecurringOrderReq, 
4        CancelRecurringOrderRes, 
5        CreateRecurringOrderReq, 
6        CreateRecurringOrderRes, 
7        GetRecurringOrdersReq, 
8        GetRecurringOrdersRes, 
9        PriceDepositReq, 
10        PriceDepositRes, 
11        PriceWithdrawReq, 
12        PriceWithdrawRes,
13    }, JupiterClient, JupiterError
14};
15
16
17
18
19#[derive(Clone)]
20pub struct RecurringService<'a>{
21    client: &'a JupiterClient,
22}
23
24
25impl<'a> RecurringService<'a> {
26    pub fn new(client: &'a JupiterClient) -> Self {
27        Self { client }
28    }
29
30
31    pub async fn create_order(
32        &self,
33        req: &CreateRecurringOrderReq,
34    ) -> Result<CreateRecurringOrderRes, JupiterError> {
35        let path = "/recurring/v1/createOrder";
36        self.client.post(&path, req).await
37    }
38
39
40    pub async fn execute(
41        &self,
42        req: &TransactionRequest,
43    ) -> Result<ExecuteRes, JupiterError> {
44        let path = "/recurring/v1/execute";
45        self.client.post(&path, req).await
46    }
47
48    pub async fn cancel_order(
49        &self,
50        req: &CancelRecurringOrderReq,
51    ) -> Result<CancelRecurringOrderRes, JupiterError> {
52        let path = "/recurring/v1/cancelOrder";
53        self.client.post(&path, req).await
54    }
55
56    pub async fn price_deposit(
57        &self,
58        req: &PriceDepositReq,
59    ) -> Result<PriceDepositRes, JupiterError> {
60        let path = "/recurring/v1/priceDeposit";
61        self.client.post(&path, req).await
62    }
63
64    pub async fn price_withdraw(
65        &self,
66        req: &PriceWithdrawReq,
67    ) -> Result<PriceWithdrawRes, JupiterError> {
68        let path = "/recurring/v1/priceWithdraw";
69        self.client.post(&path, req).await
70    }
71
72    pub async fn get_recurring_orders(
73        &self,
74        req: &GetRecurringOrdersReq,
75    ) -> Result<GetRecurringOrdersRes, JupiterError> {
76        let path = "/recurring/v1/getRecurringOrders";
77        self.client.get_json_with_query(&path, req).await
78    }
79}