Struct BackproofStrategy

Source
pub struct BackproofStrategy { /* private fields */ }
Expand description

Represents the strategy that you can run.

Implementations§

Source§

impl BackproofStrategy

Source

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}
Source

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}
Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more