opensea-stream

Crates.ioopensea-stream
lib.rsopensea-stream
version0.3.0
sourcesrc
created_at2022-07-08 15:51:38.3705
updated_at2022-09-12 01:10:46.512939
descriptionClient for receiving updates from the OpenSea Stream API over websockets
homepage
repositoryhttps://github.com/wanderers-nft/opensea-stream-rs
max_upload_size
id621952
size41,640
Emerald (the-emerald)

documentation

README

opensea-stream

Crate for receiving updates from the OpenSea Stream API. This crate is a thin wrapper over phyllo with a few convenience functions and struct definitions for the event schema. It is recommended that you also read the documentation of phyllo to understand the Phoenix protocol which delivers these messages.

Example

The following example prints all listings of items in the wandernauts collection as they are created.

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let mut client = client(Network::Mainnet, "YOUR_API_KEY_HERE").await;

    // Subscribe to a collection. Note that you must all subscribe to all events
    // in the collection; filtering is your responsibility (see below).
    let (handler, mut subscription) = subscribe_to(
        &mut client,
        Collection::Collection("wandernauts".to_string()),
    )
    .await?;

    // To unsubscribe:
    // handler.close().await?;

    loop {
        // The message received from the channel is a raw message of the Phoenix protocol.
        // It may or may not contain a payload.
        let event = match subscription.recv().await?.into_custom_payload() {
            Some(v) => v,
            None => {
                eprintln!("unexpected message");
                continue;
            }
        };

        // Only print item listing events.
        if let schema::Payload::ItemListed(listing) = event.payload {
            println!("{:?}", listing);
        }
    }
}

Features

rustls-tls-native-roots (which uses rustls-native-certs for root certificates) is enabled by default. To use rustls-tls-webpki-roots (webpki-roots) instead, include this in your Cargo.toml:

opensea-stream = { version = "0.1", default-features = false, features = ["rustls-tls-webpki-roots"] }
Commit count: 32

cargo fmt