Skip to content

Commit

Permalink
Refactor the kraken module to automatically re-connect on errors
Browse files Browse the repository at this point in the history
In order to be able to re-connect on certain errors, we model
connection errors separately from parsing errors. We also change
the API of the whole module to no longer forward all errors to
the subscribers but instead, only update the subscribers with
either a latest rate or a permanent failure in case we exhausted
all our options to re-connect the websocket.

To model all of this properly, we introduce to sub-modules so that
each submodule can have their own `Error` type.

Resolves #297.
  • Loading branch information
thomaseizinger committed Mar 9, 2021
1 parent c560b3b commit 9ad2160
Show file tree
Hide file tree
Showing 3 changed files with 257 additions and 176 deletions.
2 changes: 1 addition & 1 deletion swap/src/bin/asb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async fn main() -> Result<()> {
bitcoin_wallet.new_address().await?
);

let kraken_rate_updates = kraken::connect().await?;
let kraken_rate_updates = kraken::connect()?;

let (event_loop, _) = EventLoop::new(
config.network.listen,
Expand Down
6 changes: 2 additions & 4 deletions swap/src/bin/kraken_ticker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ use anyhow::{Context, Result};
#[tokio::main]
async fn main() -> Result<()> {
tracing::subscriber::set_global_default(
tracing_subscriber::fmt().with_env_filter("trace").finish(),
tracing_subscriber::fmt().with_env_filter("debug").finish(),
)?;

let mut ticker = swap::kraken::connect()
.await
.context("Failed to connect to kraken")?;
let mut ticker = swap::kraken::connect().context("Failed to connect to kraken")?;

loop {
match ticker.wait_for_update().await? {
Expand Down
Loading

0 comments on commit 9ad2160

Please sign in to comment.