diff --git a/Cargo.toml b/Cargo.toml index 8f90fd58..a7df99b2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ibapi" -version = "0.4.3" +version = "0.5.0" edition = "2021" authors = ["Wil Boayue "] description = "A synchronous implementation of the Interactive Brokers TWS API." diff --git a/contributors/README.md b/contributors/README.md index 0230f05b..6429f253 100644 --- a/contributors/README.md +++ b/contributors/README.md @@ -13,3 +13,29 @@ RUST_LOG=debug cargo run --bin find_contract_details `RUST_LOG=debug` `IBAPI_RECORDING_DIR=/tmp` + +## Creating and publishing releases. + +1. Make sure build is clean and tests are passing. + +```bash +cargo build --all-targets +cargo test +``` + +2. Update version number in [Cargo.toml](https://github.com/wboayue/rust-ibapi/blob/76033d170f2b87d55ed2cd96fef17bf124161d5f/Cargo.toml#L3) using [semantic versioning](https://semver.org/). Commit and push. + +3. Create tag with new version number and push. + +```bash +git tag v0.4.0 main +git push origin tag v0.4.0 +``` + +4. [Create release](https://github.com/wboayue/rust-ibapi/releases/new) pointing to new tag. Describe changes in release. + +5. Publish to crates.io + +```bash +cargo publish +``` \ No newline at end of file diff --git a/examples/tick_by_tick.rs b/examples/tick_by_tick.rs index 68793578..97f775dc 100644 --- a/examples/tick_by_tick.rs +++ b/examples/tick_by_tick.rs @@ -42,7 +42,7 @@ fn main() { thread::sleep(Duration::from_secs(5)); } -fn stream_last(client: &mut Client, symbol: &str) -> anyhow::Result<()> { +fn stream_last(client: &mut Client, _symbol: &str) -> anyhow::Result<()> { let contract = contract_gc(); let ticks = client.tick_by_tick_last(&contract, 0, false)?; @@ -87,7 +87,7 @@ fn stream_all_last(client: &Client, symbol: &str) -> anyhow::Result<()> { Ok(()) } -fn stream_bid_ask(client: &mut Client, symbol: &str) -> anyhow::Result<()> { +fn stream_bid_ask(client: &mut Client, _symbol: &str) -> anyhow::Result<()> { let contract = contract_es(); let ticks = client.tick_by_tick_bid_ask(&contract, 0, false)?; @@ -98,7 +98,7 @@ fn stream_bid_ask(client: &mut Client, symbol: &str) -> anyhow::Result<()> { Ok(()) } -fn stream_mid_point(client: &mut Client, symbol: &str) -> anyhow::Result<()> { +fn stream_mid_point(client: &mut Client, _symbol: &str) -> anyhow::Result<()> { let contract = contract_es(); let ticks = client.tick_by_tick_midpoint(&contract, 0, false)?; diff --git a/src/accounts/decoders.rs b/src/accounts/decoders.rs index dc37e44a..911bbc72 100644 --- a/src/accounts/decoders.rs +++ b/src/accounts/decoders.rs @@ -53,7 +53,6 @@ pub(crate) fn decode_family_codes(message: &mut ResponseMessage) -> Result Option { - self.connection_time.clone() + self.connection_time } /// Returns the managed accounts. diff --git a/src/client/transport.rs b/src/client/transport.rs index 8d54caa7..58ce0a67 100644 --- a/src/client/transport.rs +++ b/src/client/transport.rs @@ -2,10 +2,10 @@ use std::collections::HashMap; use std::io::{prelude::*, Cursor}; use std::iter::Iterator; use std::net::TcpStream; +use std::sync::Mutex; use std::sync::{Arc, RwLock}; use std::thread::{self, JoinHandle}; use std::time::Duration; -use std::sync::Mutex; use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt}; use crossbeam::channel::{self, Receiver, Sender}; diff --git a/src/contracts/encoders.rs b/src/contracts/encoders.rs index 8ceed697..f51c4c74 100644 --- a/src/contracts/encoders.rs +++ b/src/contracts/encoders.rs @@ -81,7 +81,6 @@ pub(crate) fn request_market_rule(market_rule_id: i32) -> Result String { +impl Display for BarSize { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { match self { - Self::Sec => "1 sec".into(), - Self::Sec5 => "5 secs".into(), - Self::Sec15 => "15 secs".into(), - Self::Sec30 => "30 secs".into(), - Self::Min => "1 min".into(), - Self::Min2 => "2 mins".into(), - Self::Min3 => "3 mins".into(), - Self::Min5 => "5 mins".into(), - Self::Min15 => "15 mins".into(), - Self::Min20 => "20 mins".into(), - Self::Min30 => "30 mins".into(), - Self::Hour => "1 hour".into(), - Self::Hour2 => "2 hours".into(), - Self::Hour3 => "3 hours".into(), - Self::Hour4 => "4 hours".into(), - Self::Hour8 => "8 hours".into(), - Self::Day => "1 day".into(), - Self::Week => "1 week".into(), - Self::Month => "1 month".into(), + Self::Sec => write!(f, "1 sec"), + Self::Sec5 => write!(f, "5 secs"), + Self::Sec15 => write!(f, "15 secs"), + Self::Sec30 => write!(f, "30 secs"), + Self::Min => write!(f, "1 min"), + Self::Min2 => write!(f, "2 mins"), + Self::Min3 => write!(f, "3 mins"), + Self::Min5 => write!(f, "5 mins"), + Self::Min15 => write!(f, "15 mins"), + Self::Min20 => write!(f, "20 mins"), + Self::Min30 => write!(f, "30 mins"), + Self::Hour => write!(f, "1 hour"), + Self::Hour2 => write!(f, "2 hours"), + Self::Hour3 => write!(f, "3 hours"), + Self::Hour4 => write!(f, "4 hours"), + Self::Hour8 => write!(f, "8 hours"), + Self::Day => write!(f, "1 day"), + Self::Week => write!(f, "1 week"), + Self::Month => write!(f, "1 month"), } } } @@ -126,9 +125,9 @@ impl Duration { } } -impl ToString for Duration { - fn to_string(&self) -> String { - format!("{} {}", self.value, self.unit) +impl Display for Duration { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "{} {}", self.value, self.unit) } } @@ -265,18 +264,18 @@ pub enum WhatToShow { Schedule, } -impl ToString for WhatToShow { - fn to_string(&self) -> String { +impl std::fmt::Display for WhatToShow { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { match self { - Self::Trades => "TRADES".to_string(), - Self::MidPoint => "MIDPOINT".to_string(), - Self::Bid => "BID".to_string(), - Self::Ask => "ASK".to_string(), - Self::BidAsk => "BID_ASK".to_string(), - Self::HistoricalVolatility => "HISTORICAL_VOLATILITY".to_string(), - Self::OptionImpliedVolatility => "OPTION_IMPLIED_VOLATILITY".to_string(), - Self::FeeRate => "FEE_RATE".to_string(), - Self::Schedule => "SCHEDULE".to_string(), + Self::Trades => write!(f, "TRADES"), + Self::MidPoint => write!(f, "MIDPOINT"), + Self::Bid => write!(f, "BID"), + Self::Ask => write!(f, "ASK"), + Self::BidAsk => write!(f, "BID_ASK"), + Self::HistoricalVolatility => write!(f, "HISTORICAL_VOLATILITY"), + Self::OptionImpliedVolatility => write!(f, "OPTION_IMPLIED_VOLATILITY"), + Self::FeeRate => write!(f, "FEE_RATE"), + Self::Schedule => write!(f, "SCHEDULE"), } } } diff --git a/src/market_data/historical/encoders.rs b/src/market_data/historical/encoders.rs index ff683056..12273e6a 100644 --- a/src/market_data/historical/encoders.rs +++ b/src/market_data/historical/encoders.rs @@ -123,6 +123,7 @@ pub(super) fn encode_request_historical_data( } // Encodes message to request historical ticks +#[allow(clippy::too_many_arguments)] pub(super) fn encode_request_historical_ticks( request_id: i32, contract: &Contract, diff --git a/src/market_data/realtime.rs b/src/market_data/realtime.rs index 1ed32aa1..8ec405ca 100644 --- a/src/market_data/realtime.rs +++ b/src/market_data/realtime.rs @@ -106,13 +106,13 @@ pub enum WhatToShow { Ask, } -impl ToString for WhatToShow { - fn to_string(&self) -> String { +impl std::fmt::Display for WhatToShow { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { match self { - Self::Trades => "TRADES".to_string(), - Self::MidPoint => "MIDPOINT".to_string(), - Self::Bid => "BID".to_string(), - Self::Ask => "ASK".to_string(), + Self::Trades => write!(f, "TRADES"), + Self::MidPoint => write!(f, "MIDPOINT"), + Self::Bid => write!(f, "BID"), + Self::Ask => write!(f, "ASK"), } } } diff --git a/src/stubs.rs b/src/stubs.rs index 1a2c6625..a1d8cbf3 100644 --- a/src/stubs.rs +++ b/src/stubs.rs @@ -25,7 +25,10 @@ impl MessageBus for MessageBusStub { } fn write_message(&mut self, message: &RequestMessage) -> Result<(), Error> { - self.request_messages.write().expect("MessageBus.request_messages is poisoned").push(message.clone()); + self.request_messages + .write() + .expect("MessageBus.request_messages is poisoned") + .push(message.clone()); Ok(()) } @@ -71,7 +74,10 @@ impl MessageBus for MessageBusStub { } fn mock_request(stub: &mut MessageBusStub, _request_id: i32, message: &RequestMessage) -> Result { - stub.request_messages.write().expect("MessageBus.request_messages is poisoned").push(message.clone()); + stub.request_messages + .write() + .expect("MessageBus.request_messages is poisoned") + .push(message.clone()); let (sender, receiver) = channel::unbounded(); let (s1, _r1) = channel::unbounded(); @@ -84,7 +90,10 @@ fn mock_request(stub: &mut MessageBusStub, _request_id: i32, message: &RequestMe } fn mock_global_request(stub: &mut MessageBusStub, message: &RequestMessage) -> Result { - stub.request_messages.write().expect("MessageBus.request_messages is poisoned").push(message.clone()); + stub.request_messages + .write() + .expect("MessageBus.request_messages is poisoned") + .push(message.clone()); let (sender, receiver) = channel::unbounded();