use polyoxide_clob::{Account, Clob, CreateOrderParams, OrderKind, OrderSide};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
dotenvy::dotenv().ok();
tracing_subscriber::fmt::init();
println!("Loading account from environment variables...");
let account = Account::from_env().unwrap();
println!("Account address: {:?}", account.address());
println!("Wallet address: {:?}", account.wallet());
let clob = Clob::from_account(account.clone())?;
let token_id = "102559817034631022221500208641784929295731053857601013029449249654006364919935"
.to_string();
let params = CreateOrderParams {
token_id,
price: 0.05,
size: 100.,
side: OrderSide::Buy,
order_type: OrderKind::Gtc,
post_only: false,
expiration: None,
funder: None, signature_type: Some(polyoxide_clob::SignatureType::PolyProxy), };
println!("\n📝 Creating order with params:");
println!(" Token ID: {}...", ¶ms.token_id[..30]);
println!(" Price: {}", params.price);
println!(" Size: {} shares", params.size);
println!(" Side: {:?}", params.side);
println!(" Order Type: {:?}", params.order_type);
println!("\n🔄 Creating and signing order...");
let order = clob.create_order(¶ms, None).await?;
println!(" Salt: {}", order.salt);
println!(" Maker: {:?}", order.maker);
println!(" Maker Amount: {}", order.maker_amount);
println!(" Taker Amount: {}", order.taker_amount);
println!("\n✍️ Signing order...");
let signed_order = clob.sign_order(&order).await?;
println!(
" Signature: {}...{}",
&signed_order.signature[..10],
&signed_order.signature[signed_order.signature.len() - 6..]
);
println!("\n🚀 Posting order to CLOB...");
match clob
.post_order(&signed_order, params.order_type, params.post_only)
.await
{
Ok(response) => {
println!("\n✅ Order placed successfully!");
println!(" Success: {}", response.success);
if let Some(order_id) = &response.order_id {
println!(" Order ID: {}", order_id);
}
if let Some(error) = &response.error_msg {
println!(" Error: {}", error);
}
if !response.transaction_hashes.is_empty() {
println!(" Tx Hashes: {:?}", response.transaction_hashes);
}
}
Err(e) => {
println!("\n❌ Order failed: {}", e);
return Err(e.into());
}
}
Ok(())
}