From d4d22e07acc56db8dd0f60bfe2a2c6a4463a095c Mon Sep 17 00:00:00 2001 From: floor-licker Date: Tue, 4 Nov 2025 22:57:43 -0500 Subject: [PATCH] fix: omit duplicate methods --- src/client.rs | 102 +++-------------------------------------- src/lib.rs | 2 +- src/types.rs | 124 +++++++++++++++++++++++++++----------------------- 3 files changed, 75 insertions(+), 153 deletions(-) diff --git a/src/client.rs b/src/client.rs index 2cb015c..93b5087 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1152,107 +1152,19 @@ impl ClobClient { } } -// Response types for API calls -#[derive(Debug, serde::Deserialize)] -pub struct MarketsResponse { - pub limit: Decimal, - pub count: Decimal, - pub next_cursor: Option, - pub data: Vec, -} - -#[derive(Debug, serde::Deserialize)] -pub struct Market { - pub condition_id: String, - pub tokens: [Token; 2], - pub rewards: Rewards, - pub min_incentive_size: Option, - pub max_incentive_spread: Option, - pub active: bool, - pub closed: bool, - pub question_id: String, - pub minimum_order_size: Decimal, - pub minimum_tick_size: Decimal, - pub description: String, - pub category: Option, - pub end_date_iso: Option, - pub game_start_time: Option, - pub question: String, - pub market_slug: String, - pub seconds_delay: Decimal, - pub icon: String, - pub fpmm: String, -} - -#[derive(Debug, serde::Deserialize)] -pub struct Token { - pub token_id: String, - pub outcome: String, -} - -#[derive(Debug, serde::Deserialize)] -pub struct Rewards { - pub rates: Option, - pub min_size: Decimal, - pub max_spread: Decimal, - pub event_start_date: Option, - pub event_end_date: Option, - pub in_game_multiplier: Option, - pub reward_epoch: Option, -} - -#[derive(Debug, serde::Deserialize)] -pub struct OrderBookSummary { - pub market: String, - pub asset_id: String, - pub hash: String, - #[serde(deserialize_with = "crate::decode::deserializers::number_from_string")] - pub timestamp: u64, - pub bids: Vec, - pub asks: Vec, -} - -#[derive(Debug, serde::Deserialize)] -pub struct OrderSummary { - #[serde(with = "rust_decimal::serde::str")] - pub price: Decimal, - #[serde(with = "rust_decimal::serde::str")] - pub size: Decimal, -} - -#[derive(Debug, serde::Deserialize)] -pub struct MidpointResponse { - pub mid: Decimal, -} - -#[derive(Debug, serde::Deserialize)] -pub struct SpreadResponse { - pub spread: Decimal, -} - -#[derive(Debug, serde::Deserialize)] -pub struct PriceResponse { - pub price: Decimal, -} - -// Additional types for full compatibility with polymarket-rs-client -pub use crate::types::{ExtraOrderArgs, MarketOrderArgs}; +// Re-export types from the canonical location in types.rs +pub use crate::types::{ + ExtraOrderArgs, MarketOrderArgs, OrderBookSummary, OrderSummary, + MidpointResponse, SpreadResponse, PriceResponse, TickSizeResponse, + NegRiskResponse, MarketsResponse, Market, Token, Rewards, +}; +// Compatibility types that need to stay in client.rs #[derive(Debug, Default)] pub struct CreateOrderOptions { pub tick_size: Option, pub neg_risk: Option, } -#[derive(Debug, serde::Deserialize)] -pub struct TickSizeResponse { - pub minimum_tick_size: Decimal, -} - -#[derive(Debug, serde::Deserialize)] -pub struct NegRiskResponse { - pub neg_risk: bool, -} - // Re-export for compatibility pub type PolyfillClient = ClobClient; \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index e3b4ea2..d39e8de 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -101,7 +101,7 @@ pub use crate::types::{ // Additional compatibility types ApiKeysResponse, MidpointResponse, PriceResponse, SpreadResponse, TickSizeResponse, NegRiskResponse, BookParams, MarketsResponse, SimplifiedMarketsResponse, Market, - SimplifiedMarket, Token, Rewards, ClientResult, + SimplifiedMarket, Token, Rewards, ClientResult, OrderBookSummary, OrderSummary, }; // Re-export client diff --git a/src/types.rs b/src/types.rs index 5afd89e..d99c1e2 100644 --- a/src/types.rs +++ b/src/types.rs @@ -861,6 +861,52 @@ pub struct BalanceAllowance { pub allowance: Decimal, } +/// Parameters for balance allowance queries (from reference implementation) +#[derive(Default)] +pub struct BalanceAllowanceParams { + pub asset_type: Option, + pub token_id: Option, + pub signature_type: Option, +} + +impl BalanceAllowanceParams { + pub fn to_query_params(&self) -> Vec<(&str, String)> { + let mut params = Vec::with_capacity(3); + + if let Some(x) = &self.asset_type { + params.push(("asset_type", x.to_string())); + } + + if let Some(x) = &self.token_id { + params.push(("token_id", x.to_string())); + } + + if let Some(x) = &self.signature_type { + params.push(("signature_type", x.to_string())); + } + params + } + + pub fn set_signature_type(&mut self, s: u8) { + self.signature_type = Some(s); + } +} + +/// Asset type enum for balance allowance queries +pub enum AssetType { + COLLATERAL, + CONDITIONAL, +} + +impl ToString for AssetType { + fn to_string(&self) -> String { + match self { + AssetType::COLLATERAL => "COLLATERAL".to_string(), + AssetType::CONDITIONAL => "CONDITIONAL".to_string(), + } + } +} + /// Notification preferences #[derive(Debug, Clone, Serialize, Deserialize)] pub struct NotificationParams { @@ -946,6 +992,25 @@ pub struct BookParams { pub side: Side, } +#[derive(Debug, Deserialize)] +pub struct OrderBookSummary { + pub market: String, + pub asset_id: String, + pub hash: String, + #[serde(deserialize_with = "crate::decode::deserializers::number_from_string")] + pub timestamp: u64, + pub bids: Vec, + pub asks: Vec, +} + +#[derive(Debug, Deserialize)] +pub struct OrderSummary { + #[serde(with = "rust_decimal::serde::str")] + pub price: Decimal, + #[serde(with = "rust_decimal::serde::str")] + pub size: Decimal, +} + #[derive(Debug, Serialize, Deserialize)] pub struct MarketsResponse { #[serde(with = "rust_decimal::serde::str")] @@ -966,63 +1031,8 @@ pub struct SimplifiedMarketsResponse { pub data: Vec, } -#[derive(Debug, Serialize, Deserialize)] -pub struct Market { - pub condition_id: String, - pub tokens: [Token; 2], - pub rewards: Rewards, - pub min_incentive_size: Option, - pub max_incentive_spread: Option, - pub active: bool, - pub closed: bool, - pub question_id: String, - #[serde(with = "rust_decimal::serde::str")] - pub minimum_order_size: Decimal, - #[serde(with = "rust_decimal::serde::str")] - pub minimum_tick_size: Decimal, - pub description: String, - pub category: Option, - pub end_date_iso: Option, - pub game_start_time: Option, - pub question: String, - pub market_slug: String, - #[serde(with = "rust_decimal::serde::str")] - pub seconds_delay: Decimal, - pub icon: String, - pub fpmm: String, -} - -#[derive(Debug, Serialize, Deserialize)] -pub struct SimplifiedMarket { - pub condition_id: String, - pub tokens: [Token; 2], - pub rewards: Rewards, - pub min_incentive_size: Option, - pub max_incentive_spread: Option, - pub active: bool, - pub closed: bool, -} - -#[derive(Debug, Serialize, Deserialize)] -pub struct Token { - pub token_id: String, - pub outcome: String, -} - -#[derive(Debug, Serialize, Deserialize)] -pub struct Rewards { - pub rates: Option, - #[serde(with = "rust_decimal::serde::str")] - pub min_size: Decimal, - #[serde(with = "rust_decimal::serde::str")] - pub max_spread: Decimal, - pub event_start_date: Option, - pub event_end_date: Option, - #[serde(with = "rust_decimal::serde::str", skip_serializing_if = "Option::is_none")] - pub in_game_multiplier: Option, - #[serde(with = "rust_decimal::serde::str", skip_serializing_if = "Option::is_none")] - pub reward_epoch: Option, -} +// Note: Market, Token, Rewards, and SimplifiedMarket are already defined above in this file +// These duplicate definitions have been removed to avoid conflicts // For compatibility with reference implementation pub type ClientResult = anyhow::Result;