-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #171 from bitbytelabio/develop
Repair for Release 0.0.1
- Loading branch information
Showing
23 changed files
with
653 additions
and
422 deletions.
There are no files selected for viewing
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,24 @@ | ||
name: Publish to crates.io | ||
|
||
on: | ||
push: | ||
tags: | ||
- "*" | ||
|
||
jobs: | ||
publish: | ||
name: Publish to crates.io | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: stable | ||
override: true | ||
- uses: actions-rs/cargo@v1 | ||
with: | ||
command: login | ||
args: ${{ secrets.CRATES_IO_TOKEN }} | ||
- uses: actions-rs/cargo@v1 | ||
with: | ||
command: publish |
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 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,116 @@ | ||
use crate::{ | ||
chart::{ | ||
models::{DataPoint, StudyResponseData, SymbolInfo}, | ||
ChartOptions, StudyOptions, | ||
}, | ||
quote::models::QuoteValue, | ||
socket::TradingViewDataEvent, | ||
Error, | ||
}; | ||
use futures_util::{future::BoxFuture, Future}; | ||
use serde_json::Value; | ||
use std::sync::Arc; | ||
use tracing::{error, info}; | ||
|
||
pub type AsyncCallback<'a, T> = Box<dyn (Fn(T) -> BoxFuture<'a, ()>) + Send + Sync + 'a>; | ||
|
||
#[derive(Clone)] | ||
pub struct Callbacks<'a> { | ||
pub(crate) on_chart_data: Arc<AsyncCallback<'a, (ChartOptions, Vec<DataPoint>)>>, | ||
pub(crate) on_quote_data: Arc<AsyncCallback<'a, QuoteValue>>, | ||
pub(crate) on_study_data: Arc<AsyncCallback<'a, (StudyOptions, StudyResponseData)>>, | ||
pub(crate) on_error: Arc<AsyncCallback<'a, Error>>, | ||
pub(crate) on_symbol_info: Arc<AsyncCallback<'a, SymbolInfo>>, | ||
pub(crate) on_other_event: Arc<AsyncCallback<'a, (TradingViewDataEvent, Vec<Value>)>>, | ||
} | ||
|
||
impl Default for Callbacks<'_> { | ||
fn default() -> Self { | ||
Self { | ||
on_chart_data: Arc::new(Box::new(|data| { | ||
Box::pin(async move { info!("default callback logging && handling: {:?}", data) }) | ||
})), | ||
on_quote_data: Arc::new(Box::new(|data| { | ||
Box::pin(async move { info!("default callback logging && handling: {:?}", data) }) | ||
})), | ||
on_study_data: Arc::new(Box::new(|data| { | ||
Box::pin(async move { info!("default callback logging && handling: {:?}", data) }) | ||
})), | ||
|
||
on_error: Arc::new(Box::new(|e| { | ||
Box::pin(async move { error!("default callback logging && handling: {e}") }) | ||
})), | ||
on_symbol_info: Arc::new(Box::new(|data| { | ||
Box::pin(async move { info!("default callback logging && handling: {:?}", data) }) | ||
})), | ||
on_other_event: Arc::new(Box::new(|data| { | ||
Box::pin(async move { info!("default callback logging && handling: {:?}", data) }) | ||
})), | ||
} | ||
} | ||
} | ||
|
||
impl<'a> Callbacks<'a> { | ||
pub fn on_chart_data<Fut>( | ||
&mut self, | ||
f: impl Fn((ChartOptions, Vec<DataPoint>)) -> Fut + Send + Sync + 'a, | ||
) -> &mut Self | ||
where | ||
Fut: Future<Output = ()> + Send + 'a, | ||
{ | ||
self.on_chart_data = Arc::new(Box::new(move |data| Box::pin(f(data)))); | ||
self | ||
} | ||
|
||
pub fn on_quote_data<Fut>( | ||
&mut self, | ||
f: impl Fn(QuoteValue) -> Fut + Send + Sync + 'a, | ||
) -> &mut Self | ||
where | ||
Fut: Future<Output = ()> + Send + 'a, | ||
{ | ||
self.on_quote_data = Arc::new(Box::new(move |data| Box::pin(f(data)))); | ||
self | ||
} | ||
|
||
pub fn on_study_data<Fut>( | ||
&mut self, | ||
f: impl Fn((StudyOptions, StudyResponseData)) -> Fut + Send + Sync + 'a, | ||
) -> &mut Self | ||
where | ||
Fut: Future<Output = ()> + Send + 'a, | ||
{ | ||
self.on_study_data = Arc::new(Box::new(move |data| Box::pin(f(data)))); | ||
self | ||
} | ||
|
||
pub fn on_error<Fut>(&mut self, f: impl Fn(Error) -> Fut + Send + Sync + 'a) -> &mut Self | ||
where | ||
Fut: Future<Output = ()> + Send + 'a, | ||
{ | ||
self.on_error = Arc::new(Box::new(move |data| Box::pin(f(data)))); | ||
self | ||
} | ||
|
||
pub fn on_symbol_info<Fut>( | ||
&mut self, | ||
f: impl Fn(SymbolInfo) -> Fut + Send + Sync + 'a, | ||
) -> &mut Self | ||
where | ||
Fut: Future<Output = ()> + Send + 'a, | ||
{ | ||
self.on_symbol_info = Arc::new(Box::new(move |data| Box::pin(f(data)))); | ||
self | ||
} | ||
|
||
pub fn on_other_event<Fut>( | ||
&mut self, | ||
f: impl Fn((TradingViewDataEvent, Vec<Value>)) -> Fut + Send + Sync + 'a, | ||
) -> &mut Self | ||
where | ||
Fut: Future<Output = ()> + Send + 'a, | ||
{ | ||
self.on_other_event = Arc::new(Box::new(move |data| Box::pin(f(data)))); | ||
self | ||
} | ||
} |
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.