Skip to content

Commit 9f7c0cd

Browse files
authored
feat: add MetaAndAssetContexts to achieve `Retrieve perpetuals asset … (#103)
…contexts (includes mark price, current funding, open interest, etc.)`
1 parent 9cefd9d commit 9f7c0cd

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

src/bin/info.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ async fn main() {
1313
user_states_example(&info_client).await;
1414
recent_trades(&info_client).await;
1515
meta_example(&info_client).await;
16+
meta_and_asset_contexts_example(&info_client).await;
1617
all_mids_example(&info_client).await;
1718
user_fills_example(&info_client).await;
1819
funding_history_example(&info_client).await;
@@ -87,7 +88,14 @@ async fn recent_trades(info_client: &InfoClient) {
8788
}
8889

8990
async fn meta_example(info_client: &InfoClient) {
90-
info!("Metadata: {:?}", info_client.meta().await.unwrap());
91+
info!("Meta: {:?}", info_client.meta().await.unwrap());
92+
}
93+
94+
async fn meta_and_asset_contexts_example(info_client: &InfoClient) {
95+
info!(
96+
"Meta and asset contexts: {:?}",
97+
info_client.meta_and_asset_contexts().await.unwrap()
98+
);
9199
}
92100

93101
async fn all_mids_example(info_client: &InfoClient) {

src/info/info_client.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{
33
CandlesSnapshotResponse, FundingHistoryResponse, L2SnapshotResponse, OpenOrdersResponse,
44
OrderInfo, RecentTradesResponse, UserFillsResponse, UserStateResponse,
55
},
6-
meta::{Meta, SpotMeta, SpotMetaAndAssetCtxs},
6+
meta::{AssetContext, Meta, SpotMeta, SpotMetaAndAssetCtxs},
77
prelude::*,
88
req::HttpClient,
99
ws::{Subscription, WsManager},
@@ -53,6 +53,7 @@ pub enum InfoRequest {
5353
oid: u64,
5454
},
5555
Meta,
56+
MetaAndAssetCtxs,
5657
SpotMeta,
5758
SpotMetaAndAssetCtxs,
5859
AllMids,
@@ -205,6 +206,11 @@ impl InfoClient {
205206
self.send_info_request(input).await
206207
}
207208

209+
pub async fn meta_and_asset_contexts(&self) -> Result<(Meta, Vec<AssetContext>)> {
210+
let input = InfoRequest::MetaAndAssetCtxs;
211+
self.send_info_request(input).await
212+
}
213+
208214
pub async fn spot_meta(&self) -> Result<SpotMeta> {
209215
let input = InfoRequest::SpotMeta;
210216
self.send_info_request(input).await

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ pub use exchange::*;
1717
pub use helpers::{bps_diff, truncate_float, BaseUrl};
1818
pub use info::{info_client::*, *};
1919
pub use market_maker::{MarketMaker, MarketMakerInput, MarketMakerRestingOrder};
20-
pub use meta::{AssetMeta, Meta, SpotAssetMeta, SpotMeta};
20+
pub use meta::{AssetContext, AssetMeta, Meta, MetaAndAssetCtxs, SpotAssetMeta, SpotMeta};
2121
pub use ws::*;

src/meta.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ pub enum SpotMetaAndAssetCtxs {
5252
Context(Vec<SpotAssetContext>),
5353
}
5454

55+
#[derive(Deserialize, Debug, Clone)]
56+
#[serde(untagged)]
57+
pub enum MetaAndAssetCtxs {
58+
Meta(Meta),
59+
Context(Vec<AssetContext>),
60+
}
61+
5562
#[derive(Deserialize, Debug, Clone)]
5663
#[serde(rename_all = "camelCase")]
5764
pub struct SpotAssetContext {
@@ -63,11 +70,28 @@ pub struct SpotAssetContext {
6370
pub coin: String,
6471
}
6572

73+
#[derive(Deserialize, Debug, Clone)]
74+
#[serde(rename_all = "camelCase")]
75+
pub struct AssetContext {
76+
pub day_ntl_vlm: String,
77+
pub funding: String,
78+
pub impact_pxs: Vec<String>,
79+
pub mark_px: String,
80+
pub mid_px: Option<String>,
81+
pub open_interest: String,
82+
pub oracle_px: String,
83+
pub premium: String,
84+
pub prev_day_px: String,
85+
}
86+
6687
#[derive(Deserialize, Debug, Clone)]
6788
#[serde(rename_all = "camelCase")]
6889
pub struct AssetMeta {
6990
pub name: String,
7091
pub sz_decimals: u32,
92+
pub max_leverage: usize,
93+
#[serde(default)]
94+
pub only_isolated: Option<bool>,
7195
}
7296

7397
#[derive(Deserialize, Debug, Clone)]

0 commit comments

Comments
 (0)