cefi_rs_bybit/rest/
position.rs1use std::collections::HashMap;
2
3use crate::{errors::BybitResult, http::BybitHttp, types::GetPositionResponse};
4
5impl BybitHttp {
6 pub async fn get_positions(&self) -> BybitResult<GetPositionResponse> {
7 let mut params = HashMap::new();
8 params.insert("category", "linear");
9 params.insert("settleCoin", "USDT");
10 params.insert("limit", "200");
11
12 self.send_get_request::<GetPositionResponse>("v5/position/list", params, true)
13 .await
14 }
15}
16
17#[cfg(test)]
18mod tests {
19 use super::*;
20 use dotenv::dotenv;
21
22 #[tokio::test]
23 async fn test_get_positions() -> BybitResult<()> {
24 dotenv().ok();
25 let api_key = std::env::var("BYBIT_API_KEY").expect("BYBIT_API_KEY");
26 let api_secret = std::env::var("BYBIT_API_SECRET").expect("BYBIT_API_SECRET");
27 let client = BybitHttp::new(api_key.to_string(), api_secret.to_string());
28 let res = client.get_positions().await;
29 println!("{:?}", res);
30 Ok(())
31 }
32}