Crates.io | longbridge |
lib.rs | longbridge |
version | 0.2.77 |
source | src |
created_at | 2022-05-23 12:19:19.902831 |
updated_at | 2023-10-30 11:36:04.187797 |
description | Longbridge OpenAPI SDK for Rust |
homepage | https://open.longbridgeapp.com/en/ |
repository | https://github.com/longbridgeapp/openapi-sdk |
max_upload_size | |
id | 591767 |
size | 307,656 |
longbridge
provides an easy-to-use interface for invokes Longbridge OpenAPI
.
Add dependencies to Cargo.toml
[dependencies]
longbridge = "0.1.0"
Setting environment variables(MacOS/Linux)
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)
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"
use std::sync::Arc;
use longbridge::{
decimal,
trade::{OrderSide, OrderType, SubmitOrderOptions, TimeInForceType},
Config, QuoteContext, TradeContext,
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Load configuration from environment variables
let config = Arc::new(Config::from_env()?);
// Create a context for quote APIs
let (ctx, _) = QuoteContext::try_new(config.clone()).await?;
// Get basic information of securities
let resp = ctx
.quote(["700.HK", "AAPL.US", "TSLA.US", "NFLX.US"])
.await?;
println!("{:?}", resp);
Ok(())
}
use std::sync::Arc;
use longbridge::{quote::SubFlags, Config, QuoteContext};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Load configuration from environment variables
let config = Arc::new(Config::from_env()?);
// Create a context for quote APIs
let (ctx, mut receiver) = QuoteContext::try_new(config).await?;
// Subscribe
ctx.subscribe(["700.HK"], SubFlags::QUOTE, true).await?;
// Receive push events
while let Some(event) = receiver.recv().await {
println!("{:?}", event);
}
Ok(())
}
use std::sync::Arc;
use longbridge::{
decimal,
trade::{OrderSide, OrderType, SubmitOrderOptions, TimeInForceType},
Config, TradeContext,
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Load configuration from environment variables
let config = Arc::new(Config::from_env()?);
// Create a context for trade APIs
let (ctx, _) = TradeContext::try_new(config).await?;
// Submit order
let opts = SubmitOrderOptions::new(
"700.HK",
OrderType::LO,
OrderSide::Buy,
500,
TimeInForceType::Day,
)
.submitted_price(decimal!(50i32))
.remark("Hello from Rust SDK".to_string());
let resp = ctx.submit_order(opts).await?;
println!("{:?}", resp);
Ok(())
}
To avoid compiling unused dependencies, Longbridge gates certain features, all of which are disabled by default:
Feature | Description |
---|---|
blocking | Provides the blocking client API. |
Licensed under either of