Skip to content

openfeed-org/sdk-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SDK-Rust

Facilitates client connections and message parsing using the Openfeed Protocol for streaming Barchart market data.

Installation

The SDK offers a basic blocking streaming client or one compatible with one of the popular async runtimes:

Blocking:

[dependencies]
sdk-rust = { git = "https://github.com/openfeed-org/sdk-rust", features=["blocking"]}

Non-blocking:

[dependencies]
sdk-rust = { git = "https://github.com/openfeed-org/sdk-rust", features=["tokio-runtime"]}

At least one runtime feature must be provided in order to use the client.

Usage

Upon connection, the client may subscribe to either individual symbols or entire exchanges. More information about the available methods here. Streaming data can be accessed from the client via a Feed type which is either an Iterator or Stream depending on the runtime feature selected. Feed messages can be read off the stream with read_messages() or as raw bytes with read_bytes().

use {
    sdk_rust::{
        client, error,
        openfeed::{Service, SubscriptionType, openfeed_gateway_message::Data::*},
    },
};

fn main() -> Result<(), error::OpenfeedError> {
    let symbols = vec!["GCQ26","GCU26"];

    let mut c = client::OpenfeedClient::new(
        client::OpenfeedConfig::default()
            .username("<user>")
            .password("<pass>"),
    );
    c.connect()?;
    c.subscribe_symbols(symbols, &[SubscriptionType::Quote], Service::RealTime)?;
    Ok(for message in c.read_messages() {
        match message?.data {
            Some(InstrumentDefinition(def)) => println!("definition: {:?}", def),
            Some(MarketUpdate(update))=> println!("update: {:?}", update),
            Some(HeartBeat(_)) => println!("hearbeat"),
            _ => {/* ignore other message types */},
        }
    })
}

Provided are some examples of the different client types to try yourself:

Blocking (sync.rs)

cargo run --example sync --features blocking -- -u <user> -p <pass> GCQ26,GCU26

Tokio (tokio_async.rs)

cargo run --example tokio_async --features tokio-runtime -- -u <user> -p <pass> GCQ26,GCU26

About

Rust SDK for Barchart Openfeed

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages