Crates.io | longport |
lib.rs | longport |
version | |
source | src |
created_at | 2023-11-21 02:44:41.900495 |
updated_at | 2024-12-04 12:17:42.799222 |
description | LongPort OpenAPI SDK for Rust |
homepage | https://open.longportapp.com/en/ |
repository | https://github.com/longportapp/openapi-sdk |
max_upload_size | |
id | 1043667 |
Cargo.toml error: | TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
longport
provides an easy-to-use interface for invokes LongPort OpenAPI
.
Add dependencies to Cargo.toml
[dependencies]
longport = "1.0.0"
Setting environment variables(MacOS/Linux)
export LONGPORT_APP_KEY="App Key get from user center"
export LONGPORT_APP_SECRET="App Secret get from user center"
export LONGPORT_ACCESS_TOKEN="Access Token get from user center"
Setting environment variables(Windows)
setx LONGPORT_APP_KEY "App Key get from user center"
setx LONGPORT_APP_SECRET "App Secret get from user center"
setx LONGPORT_ACCESS_TOKEN "Access Token get from user center"
use std::sync::Arc;
use longport::{
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 longport::{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 longport::{
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,
decimal!(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, longport gates certain features, all of which are disabled by default:
Feature | Description |
---|---|
blocking | Provides the blocking client API. |
Licensed under either of