|
| 1 | +use drift_sdk::math::leverage::get_leverage; |
1 | 2 | use drift_sdk::{ |
2 | 3 | constants::{ProgramData, BASE_PRECISION}, |
3 | 4 | dlob_client::DLOBClient, |
@@ -26,7 +27,7 @@ use crate::{ |
26 | 27 | GetOrderbookRequest, GetOrdersRequest, GetOrdersResponse, GetPositionsRequest, |
27 | 28 | GetPositionsResponse, Market, MarketInfoResponse, ModifyOrdersRequest, Order, OrderbookL2, |
28 | 29 | PerpPosition, PerpPositionExtended, PlaceOrdersRequest, SolBalanceResponse, SpotPosition, |
29 | | - TxEventsResponse, TxResponse, UserMarginResponse, PRICE_DECIMALS, |
| 30 | + TxEventsResponse, TxResponse, UserMarginResponse, UserLeverageResponse, PRICE_DECIMALS, |
30 | 31 | }, |
31 | 32 | websocket::map_drift_event_for_account, |
32 | 33 | Context, LOG_TARGET, |
@@ -216,6 +217,16 @@ impl AppState { |
216 | 217 | .map_err(|err| ControllerError::Sdk(err)) |
217 | 218 | } |
218 | 219 |
|
| 220 | + pub async fn get_leverage(&self, ctx: Context) -> GatewayResult<UserLeverageResponse> { |
| 221 | + let sub_account = self.resolve_sub_account(ctx.sub_account_id); |
| 222 | + get_leverage( |
| 223 | + &self.client, |
| 224 | + &self.client.get_user_account(&sub_account).await?, |
| 225 | + ) |
| 226 | + .map(Into::into) |
| 227 | + .map_err(|err| ControllerError::Sdk(err)) |
| 228 | + } |
| 229 | + |
219 | 230 | pub async fn get_position_extended( |
220 | 231 | &self, |
221 | 232 | ctx: Context, |
|
0 commit comments