pub struct OpenApiSdkClient { /* private fields */ }Implementations§
Source§impl OpenApiSdkClient
impl OpenApiSdkClient
Sourcepub async fn connect(dst: impl Into<String>) -> Result<Self, Error>
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}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>
Sourcepub async fn login(
&mut self,
username: impl Into<String>,
password: impl Into<String>,
) -> Result<String, OpenApiError>
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}Sourcepub async fn logout(
&mut self,
session_token: impl Into<String>,
) -> Result<(), OpenApiError>
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}Sourcepub async fn fetch_balance(
&mut self,
session_token: impl Into<String>,
) -> Result<AccountBalance, OpenApiError>
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}Sourcepub async fn fetch_open_positions(
&mut self,
session_token: impl Into<String>,
) -> Result<Vec<OpenPosition>, OpenApiError>
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}Sourcepub async fn quote_volume(
&mut self,
symbol: impl Into<String>,
lot_size: Decimal,
) -> Result<VolumeQuote, OpenApiError>
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}Sourcepub async fn place_market_order(
&mut self,
session_token: impl Into<String>,
symbol: impl Into<String>,
lot_size: Decimal,
side: OrderSide,
) -> Result<OrderExecution, OpenApiError>
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}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>
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>
pub async fn get_server_time(&mut self) -> Result<DateTime<Utc>, OpenApiError>
Trait Implementations§
Source§impl Clone for OpenApiSdkClient
impl Clone for OpenApiSdkClient
Auto Trait Implementations§
impl !Freeze for OpenApiSdkClient
impl !RefUnwindSafe for OpenApiSdkClient
impl !UnwindSafe for OpenApiSdkClient
impl Send for OpenApiSdkClient
impl Sync for OpenApiSdkClient
impl Unpin for OpenApiSdkClient
impl UnsafeUnpin for OpenApiSdkClient
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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