longbridge
provides an easy-to-use interface for invokes Longbridge OpenAPI
.
Add dependencies to Cargo.toml
toml
[dependencies]
longbridge = "0.1.0"
Setting environment variables(MacOS/Linux)
bash
export LONGBRIDGE_APP_KEY="App Key get from user center"
export LONGBRIDGE_APP_SECRET="App Secret get from user center"
export LONGBRIDGE_ACCESS_TOKEN="Access Token get from user center"
Setting environment variables(Windows)
powershell
setx LONGBRIDGE_APP_KEY "App Key get from user center"
setx LONGBRIDGE_APP_SECRET "App Secret get from user center"
setx LONGBRIDGE_ACCESS_TOKEN "Access Token get from user center"
```rust,no_run use std::{error::Error, sync::Arc};
use longbridge::{ decimal, trade::{OrderSide, OrderType, SubmitOrderOptions, TimeInForceType}, Config, QuoteContext, TradeContext, };
async fn main() -> Result<(), Box
// Create a context for quote APIs
let (quote_ctx, _) = QuoteContext::try_new(config.clone()).await?;
// Create a context for trade APIs
let (trade_ctx, _) = TradeContext::try_new(config).await?;
// Get basic information of securities
let resp = quote_ctx
.quote(vec!["700.HK", "AAPL.US", "TSLA.US", "NFLX.US"])
.await?;
println!("{:?}", resp);
// Submit order
let opts = SubmitOrderOptions::new(
"700.HK",
OrderType::Limit,
OrderSide::Buy,
decimal!(50i32),
TimeInForceType::Day,
)
.submitted_price(decimal!(50i32))
.remark("Hello from Python SDK".to_string());
let resp = trade_ctx.submit_order(opts).await?;
print!("order id: {}", resp.order_id);
Ok(())
} ```
To avoid compiling unused dependencies, Poem gates certain features, all of which are disabled by default:
| Feature | Description | |----------|--------------------------------------------------------------------------------------------------| | blocking | Provides the blocking client API. |