Skip to content

Commit

Permalink
ADD: Add reconnect logic to Rust client
Browse files Browse the repository at this point in the history
  • Loading branch information
threecgreen committed Feb 7, 2025
1 parent c137d42 commit 62ab0e2
Show file tree
Hide file tree
Showing 7 changed files with 223 additions and 42 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Changelog

## 0.20.0 - TBD

### Enhancements
- Added `LiveClient::reconnect()` and `LiveClient::resubscribe()` methods to make it easier
to resume a live session after losing the connection to the live gateway
- Added `subscriptions()` and `subscriptions_mut()` getters to `LiveClient` for getting all
active subscriptions
- Added `shutdown()` method to `live::Protocol` to clean up the active session
- Downgraded to tracing span level on `LiveClient::next_record()` to "debug" to reduce
performance impact
- Added `From<&[&str]>` and `From<[str; N]>` implementations for `Symbols`

### Breaking changes
- Changed `LiveClient::close()` to take `&mut self` rather than an owned value to `self` now
that clients can be reused through the `reconnect()` method
- Changed `LiveClient::subscribe()` to take a `Subscription` parameter rather than a
`&Subscription` because it will now store the `Subscription` struct internally

## 0.19.0 - 2025-01-21

### Enhancements
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
.await?;
client
.subscribe(
&Subscription::builder()
Subscription::builder()
.symbols("ES.FUT")
.schema(Schema::Trades)
.stype_in(SType::Parent)
Expand Down
2 changes: 1 addition & 1 deletion examples/live.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
.await?;
client
.subscribe(
&Subscription::builder()
Subscription::builder()
.symbols("ES.FUT")
.schema(Schema::Trades)
.stype_in(SType::Parent)
Expand Down
4 changes: 2 additions & 2 deletions examples/live_smoke_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async fn run(args: Args, mut client: LiveClient) -> anyhow::Result<()> {
builder.build()
};

client.subscribe(&subscription).await?;
client.subscribe(subscription).await?;

//For start != 0 we stop at SymbolMappingMsg so that the tests can be run outside trading hours
let expected_rtype: RType = if start
Expand Down Expand Up @@ -117,7 +117,7 @@ async fn run(args: Args, mut client: LiveClient) -> anyhow::Result<()> {
async fn run_with_snapshot(args: Args, mut client: LiveClient) -> anyhow::Result<()> {
client
.subscribe(
&Subscription::builder()
Subscription::builder()
.schema(args.schema)
.symbols(args.symbols)
.stype_in(args.stype)
Expand Down
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,18 @@ impl From<Vec<String>> for Symbols {
}
}

impl<const N: usize> From<[&str; N]> for Symbols {
fn from(value: [&str; N]) -> Self {
Symbols::Symbols(value.iter().map(ToString::to_string).collect())
}
}

impl From<&[&str]> for Symbols {
fn from(value: &[&str]) -> Self {
Symbols::Symbols(value.iter().map(ToString::to_string).collect())
}
}

impl From<Vec<&str>> for Symbols {
fn from(value: Vec<&str>) -> Self {
Symbols::Symbols(value.into_iter().map(ToOwned::to_owned).collect())
Expand Down
Loading

0 comments on commit 62ab0e2

Please sign in to comment.