-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathgtc_limit_buy.rs
More file actions
43 lines (36 loc) · 1.33 KB
/
gtc_limit_buy.rs
File metadata and controls
43 lines (36 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#![allow(
clippy::print_stdout,
reason = "Examples print their results to stdout"
)]
//! Place a resting GTC limit buy. Sits on the book until filled or cancelled.
use std::str::FromStr as _;
use alloy::signers::Signer as _;
use alloy::signers::local::LocalSigner;
use polymarket_client_sdk_v2::clob::types::{OrderType, Side};
use polymarket_client_sdk_v2::clob::{Client, Config};
use polymarket_client_sdk_v2::types::{Decimal, U256};
use polymarket_client_sdk_v2::{POLYGON, PRIVATE_KEY_VAR};
use polymarket_client_sdk_v2::CLOB_HOST;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let host =
std::env::var("CLOB_API_URL").unwrap_or_else(|_| CLOB_HOST.into());
let token_id = U256::from_str(&std::env::var("TOKEN_ID")?)?;
let signer =
LocalSigner::from_str(&std::env::var(PRIVATE_KEY_VAR)?)?.with_chain_id(Some(POLYGON));
let client = Client::new(&host, Config::default())?
.authentication_builder(&signer)
.authenticate()
.await?;
let resp = client
.limit_order()
.token_id(token_id)
.side(Side::Buy)
.price(Decimal::from_str("0.4")?)
.size(Decimal::from_str("100")?)
.order_type(OrderType::GTC)
.build_sign_and_post(&signer)
.await?;
println!("order_id={} status={}", resp.order_id, resp.status);
Ok(())
}