polymarket-rs-client 0.1.1

An async client to interact with polymarket.
Documentation
use std::str::FromStr;

use rust_decimal::prelude::FromPrimitive;

use super::*;
use crate::utils::get_current_unix_time_secs;
const POLY_CLOB_HOST: &str = "https://clob.polymarket.com";

#[tokio::test]
async fn l2_header_hmac_test() {
    let host = "https://clob.polymarket.com";
    let polygon = 137;
    let mut client = ClobClient::with_l1_headers(
        host,
        "0xdda00f03e28953ec80f9585caae811cab57472deae5579c74d7be5c1d34113e2",
        polygon,
    );

    let keys = client.create_or_derive_api_key(None).await.unwrap();
    client.set_api_creds(keys);

    let order_args = OrderArgs::new(
        "114761267365478898980972715831447821668602311520659390392678082367909012888961",
        Decimal::from_f32(0.5).unwrap(),
        Decimal::ONE,
        Side::BUY,
    );

    let order = client
        .create_order(&order_args, Some(1000000000000), None, None)
        .await
        .unwrap();

    let o = client.post_order(order, OrderType::GTC).await.unwrap();

    //println!("Del: {:?}", client.delete_api_key().await.unwrap());
}


// #[tokio::test]
// async fn get_order_data() {
//     let host = "https://clob.polymarket.com";
//     let polygon = 137;
//     let mut client = ClobClient::with_l1_headers(
//         host,
//         "0xdda00f03e28953ec80f9585caae811cab57472deae5579c74d7be5c1d34113e2",
//         polygon,
//     );
//
//     let keys = client.create_or_derive_api_key(None).await.unwrap();
//     client.set_api_creds(keys);
//
//     let order_args = OrderArgs::new(
//         "114761267365478898980972715831447821668602311520659390392678082367909012888961",
//         Decimal::from_f32(0.5).unwrap(),
//         Decimal::ONE,
//         Side::BUY,
//     );
//
//     println!(
//         "Order: {:?}",
//         client
//             .create_order(&order_args, Some(1000000000000), None, None)
//             .await
//     );
//     //println!("Del: {:?}", client.delete_api_key().await.unwrap());
// }
//
// #[tokio::test]
// async fn server_time_close_to_local() {
//     let client = ClobClient::new(POLY_CLOB_HOST);
//     let curr_time = get_current_unix_time_secs();
//     assert!((client.get_server_time().await.unwrap() as i64 - curr_time as i64).abs() < 2);
// }
//
// #[tokio::test]
// async fn server_is_ok() {
//     let client = ClobClient::new(POLY_CLOB_HOST);
//     assert!(client.get_ok().await)
// }
//
// #[tokio::test]
// async fn get_market_midpoint() {
//     let host = "https://clob.polymarket.com";
//     //let polygon = 137;
//     let client = ClobClient::new(host);
//     println!(
//         "Midpoint {:?}",
//         client
//             .get_midpoint(
//                 "114761267365478898980972715831447821668602311520659390392678082367909012888961"
//             )
//             .await
//     );
// }
//
// #[tokio::test]
// async fn get_market_midpoints() {
//     let host = "https://clob.polymarket.com";
//     //let polygon = 137;
//     let client = ClobClient::new(host);
//     println!(
//         "Midpoints {:?}",
//         client
//             .get_midpoints(&[
//                 "114761267365478898980972715831447821668602311520659390392678082367909012888961"
//                     .to_owned(),
//                 "50391675285588386773290115980531001416224432744549098276461120982910687652549"
//                     .to_owned(),
//             ])
//             .await
//     );
// }
//
// #[tokio::test]
// async fn get_price() {
//     let host = "https://clob.polymarket.com";
//     //let polygon = 137;
//     let client = ClobClient::new(host);
//     println!(
//         "Midpoint {:?}",
//         client
//             .get_price(
//                 "114761267365478898980972715831447821668602311520659390392678082367909012888961",
//                 Side::BUY
//             )
//             .await
//     );
// }
//
// #[tokio::test]
// async fn get_prices() {
//     let host = "https://clob.polymarket.com";
//     //let polygon = 137;
//     let client = ClobClient::new(host);
//     println!(
//         "Prices {:?}",
//         client
//             .get_prices(&[ BookParams {
//                 token_id:"114761267365478898980972715831447821668602311520659390392678082367909012888961"
//                     .to_owned(),
//                 side: Side::BUY },
//                 BookParams {
//                 token_id: "50391675285588386773290115980531001416224432744549098276461120982910687652549"
//                     .to_owned(),
//                     side:Side::BUY }
//             ])
//             .await
//     );
// }
//
// #[tokio::test]
// async fn get_spread() {
//     let host = "https://clob.polymarket.com";
//     //let polygon = 137;
//     let client = ClobClient::new(host);
//     println!(
//         "Spread {:?}",
//         client
//             .get_spread(
//                 "114761267365478898980972715831447821668602311520659390392678082367909012888961"
//             )
//             .await
//     );
// }
//
// #[tokio::test]
// async fn get_spreads() {
//     let host = "https://clob.polymarket.com";
//     //let polygon = 137;
//     let client = ClobClient::new(host);
//     println!(
//         "Spreads {:?}",
//         client
//             .get_spreads(&[
//                 "114761267365478898980972715831447821668602311520659390392678082367909012888961"
//                     .to_owned(),
//                 "50391675285588386773290115980531001416224432744549098276461120982910687652549"
//                     .to_owned(),
//             ])
//             .await
//     );
// }
//
#[tokio::test]
async fn get_tick_size() {
    let host = "https://clob.polymarket.com";
    //let polygon = 137;
    let client = ClobClient::new(host);
    println!(
        "Tick size {:?}",
        client
            .get_tick_size(
                "114761267365478898980972715831447821668602311520659390392678082367909012888961"
            )
            .await
    );
}
//
// #[tokio::test]
// async fn get_neg_risk() {
//     let host = "https://clob.polymarket.com";
//     //let polygon = 137;
//     let client = ClobClient::new(host);
//     println!(
//         "Neg risk {:?}",
//         client
//             .get_neg_risk(
//                 "114761267365478898980972715831447821668602311520659390392678082367909012888961"
//             )
//             .await
//     );
// }
//
// // #[tokio::test]
// // async fn api_key_create() {
// //     let host = "https://clob.polymarket.com";
// //     let polygon = 137;
// //     let client = ClobClient::with_l1_headers(
// //         host,
// //         "0xdda00f03e28953ec80f9585caae811cab57472deae5579c74d7be5c1d34113e2",
// //         polygon,
// //     );
// //
// //     println!("Key create test {:?}", client.create_api_key(None).await)
// // }
//
// // #[tokio::test]
// // async fn api_key_derive() {
// //     let host = "https://clob.polymarket.com";
// //     let polygon = 137;
// //     let client = ClobClient::with_l1_headers(
// //         host,
// //         "0xdda00f03e28953ec80f9585caae811cab57472deae5579c74d7be5c1d34113e2",
// //         polygon,
// //     );
// //
// //     println!("Key derive test {:?}", client.derive_api_key(None).await)
// // }
//
// #[tokio::test]
// async fn delete_api_key() {
//     let host = "https://clob.polymarket.com";
//     let polygon = 137;
//     let mut client = ClobClient::with_l1_headers(
//         host,
//         "0xdda00f03e28953ec80f9585caae811cab57472deae5579c74d7be5c1d34113e2",
//         polygon,
//     );
//
//     let keys = client.create_or_derive_api_key(None).await.unwrap();
//     client.set_api_creds(keys);
//
//     println!("KEys: {:?}", client.get_api_keys().await.unwrap());
//     println!("Del: {:?}", client.delete_api_key().await.unwrap());
// }