pub struct BackproofStrategy { /* private fields */ }
Expand description
Represents the strategy that you can run.
Implementations§
Source§impl BackproofStrategy
impl BackproofStrategy
Sourcepub fn builder() -> BackProofStrategyBuilder
pub fn builder() -> BackProofStrategyBuilder
Get a builder to configure the strategy.
Examples found in repository?
examples/client.rs (line 16)
11async fn main() {
12 tracing_subscriber::fmt::init();
13
14 let address = std::env::args().nth(1).unwrap();
15
16 let mut strategy = BackproofStrategy::builder()
17 .api_key("A323FSDEO3123FSD".to_string())
18 .api_strategy("flex".to_string(), |x: Candle| -> Order {
19 println!("Strategy running with input {x:?}...");
20 std::thread::sleep(Duration::from_secs(1));
21
22 Order {
23 symbol: "BTC".to_string(),
24 quantity: "100".to_string(),
25 side: 1,
26 }
27 })
28 .build(address)
29 .await
30 .expect("strategy build failed");
31
32 let session = strategy.register().await.expect("register");
33
34 info!("Starting strategy");
35
36 let closer = strategy
37 .run(Options::default(), session)
38 .await
39 .expect("strategy run failed");
40
41 std::thread::sleep(Duration::from_secs(5));
42 info!("closing backend.");
43 let _ = closer.send(()).expect("failed to close");
44}
Sourcepub async fn register(&mut self) -> Result<Session, BackproofSdkError>
pub async fn register(&mut self) -> Result<Session, BackproofSdkError>
register the strategy and setup the backend.
Examples found in repository?
examples/client.rs (line 32)
11async fn main() {
12 tracing_subscriber::fmt::init();
13
14 let address = std::env::args().nth(1).unwrap();
15
16 let mut strategy = BackproofStrategy::builder()
17 .api_key("A323FSDEO3123FSD".to_string())
18 .api_strategy("flex".to_string(), |x: Candle| -> Order {
19 println!("Strategy running with input {x:?}...");
20 std::thread::sleep(Duration::from_secs(1));
21
22 Order {
23 symbol: "BTC".to_string(),
24 quantity: "100".to_string(),
25 side: 1,
26 }
27 })
28 .build(address)
29 .await
30 .expect("strategy build failed");
31
32 let session = strategy.register().await.expect("register");
33
34 info!("Starting strategy");
35
36 let closer = strategy
37 .run(Options::default(), session)
38 .await
39 .expect("strategy run failed");
40
41 std::thread::sleep(Duration::from_secs(5));
42 info!("closing backend.");
43 let _ = closer.send(()).expect("failed to close");
44}
Sourcepub async fn run(
self,
_opts: Options,
session: Session,
) -> Result<Sender<()>, BackproofSdkError>
pub async fn run( self, _opts: Options, session: Session, ) -> Result<Sender<()>, BackproofSdkError>
Starts the strategy with given options.
Examples found in repository?
examples/client.rs (line 37)
11async fn main() {
12 tracing_subscriber::fmt::init();
13
14 let address = std::env::args().nth(1).unwrap();
15
16 let mut strategy = BackproofStrategy::builder()
17 .api_key("A323FSDEO3123FSD".to_string())
18 .api_strategy("flex".to_string(), |x: Candle| -> Order {
19 println!("Strategy running with input {x:?}...");
20 std::thread::sleep(Duration::from_secs(1));
21
22 Order {
23 symbol: "BTC".to_string(),
24 quantity: "100".to_string(),
25 side: 1,
26 }
27 })
28 .build(address)
29 .await
30 .expect("strategy build failed");
31
32 let session = strategy.register().await.expect("register");
33
34 info!("Starting strategy");
35
36 let closer = strategy
37 .run(Options::default(), session)
38 .await
39 .expect("strategy run failed");
40
41 std::thread::sleep(Duration::from_secs(5));
42 info!("closing backend.");
43 let _ = closer.send(()).expect("failed to close");
44}
Auto Trait Implementations§
impl Freeze for BackproofStrategy
impl !RefUnwindSafe for BackproofStrategy
impl Send for BackproofStrategy
impl !Sync for BackproofStrategy
impl Unpin for BackproofStrategy
impl !UnwindSafe for BackproofStrategy
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T
in a tonic::Request