Skip to main content

OpenApiSdkClient

Struct OpenApiSdkClient 

Source
pub struct OpenApiSdkClient { /* private fields */ }

Implementations§

Source§

impl OpenApiSdkClient

Source

pub async fn connect(dst: impl Into<String>) -> Result<Self, Error>

Examples found in repository?
examples/grpc_client.rs (line 11)
9async fn main() -> Result<(), Box<dyn std::error::Error>> {
10    let grpc_url = std::env::var("OPENAPI_GRPC_URL")?;
11    let mut client = OpenApiSdkClient::connect(grpc_url.clone()).await?;
12    println!("connected to {grpc_url}");
13
14    let token = client.login("alice", "secret").await?;
15
16    let quote = client.quote_volume("EURUSD", d(15, 2)).await?;
17    println!(
18        "quote => symbol={}, lot={}, volume={}",
19        quote.symbol, quote.lot_size, quote.volume
20    );
21
22    let execution = client
23        .place_market_order(token.clone(), "EURUSD", d(1, 2), OrderSide::Sell)
24        .await?;
25    println!(
26        "order => id={}, symbol={}, volume={}, margin={}",
27        execution.order_id, execution.symbol, execution.volume, execution.margin_used
28    );
29
30    let positions = client.fetch_open_positions(token.clone()).await?;
31    println!("open positions => {}", positions.len());
32
33    let balance = client.fetch_balance(token.clone()).await?;
34    println!(
35        "balance => total={}, used_margin={}, free_margin={}",
36        balance.balance, balance.used_margin, balance.free_margin
37    );
38
39    client.logout(token).await?;
40
41    Ok(())
42}
Source

pub async fn register_user( &mut self, username: impl Into<String>, password: impl Into<String>, account_id: impl Into<String>, initial_balance: Decimal, ) -> Result<(), OpenApiError>

Source

pub async fn login( &mut self, username: impl Into<String>, password: impl Into<String>, ) -> Result<String, OpenApiError>

Examples found in repository?
examples/grpc_client.rs (line 14)
9async fn main() -> Result<(), Box<dyn std::error::Error>> {
10    let grpc_url = std::env::var("OPENAPI_GRPC_URL")?;
11    let mut client = OpenApiSdkClient::connect(grpc_url.clone()).await?;
12    println!("connected to {grpc_url}");
13
14    let token = client.login("alice", "secret").await?;
15
16    let quote = client.quote_volume("EURUSD", d(15, 2)).await?;
17    println!(
18        "quote => symbol={}, lot={}, volume={}",
19        quote.symbol, quote.lot_size, quote.volume
20    );
21
22    let execution = client
23        .place_market_order(token.clone(), "EURUSD", d(1, 2), OrderSide::Sell)
24        .await?;
25    println!(
26        "order => id={}, symbol={}, volume={}, margin={}",
27        execution.order_id, execution.symbol, execution.volume, execution.margin_used
28    );
29
30    let positions = client.fetch_open_positions(token.clone()).await?;
31    println!("open positions => {}", positions.len());
32
33    let balance = client.fetch_balance(token.clone()).await?;
34    println!(
35        "balance => total={}, used_margin={}, free_margin={}",
36        balance.balance, balance.used_margin, balance.free_margin
37    );
38
39    client.logout(token).await?;
40
41    Ok(())
42}
Source

pub async fn logout( &mut self, session_token: impl Into<String>, ) -> Result<(), OpenApiError>

Examples found in repository?
examples/grpc_client.rs (line 39)
9async fn main() -> Result<(), Box<dyn std::error::Error>> {
10    let grpc_url = std::env::var("OPENAPI_GRPC_URL")?;
11    let mut client = OpenApiSdkClient::connect(grpc_url.clone()).await?;
12    println!("connected to {grpc_url}");
13
14    let token = client.login("alice", "secret").await?;
15
16    let quote = client.quote_volume("EURUSD", d(15, 2)).await?;
17    println!(
18        "quote => symbol={}, lot={}, volume={}",
19        quote.symbol, quote.lot_size, quote.volume
20    );
21
22    let execution = client
23        .place_market_order(token.clone(), "EURUSD", d(1, 2), OrderSide::Sell)
24        .await?;
25    println!(
26        "order => id={}, symbol={}, volume={}, margin={}",
27        execution.order_id, execution.symbol, execution.volume, execution.margin_used
28    );
29
30    let positions = client.fetch_open_positions(token.clone()).await?;
31    println!("open positions => {}", positions.len());
32
33    let balance = client.fetch_balance(token.clone()).await?;
34    println!(
35        "balance => total={}, used_margin={}, free_margin={}",
36        balance.balance, balance.used_margin, balance.free_margin
37    );
38
39    client.logout(token).await?;
40
41    Ok(())
42}
Source

pub async fn fetch_balance( &mut self, session_token: impl Into<String>, ) -> Result<AccountBalance, OpenApiError>

Examples found in repository?
examples/grpc_client.rs (line 33)
9async fn main() -> Result<(), Box<dyn std::error::Error>> {
10    let grpc_url = std::env::var("OPENAPI_GRPC_URL")?;
11    let mut client = OpenApiSdkClient::connect(grpc_url.clone()).await?;
12    println!("connected to {grpc_url}");
13
14    let token = client.login("alice", "secret").await?;
15
16    let quote = client.quote_volume("EURUSD", d(15, 2)).await?;
17    println!(
18        "quote => symbol={}, lot={}, volume={}",
19        quote.symbol, quote.lot_size, quote.volume
20    );
21
22    let execution = client
23        .place_market_order(token.clone(), "EURUSD", d(1, 2), OrderSide::Sell)
24        .await?;
25    println!(
26        "order => id={}, symbol={}, volume={}, margin={}",
27        execution.order_id, execution.symbol, execution.volume, execution.margin_used
28    );
29
30    let positions = client.fetch_open_positions(token.clone()).await?;
31    println!("open positions => {}", positions.len());
32
33    let balance = client.fetch_balance(token.clone()).await?;
34    println!(
35        "balance => total={}, used_margin={}, free_margin={}",
36        balance.balance, balance.used_margin, balance.free_margin
37    );
38
39    client.logout(token).await?;
40
41    Ok(())
42}
Source

pub async fn fetch_open_positions( &mut self, session_token: impl Into<String>, ) -> Result<Vec<OpenPosition>, OpenApiError>

Examples found in repository?
examples/grpc_client.rs (line 30)
9async fn main() -> Result<(), Box<dyn std::error::Error>> {
10    let grpc_url = std::env::var("OPENAPI_GRPC_URL")?;
11    let mut client = OpenApiSdkClient::connect(grpc_url.clone()).await?;
12    println!("connected to {grpc_url}");
13
14    let token = client.login("alice", "secret").await?;
15
16    let quote = client.quote_volume("EURUSD", d(15, 2)).await?;
17    println!(
18        "quote => symbol={}, lot={}, volume={}",
19        quote.symbol, quote.lot_size, quote.volume
20    );
21
22    let execution = client
23        .place_market_order(token.clone(), "EURUSD", d(1, 2), OrderSide::Sell)
24        .await?;
25    println!(
26        "order => id={}, symbol={}, volume={}, margin={}",
27        execution.order_id, execution.symbol, execution.volume, execution.margin_used
28    );
29
30    let positions = client.fetch_open_positions(token.clone()).await?;
31    println!("open positions => {}", positions.len());
32
33    let balance = client.fetch_balance(token.clone()).await?;
34    println!(
35        "balance => total={}, used_margin={}, free_margin={}",
36        balance.balance, balance.used_margin, balance.free_margin
37    );
38
39    client.logout(token).await?;
40
41    Ok(())
42}
Source

pub async fn quote_volume( &mut self, symbol: impl Into<String>, lot_size: Decimal, ) -> Result<VolumeQuote, OpenApiError>

Examples found in repository?
examples/grpc_client.rs (line 16)
9async fn main() -> Result<(), Box<dyn std::error::Error>> {
10    let grpc_url = std::env::var("OPENAPI_GRPC_URL")?;
11    let mut client = OpenApiSdkClient::connect(grpc_url.clone()).await?;
12    println!("connected to {grpc_url}");
13
14    let token = client.login("alice", "secret").await?;
15
16    let quote = client.quote_volume("EURUSD", d(15, 2)).await?;
17    println!(
18        "quote => symbol={}, lot={}, volume={}",
19        quote.symbol, quote.lot_size, quote.volume
20    );
21
22    let execution = client
23        .place_market_order(token.clone(), "EURUSD", d(1, 2), OrderSide::Sell)
24        .await?;
25    println!(
26        "order => id={}, symbol={}, volume={}, margin={}",
27        execution.order_id, execution.symbol, execution.volume, execution.margin_used
28    );
29
30    let positions = client.fetch_open_positions(token.clone()).await?;
31    println!("open positions => {}", positions.len());
32
33    let balance = client.fetch_balance(token.clone()).await?;
34    println!(
35        "balance => total={}, used_margin={}, free_margin={}",
36        balance.balance, balance.used_margin, balance.free_margin
37    );
38
39    client.logout(token).await?;
40
41    Ok(())
42}
Source

pub async fn place_market_order( &mut self, session_token: impl Into<String>, symbol: impl Into<String>, lot_size: Decimal, side: OrderSide, ) -> Result<OrderExecution, OpenApiError>

Examples found in repository?
examples/grpc_client.rs (line 23)
9async fn main() -> Result<(), Box<dyn std::error::Error>> {
10    let grpc_url = std::env::var("OPENAPI_GRPC_URL")?;
11    let mut client = OpenApiSdkClient::connect(grpc_url.clone()).await?;
12    println!("connected to {grpc_url}");
13
14    let token = client.login("alice", "secret").await?;
15
16    let quote = client.quote_volume("EURUSD", d(15, 2)).await?;
17    println!(
18        "quote => symbol={}, lot={}, volume={}",
19        quote.symbol, quote.lot_size, quote.volume
20    );
21
22    let execution = client
23        .place_market_order(token.clone(), "EURUSD", d(1, 2), OrderSide::Sell)
24        .await?;
25    println!(
26        "order => id={}, symbol={}, volume={}, margin={}",
27        execution.order_id, execution.symbol, execution.volume, execution.margin_used
28    );
29
30    let positions = client.fetch_open_positions(token.clone()).await?;
31    println!("open positions => {}", positions.len());
32
33    let balance = client.fetch_balance(token.clone()).await?;
34    println!(
35        "balance => total={}, used_margin={}, free_margin={}",
36        balance.balance, balance.used_margin, balance.free_margin
37    );
38
39    client.logout(token).await?;
40
41    Ok(())
42}
Source

pub async fn get_candles( &mut self, symbol: impl Into<String>, timeframe: Timeframe, from_time: Option<DateTime<Utc>>, to_time: Option<DateTime<Utc>>, limit: u32, ) -> Result<Vec<Candle>, OpenApiError>

Source

pub async fn stream_candles( &mut self, symbol: impl Into<String>, timeframe: Timeframe, from_time: Option<DateTime<Utc>>, to_time: Option<DateTime<Utc>>, limit: u32, ) -> Result<Streaming<StreamCandlesResponse>, OpenApiError>

Source

pub async fn get_server_time(&mut self) -> Result<DateTime<Utc>, OpenApiError>

Trait Implementations§

Source§

impl Clone for OpenApiSdkClient

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OpenApiSdkClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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