lightcone 0.5.2

Rust SDK for the Lightcone Protocol — unified native + WASM client
Documentation
mod common;

use common::{fresh_order_nonce, get_keypair, market_and_orderbook, rest_client, ExampleResult};
use lightcone::prelude::*;
use solana_signer::Signer;
use std::sync::Arc;

#[tokio::main]
async fn main() -> ExampleResult {
    let client = rest_client()?;
    let keypair = get_keypair()?;
    let maker = keypair.pubkey();
    common::login(&client, &keypair, false).await?;
    client
        .set_signing_strategy(SigningStrategy::Native(Arc::new(keypair)))
        .await;

    let (_market, orderbook) = market_and_orderbook(&client).await?;

    // Fetch and cache the on-chain nonce once. Subsequent orders that omit
    // `.nonce()` will automatically use this cached value.
    let nonce = fresh_order_nonce(&client, &maker).await?;
    client.set_order_nonce(nonce).await;

    // submit() auto-populates nonce from cache when `.nonce()` is not called.
    let response = client
        .orders()
        .limit_order()
        .await
        .maker(maker)
        .bid()
        .price("0.55")
        .size("2")
        .salt(lightcone::program::orders::generate_salt())
        .submit(&client, &orderbook)
        .await?;
    println!(
        "submitted: {} filled={} remaining={} fills={}",
        response.order_hash,
        response.filled,
        response.remaining,
        response.fills.len()
    );
    Ok(())
}