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
6 changes: 1 addition & 5 deletions examples/balance_allowance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ async fn main() -> Result<()> {

let l1_client = ClobClient::with_l1_headers(&base_url, &private_key, chain_id);
let creds = l1_client.create_or_derive_api_key(None).await?;
let mut client = ClobClient::with_l2_headers(&base_url, &private_key, chain_id, creds.clone());

if let Ok(funder) = env::var("POLY_FUNDER") {
client.set_funder(&funder)?;
}
let client = ClobClient::with_l2_headers(&base_url, &private_key, chain_id, creds.clone());

let mut params = BalanceAllowanceParams::default();
params.asset_type = Some(AssetType::COLLATERAL);
Expand Down
4 changes: 0 additions & 4 deletions examples/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ async fn main() -> Result<()> {
let creds = l1_client.create_or_derive_api_key(None).await?;
let mut client = ClobClient::with_l2_headers(&base_url, &private_key, chain_id, creds.clone());

if let Ok(funder) = env::var("POLY_FUNDER") {
client.set_funder(&funder)?;
}

let gamma_params = GammaListParams {
limit: Some(5), // how many markets to fetch max
..Default::default()
Expand Down
4 changes: 0 additions & 4 deletions examples/wss_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ async fn main() -> Result<()> {
let mut l2_client =
ClobClient::with_l2_headers(&base_url, &private_key, chain_id, creds.clone());

if let Ok(funder) = env::var("POLY_FUNDER") {
l2_client.set_funder(&funder)?;
}

let min_liquidity = env::var("POLY_WSS_MIN_LIQUIDITY")
.ok()
.and_then(|value| Decimal::from_str(&value).ok())
Expand Down
23 changes: 17 additions & 6 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ impl ClobClient {
api_creds: Some(api_creds),
order_builder: Some(order_builder),
}
.with_env_funder()
}

/// Set API credentials
Expand All @@ -186,6 +187,14 @@ impl ClobClient {
Ok(())
}

fn with_env_funder(mut self) -> Self {
if let Ok(funder) = env::var("POLY_FUNDER") {
self.set_funder(&funder)
.unwrap_or_else(|err| panic!("Failed to set funder from POLY_FUNDER: {}", err));
}
self
}

/// Override the Gamma API base URL
pub fn with_gamma_base(mut self, url: &str) -> Self {
self.gamma_base_url = url.to_string();
Expand Down Expand Up @@ -793,7 +802,10 @@ impl ClobClient {
if !response.status().is_success() {
return Err(PolyError::api(
response.status().as_u16(),
format!("Failed to post batch orders: {}", response.text().await.unwrap()),
format!(
"Failed to post batch orders: {}",
response.text().await.unwrap()
),
));
}

Expand Down Expand Up @@ -1724,8 +1736,8 @@ impl ClobClient {
.await
.map_err(|e| PolyError::parse(format!("Failed to read response body: {}", e), None))?;

let gamma_market = serde_json::from_str::<crate::types::GammaMarket>(&body)
.map_err(|err| {
let gamma_market =
serde_json::from_str::<crate::types::GammaMarket>(&body).map_err(|err| {
PolyError::parse(
format!("Failed to parse market {}: {}", market_id, err),
None,
Expand Down Expand Up @@ -1883,9 +1895,8 @@ impl ClobClient {
value
};

serde_json::from_value::<Vec<T>>(payload).map_err(|err| {
PolyError::parse(format!("Failed to parse {}: {}", ctx, err), None)
})
serde_json::from_value::<Vec<T>>(payload)
.map_err(|err| PolyError::parse(format!("Failed to parse {}: {}", ctx, err), None))
}
}

Expand Down