-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor tick by tick / Cleanup examples (#200)
- Loading branch information
Showing
10 changed files
with
248 additions
and
146 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use std::time::Duration; | ||
|
||
use ibapi::contracts::Contract; | ||
use ibapi::market_data::realtime::LastTicks; | ||
use ibapi::Client; | ||
|
||
// This example demonstrates how to stream tick by tick data for the last price of a contract. | ||
|
||
fn main() { | ||
env_logger::init(); | ||
|
||
let connection_string = "127.0.0.1:4002"; | ||
println!("connecting to server @ {connection_string}"); | ||
|
||
let client = Client::connect(connection_string, 100).expect("connection failed"); | ||
|
||
let contract = Contract::stock("NVDA"); | ||
let ticks = client.tick_by_tick_all_last(&contract, 0, false).expect("failed to get ticks"); | ||
|
||
println!( | ||
"streaming all last price for security_type: {:?}, symbol: {}", | ||
contract.security_type, contract.symbol | ||
); | ||
|
||
for (i, tick) in ticks.timeout_iter(Duration::from_secs(10)).enumerate() { | ||
match tick { | ||
LastTicks::Trade(trade) => { | ||
println!("{}: {i:?} {trade:?}", contract.symbol); | ||
} | ||
LastTicks::Notice(notice) => { | ||
// server could send a notice if it doesn't recognize the contract | ||
println!("error_code: {}, error_message: {}", notice.code, notice.message); | ||
} | ||
} | ||
} | ||
|
||
// check for errors during streaming | ||
if let Some(error) = ticks.error() { | ||
println!("error: {}", error); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use std::time::Duration; | ||
|
||
use ibapi::contracts::Contract; | ||
use ibapi::market_data::realtime::BidAskTicks; | ||
use ibapi::Client; | ||
|
||
// This example demonstrates how to stream tick by tick data for the bid and ask price of a contract. | ||
|
||
fn main() { | ||
env_logger::init(); | ||
|
||
let connection_string = "127.0.0.1:4002"; | ||
println!("connecting to server @ {connection_string}"); | ||
|
||
let client = Client::connect(connection_string, 100).expect("connection failed"); | ||
|
||
let contract = Contract::stock("NVDA"); | ||
let ticks = client.tick_by_tick_bid_ask(&contract, 0, false).expect("failed to get ticks"); | ||
|
||
println!( | ||
"streaming bid/ask price for security_type: {:?}, symbol: {}", | ||
contract.security_type, contract.symbol | ||
); | ||
|
||
for (i, tick) in ticks.timeout_iter(Duration::from_secs(10)).enumerate() { | ||
match tick { | ||
BidAskTicks::BidAsk(bid_ask) => { | ||
println!("{}: {i:?} {bid_ask:?}", contract.symbol); | ||
} | ||
BidAskTicks::Notice(notice) => { | ||
// server could send a notice if it doesn't recognize the contract | ||
println!("error_code: {}, error_message: {}", notice.code, notice.message); | ||
} | ||
} | ||
} | ||
|
||
// check for errors during streaming | ||
if let Some(error) = ticks.error() { | ||
println!("error: {}", error); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use std::time::Duration; | ||
|
||
use ibapi::contracts::Contract; | ||
use ibapi::market_data::realtime::LastTicks; | ||
use ibapi::Client; | ||
|
||
// This example demonstrates how to stream tick by tick data for the last price of a contract. | ||
|
||
fn main() { | ||
env_logger::init(); | ||
|
||
let connection_string = "127.0.0.1:4002"; | ||
println!("connecting to server @ {connection_string}"); | ||
|
||
let client = Client::connect(connection_string, 100).expect("connection failed"); | ||
|
||
let contract = Contract::stock("NVDA"); | ||
let ticks = client.tick_by_tick_last(&contract, 0, false).expect("failed to get ticks"); | ||
|
||
println!( | ||
"streaming last price for security_type: {:?}, symbol: {}", | ||
contract.security_type, contract.symbol | ||
); | ||
|
||
for (i, tick) in ticks.timeout_iter(Duration::from_secs(10)).enumerate() { | ||
match tick { | ||
LastTicks::Trade(trade) => { | ||
println!("{}: {i:?} {trade:?}", contract.symbol); | ||
} | ||
LastTicks::Notice(notice) => { | ||
// server could send a notice if it doesn't recognize the contract | ||
println!("error_code: {}, error_message: {}", notice.code, notice.message); | ||
} | ||
} | ||
} | ||
|
||
// check for errors during streaming | ||
if let Some(error) = ticks.error() { | ||
println!("error: {}", error); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use std::time::Duration; | ||
|
||
use ibapi::contracts::Contract; | ||
use ibapi::market_data::realtime::MidpointTicks; | ||
use ibapi::Client; | ||
|
||
// This example demonstrates how to stream tick by tick data for the midpoint price of a contract. | ||
|
||
fn main() { | ||
env_logger::init(); | ||
|
||
let connection_string = "127.0.0.1:4002"; | ||
println!("connecting to server @ {connection_string}"); | ||
|
||
let client = Client::connect(connection_string, 100).expect("connection failed"); | ||
|
||
let contract = Contract::stock("NVDA"); | ||
let ticks = client.tick_by_tick_midpoint(&contract, 0, false).expect("failed to get ticks"); | ||
|
||
println!( | ||
"streaming midpoint price for security_type: {:?}, symbol: {}", | ||
contract.security_type, contract.symbol | ||
); | ||
|
||
for (i, tick) in ticks.timeout_iter(Duration::from_secs(10)).enumerate() { | ||
match tick { | ||
MidpointTicks::Midpoint(midpoint) => { | ||
println!("{}: {i:?} {midpoint:?}", contract.symbol); | ||
} | ||
MidpointTicks::Notice(notice) => { | ||
// server could send a notice if it doesn't recognize the contract | ||
println!("error_code: {}, error_message: {}", notice.code, notice.message); | ||
} | ||
} | ||
} | ||
|
||
// check for errors during streaming | ||
if let Some(error) = ticks.error() { | ||
println!("error: {}", error); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.