#stream #nft #opensea

opensea-stream

Client for receiving updates from the OpenSea Stream API over websockets

4 releases (2 breaking)

0.3.0 Sep 12, 2022
0.2.0 Jul 29, 2022
0.1.1 Jul 11, 2022
0.1.0 Jul 8, 2022

#114 in #nft

Download history

91 downloads per month

MIT/Apache

31KB
533 lines

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"] }

Dependencies

~15–27MB
~425K SLoC