-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
55 changed files
with
1,349 additions
and
863 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
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
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
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
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
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 |
---|---|---|
@@ -1,20 +1,39 @@ | ||
use std::time::Duration; | ||
|
||
use tokio::time::sleep; | ||
use tracing_subscriber::fmt::init; | ||
|
||
use bothan_coinbase::service::builder::CoinbaseServiceBuilder; | ||
use bothan_core::service::Service; | ||
use bothan_coinbase::{CoinbaseWorkerBuilder, CoinbaseWorkerBuilderOpts}; | ||
use bothan_core::registry::Registry; | ||
use bothan_core::store::SharedStore; | ||
use bothan_core::worker::{AssetWorker, AssetWorkerBuilder}; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
init(); | ||
let path = std::env::current_dir().unwrap(); | ||
let registry = Registry::default().validate().unwrap(); | ||
let store = SharedStore::new(registry, path.as_path()).await.unwrap(); | ||
|
||
let worker_store = store.create_worker_store(CoinbaseWorkerBuilder::worker_name()); | ||
let opts = CoinbaseWorkerBuilderOpts::default(); | ||
|
||
let worker = CoinbaseWorkerBuilder::new(worker_store, opts) | ||
.build() | ||
.await | ||
.unwrap(); | ||
|
||
worker | ||
.set_query_ids(vec!["BTC-USD".to_string(), "ETH-USD".to_string()]) | ||
.await | ||
.unwrap(); | ||
|
||
sleep(Duration::from_secs(2)).await; | ||
|
||
let service = CoinbaseServiceBuilder::default().build().await; | ||
if let Ok(mut service) = service { | ||
loop { | ||
let data = service | ||
.get_price_data(&["BTC-USD", "ETH-USD", "USDT-USD"]) | ||
.await; | ||
println!("{:?}", data); | ||
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await; | ||
} | ||
loop { | ||
let btc_data = worker.get_asset("BTC-USD").await; | ||
let eth_data = worker.get_asset("ETH-USD").await; | ||
println!("{:?} {:?}", btc_data, eth_data); | ||
sleep(Duration::from_secs(5)).await; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
pub use error::{ConnectionError, MessageError, SendError}; | ||
pub use types::channels::ticker::Ticker; | ||
pub use websocket::{CoinbaseWebSocketConnection, CoinbaseWebSocketConnector}; | ||
|
||
pub mod error; | ||
pub mod types; | ||
pub mod websocket; |
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 |
---|---|---|
@@ -1,25 +1,32 @@ | ||
use tokio_tungstenite::tungstenite::{self, http::StatusCode}; | ||
use tokio_tungstenite::tungstenite; | ||
|
||
/// Represents the various errors that can occur. | ||
#[derive(Debug, thiserror::Error)] | ||
pub enum Error { | ||
/// Connection failure with a response code. | ||
#[error("failed to connect with response code {0}")] | ||
ConnectionFailure(StatusCode), | ||
pub enum ConnectionError { | ||
#[error("failed to connect to endpoint {0}")] | ||
ConnectionFailure(#[from] tungstenite::Error), | ||
|
||
/// Error parsing JSON. | ||
#[error("failed to parse")] | ||
Parse(#[from] serde_json::Error), | ||
#[error("received unsuccessful WebSocket response: {0}")] | ||
UnsuccessfulWebSocketResponse(tungstenite::http::StatusCode), | ||
} | ||
|
||
/// Error from the Tungstenite library. | ||
#[error("tungstenite error")] | ||
Tungstenite(#[from] tungstenite::Error), | ||
#[derive(Debug, thiserror::Error)] | ||
pub enum MessageError { | ||
#[error("failed to parse message")] | ||
Parse(#[from] serde_json::Error), | ||
|
||
/// Channel closed unexpectedly. | ||
#[error("channel closed")] | ||
ChannelClosed, | ||
|
||
/// Received an unsupported message. | ||
#[error("unsupported message")] | ||
UnsupportedMessage, | ||
} | ||
|
||
#[derive(Debug, thiserror::Error)] | ||
pub enum SendError { | ||
#[error(transparent)] | ||
Tungstenite(#[from] tungstenite::Error), | ||
|
||
/// Indicates a failure to parse a message. | ||
#[error("failed to parse")] | ||
Parse(#[from] serde_json::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
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
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.