Skip to content

Commit

Permalink
chore: unset python's default config
Browse files Browse the repository at this point in the history
  • Loading branch information
flisky committed Nov 29, 2023
1 parent 78c297b commit 3d8886c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
8 changes: 4 additions & 4 deletions python/pysrc/longport/openapi.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ class Config:
app_key: str,
app_secret: str,
access_token: str,
http_url: str = "https://openapi.longportapp.com",
quote_ws_url: str = "wss://openapi-quote.longportapp.com/v2",
trade_ws_url: str = "wss://openapi-trade.longportapp.com/v2",
language: Type[Language] = Language.EN,
http_url: Optional[str] = None,
quote_ws_url: Optional[str] = None,
trade_ws_url: Optional[str] = None,
language: Optional[Type[Language]] = None,
) -> None: ...

@classmethod
Expand Down
37 changes: 22 additions & 15 deletions python/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,34 @@ impl Config {
app_key,
app_secret,
access_token,
http_url = "https://openapi.longportapp.com",
quote_ws_url = "wss://openapi-quote.longportapp.com/v2",
trade_ws_url = "wss://openapi-trade.longportapp.com/v2",
language = Language::EN,
http_url = None,
quote_ws_url = None,
trade_ws_url = None,
language = None,
))]
fn py_new(
app_key: String,
app_secret: String,
access_token: String,
http_url: &str,
quote_ws_url: &str,
trade_ws_url: &str,
language: Language,
http_url: Option<String>,
quote_ws_url: Option<String>,
trade_ws_url: Option<String>,
language: Option<Language>,
) -> Self {
Self(
longport::Config::new(app_key, app_secret, access_token)
.http_url(http_url)
.quote_ws_url(quote_ws_url)
.trade_ws_url(trade_ws_url)
.language(language.into()),
)
let mut config = longport::Config::new(app_key, app_secret, access_token);
if let Some(http_url) = http_url {
config = config.http_url(http_url);
}
if let Some(quote_ws_url) = quote_ws_url {
config = config.quote_ws_url(quote_ws_url);
}
if let Some(trade_ws_url) = trade_ws_url {
config = config.trade_ws_url(trade_ws_url);
}
if let Some(language) = language {
config = config.language(language.into());
}
Self(config)
}

#[classmethod]
Expand Down

0 comments on commit 3d8886c

Please sign in to comment.