Skip to main content

polyester/
lib.rs

1//! Official Rust SDK for Polyester APIs.
2//!
3//! Built on [Connect for Rust](https://github.com/connectrpc/connect-rust) and
4//! Polyester's published Protobuf contracts (Buffa + Connect codegen).
5//!
6//! # Quick start
7//!
8//! ```rust,no_run
9//! use polyester::{Client, Config};
10//! use polyester::types::{Price, Quantity};
11//!
12//! #[tokio::main]
13//! async fn main() -> polyester::Result<()> {
14//!     let client = Client::new(Config {
15//!         api_key_id: Some("ak_...".into()),
16//!         api_private_key: Some("...".into()),
17//!         default_account_id: Some("...".into()),
18//!         ..Default::default()
19//!     })?;
20//!     let _ = client.auth.me().await?;
21//!     Ok(())
22//! }
23//! ```
24//!
25//! # Qty / price
26//!
27//! Order write APIs take [`types::Price`] / [`types::Quantity`] only:
28//! - Humans: `Price::from_decimal_str("1.5")` / `Quantity::from_decimal_str("0.01", scale, …)`
29//! - Bots: `Price::from_ticks(1_500_000)` / `Quantity::from_scaled(…)`
30//!
31//! Floats and bare integers are rejected.
32
33#![cfg_attr(docsrs, feature(doc_cfg))]
34#![allow(clippy::module_inception)]
35
36/// Generated Buffa message types (`crate::proto` for Connect stubs).
37pub mod proto;
38
39/// Generated ConnectRPC service clients and server traits.
40#[path = "connect_gen/mod.rs"]
41pub mod connect;
42
43pub mod auth;
44pub mod catalogs;
45pub mod client;
46pub mod codecs;
47pub mod errors;
48pub mod marketoverview;
49pub mod models;
50pub mod orderbook;
51pub mod services;
52pub mod transport;
53pub mod types;
54pub mod user_agent;
55
56pub mod realtime;
57
58/// On-chain Funding and smart-account helpers.
59///
60/// Calldata encoders, Safe CREATE2 prediction, and UserOperation submit.
61pub mod chain;
62
63pub use client::{Client, Config};
64pub use errors::{Error, Result, auth_codes};
65pub use services::{
66    PreparedTradingWithdraw, new_trading_withdraw_idempotency_key, new_trading_withdraw_nonce,
67};
68pub use types::{
69    AssetAmount, Price, PriceTicks, QtyScaled, Quantity, QuantityDomain,
70    resolve_asset_amount_scaled, resolve_price_ticks, resolve_qty_scaled, resolve_quote_qty_scaled,
71};
72
73pub const VERSION: &str = env!("CARGO_PKG_VERSION");