pub struct Config { /* private fields */ }Expand description
Configuration options for Longbridge SDK
Implementations§
Source§impl Config
impl Config
Sourcepub fn from_apikey(
app_key: impl Into<String>,
app_secret: impl Into<String>,
access_token: impl Into<String>,
) -> Self
pub fn from_apikey( app_key: impl Into<String>, app_secret: impl Into<String>, access_token: impl Into<String>, ) -> Self
Create a new Config using API Key authentication.
All optional environment variables (LONGBRIDGE_HTTP_URL,
LONGBRIDGE_LANGUAGE, LONGBRIDGE_QUOTE_WS_URL,
LONGBRIDGE_TRADE_WS_URL, LONGBRIDGE_ENABLE_OVERNIGHT,
LONGBRIDGE_PUSH_CANDLESTICK_MODE,
LONGBRIDGE_PRINT_QUOTE_PACKAGES, LONGBRIDGE_LOG_PATH) are read from
the environment (or .env file) and applied automatically if set.
For OAuth 2.0, use Config::from_oauth together with
[longbridge::oauth::OAuthBuilder] instead.
Sourcepub fn from_oauth(oauth: OAuth) -> Self
pub fn from_oauth(oauth: OAuth) -> Self
Create a new Config for OAuth 2.0 authentication.
All optional environment variables (LONGBRIDGE_HTTP_URL,
LONGBRIDGE_LANGUAGE, LONGBRIDGE_QUOTE_WS_URL,
LONGBRIDGE_TRADE_WS_URL, LONGBRIDGE_ENABLE_OVERNIGHT,
LONGBRIDGE_PUSH_CANDLESTICK_MODE,
LONGBRIDGE_PRINT_QUOTE_PACKAGES, LONGBRIDGE_LOG_PATH) are read from
the environment (or .env file) and applied automatically if set.
§Arguments
oauth- An [OAuth] client obtained from [longbridge::oauth::OAuthBuilder].
§Example
use std::sync::Arc;
use longbridge::{Config, oauth::OAuthBuilder};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let oauth = OAuthBuilder::new("your-client-id")
.build(|url| println!("Visit: {url}"))
.await?;
let config = Arc::new(Config::from_oauth(oauth));
let (ctx, receiver) = longbridge::quote::QuoteContext::try_new(config).await?;
Ok(())
}Sourcepub fn from_apikey_env() -> Result<Self>
pub fn from_apikey_env() -> Result<Self>
Create a new Config from environment variables (API Key
authentication).
It first loads the environment variables from the .env file in the
current directory.
§Variables
LONGBRIDGE_APP_KEY- App keyLONGBRIDGE_APP_SECRET- App secretLONGBRIDGE_ACCESS_TOKEN- Access tokenLONGBRIDGE_LANGUAGE- Language identifier,zh-CN,zh-HKoren(Default:en)LONGBRIDGE_HTTP_URL- HTTP endpoint url (Default:https://openapi.longbridge.com)LONGBRIDGE_QUOTE_WS_URL- Quote websocket endpoint url (Default:wss://openapi-quote.longbridge.com/v2)LONGBRIDGE_TRADE_WS_URL- Trade websocket endpoint url (Default:wss://openapi-trade.longbridge.com/v2)LONGBRIDGE_ENABLE_OVERNIGHT- Enable overnight quote,trueorfalse(Default:false)LONGBRIDGE_PUSH_CANDLESTICK_MODE-realtimeorconfirmed(Default:realtime)LONGBRIDGE_PRINT_QUOTE_PACKAGES- Print quote packages when connected,trueorfalse(Default:true)LONGBRIDGE_LOG_PATH- Set the path of the log files (Default:no logs)
For OAuth 2.0 authentication use from_oauth
together with OAuthBuilder.
Sourcepub fn http_url(self, url: impl Into<String>) -> Self
pub fn http_url(self, url: impl Into<String>) -> Self
Specifies the url of the OpenAPI server.
Default: https://openapi.longbridge.com
NOTE: Usually you don’t need to change it.
Sourcepub fn quote_ws_url(self, url: impl Into<String>) -> Self
pub fn quote_ws_url(self, url: impl Into<String>) -> Self
Specifies the url of the OpenAPI quote websocket server.
Default: wss://openapi-quote.longbridge.com
NOTE: Usually you don’t need to change it.
Sourcepub fn trade_ws_url(self, url: impl Into<String>) -> Self
pub fn trade_ws_url(self, url: impl Into<String>) -> Self
Specifies the url of the OpenAPI trade websocket server.
Default: wss://openapi-trade.longbridge.com/v2
NOTE: Usually you don’t need to change it.
Sourcepub fn enable_overnight(self) -> Self
pub fn enable_overnight(self) -> Self
Enable overnight quote
Default: false
Sourcepub fn push_candlestick_mode(self, mode: PushCandlestickMode) -> Self
pub fn push_candlestick_mode(self, mode: PushCandlestickMode) -> Self
Specifies the push candlestick mode
Default: PushCandlestickMode::Realtime
Sourcepub fn dont_print_quote_packages(self) -> Self
pub fn dont_print_quote_packages(self) -> Self
Disable printing the opened quote packages when connected to the server.
Sourcepub fn create_metadata(&self) -> HashMap<String, String>
pub fn create_metadata(&self) -> HashMap<String, String>
Create metadata for auth/reconnect request
Sourcepub fn log_path(self, path: impl Into<PathBuf>) -> Self
pub fn log_path(self, path: impl Into<PathBuf>) -> Self
Specifies the path of the log file
Default: None
Sourcepub fn set_http_url(&mut self, url: impl Into<String>)
pub fn set_http_url(&mut self, url: impl Into<String>)
Set the HTTP endpoint URL in place.
Sourcepub fn set_quote_ws_url(&mut self, url: impl Into<String>)
pub fn set_quote_ws_url(&mut self, url: impl Into<String>)
Set the quote websocket endpoint URL in place.
Sourcepub fn set_trade_ws_url(&mut self, url: impl Into<String>)
pub fn set_trade_ws_url(&mut self, url: impl Into<String>)
Set the trade websocket endpoint URL in place.
Sourcepub fn set_language(&mut self, language: Language)
pub fn set_language(&mut self, language: Language)
Set the language in place.
Sourcepub fn set_enable_overnight(&mut self)
pub fn set_enable_overnight(&mut self)
Enable overnight quote in place.
Sourcepub fn set_push_candlestick_mode(&mut self, mode: PushCandlestickMode)
pub fn set_push_candlestick_mode(&mut self, mode: PushCandlestickMode)
Set the push candlestick mode in place.
Sourcepub fn set_dont_print_quote_packages(&mut self)
pub fn set_dont_print_quote_packages(&mut self)
Disable printing quote packages in place.
Sourcepub fn set_log_path(&mut self, path: impl Into<PathBuf>)
pub fn set_log_path(&mut self, path: impl Into<PathBuf>)
Set the log path in place.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Config
impl !RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl !UnwindSafe for Config
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more