Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/bin/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ async fn main() {
user_states_example(&info_client).await;
recent_trades(&info_client).await;
meta_example(&info_client).await;
meta_and_asset_contexts_example(&info_client).await;
all_mids_example(&info_client).await;
user_fills_example(&info_client).await;
funding_history_example(&info_client).await;
Expand Down Expand Up @@ -68,6 +69,13 @@ async fn meta_example(info_client: &InfoClient) {
info!("Metadata: {:?}", info_client.meta().await.unwrap());
}

async fn meta_and_asset_contexts_example(info_client: &InfoClient) {
info!(
"MetaAndAssetContexts: {:?}",
info_client.meta_and_asset_contexts().await.unwrap()
);
}

async fn all_mids_example(info_client: &InfoClient) {
info!("All mids: {:?}", info_client.all_mids().await.unwrap());
}
Expand Down
11 changes: 10 additions & 1 deletion src/info/info_client.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
info::{
CandlesSnapshotResponse, FundingHistoryResponse, L2SnapshotResponse, OpenOrdersResponse,
RecentTradesResponse, UserFillsResponse, UserStateResponse,
RecentTradesResponse, UserFillsResponse, UserStateResponse, MetaAndAssetContexts
},
meta::{Meta, SpotMeta},
prelude::*,
Expand Down Expand Up @@ -41,6 +41,7 @@ pub enum InfoRequest {
user: H160,
},
Meta,
MetaAndAssetCtxs,
SpotMeta,
AllMids,
UserFills {
Expand Down Expand Up @@ -147,6 +148,14 @@ impl InfoClient {
serde_json::from_str(&return_data).map_err(|e| Error::JsonParse(e.to_string()))
}

pub async fn meta_and_asset_contexts(&self) -> Result<Vec<MetaAndAssetContexts>> {
let input = InfoRequest::MetaAndAssetCtxs;
let data = serde_json::to_string(&input).map_err(|e| Error::JsonParse(e.to_string()))?;

let return_data = self.http_client.post("/info", data).await?;
serde_json::from_str(&return_data).map_err(|e| Error::JsonParse(e.to_string()))
}

pub async fn spot_meta(&self) -> Result<SpotMeta> {
let input = InfoRequest::SpotMeta;
let data = serde_json::to_string(&input).map_err(|e| Error::JsonParse(e.to_string()))?;
Expand Down
22 changes: 21 additions & 1 deletion src/info/response_structs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::info::{AssetPosition, Level, MarginSummary};
use crate::{info::{AssetPosition, Level, MarginSummary}, meta::Meta};
use serde::Deserialize;

#[derive(Deserialize, Debug)]
Expand Down Expand Up @@ -88,3 +88,23 @@ pub struct CandlesSnapshotResponse {
#[serde(rename = "n")]
pub num_trades: u64,
}

#[derive(Deserialize, Debug, Clone)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably move this to meta.rs

#[serde(untagged)]
pub enum MetaAndAssetContexts {
Meta(Meta),
Context(Vec<AssetContext>),
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct AssetContext {
pub day_ntl_vlm: String,
pub funding: String,
pub impact_pxs: Option<Vec<String>>,
pub mark_px: String,
pub mid_px: Option<String>,
pub open_interest: String,
pub oracle_px: String,
pub premium: Option<String>,
pub prev_day_px: String,
}