A Python library for LongPort Open API
Project description
LongPort OpenAPI SDK for Python
longport
provides an easy-to-use interface for invokes LongPort OpenAPI
.
References
-
The configuration of the SDK.
-
The Quote API part of the SDK, e.g.: get basic information of securities, subscribe quotes...
-
The Trade API part of the SDK, e.g.: submit order, get order status...
Quickstart
Install LongPort OpenAPI SDK
pip install longport
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"
Quote API (Get basic information of securities)
from longpport.openapi import Config, QuoteContext
# Load configuration from environment variables
config = Config.from_env()
# Create a context for quote APIs
ctx = QuoteContext(config)
# Get basic information of securities
resp = ctx.quote(["700.HK", "AAPL.US", "TSLA.US", "NFLX.US"])
print(resp)
Quote API (Subscribe quotes)
from time import sleep
from longport.openapi import Config, QuoteContext, SubType, PushQuote
# Load configuration from environment variables
config = Config.from_env()
# A callback to receive quote data
def on_quote(symbol: str, event: PushQuote):
print(symbol, event)
# Create a context for quote APIs
ctx = QuoteContext(config)
ctx.set_on_quote(on_quote)
# Subscribe
resp = ctx.subscribe(["700.HK"], [SubType.Quote], is_first_push=True)
# Receive push duration to 30 seconds
sleep(30)
Trade API (Submit order)
from decimal import Decimal
from longport.openapi import TradeContext, Config, OrderType, OrderSide, TimeInForceType
# Load configuration from environment variables
config = Config.from_env()
# Create a context for trade APIs
ctx = TradeContext(config)
# Submit order
resp = ctx.submit_order("700.HK", OrderType.LO, OrderSide.Buy, Decimal(
"500"), TimeInForceType.Day, submitted_price=Decimal("50"), remark="Hello from Python SDK")
print(resp)
License
Licensed under either of
- Apache License, Version 2.0,(LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT) at your option.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distributions
Close
Hashes for longport-1.0.26-cp312-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e84812e93e98581ad93e6f0765e35df7a984ba813a675576bb99d4a6b84b7990 |
|
MD5 | de87182a6004e65e9eb2fe9111480134 |
|
BLAKE2b-256 | 2a59707077a6f7f2fae145c1f0a57e163f30d4156519ba45cfea506457a88376 |
Close
Hashes for longport-1.0.26-cp312-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e86e2adfbb18adca3f6dac9a535d3d06560ca8076c8df8f5f73a809496f1323 |
|
MD5 | bdc6434f81f588391b72c3a872fc4a45 |
|
BLAKE2b-256 | c202d31dd2c5f71bf315a225fddf820f5f5911b1764779423b4c81c154c9097a |
Close
Hashes for longport-1.0.26-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13bd5450debe9c2dada6a78429fdfbb788128f179d9a1eba6e90e4cc14bab09a |
|
MD5 | 68e32b3858be15aab7c8034c31801473 |
|
BLAKE2b-256 | adc9957b9ffe6b33c17544dd9bc51fb4e4714306caef1ca5d1215dcf70f1d24f |
Close
Hashes for longport-1.0.26-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 625bc6f694027fe2bd1a09c125444591db5809f1981f4ed697b5057ff7acfa4c |
|
MD5 | 51c48d630afbdcb57ed7df4e6c7d927c |
|
BLAKE2b-256 | 37906e08230efa9011b9c3be987c89de27a54f03593bf7bcd9af7e9522ebe68c |
Close
Hashes for longport-1.0.26-cp312-cp312-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ccfad1721e4228b7a10ce091e25e577c6347f9e0c25c669995a7282edcff6154 |
|
MD5 | ae1dc97169a572afba6871ee4353ddd1 |
|
BLAKE2b-256 | f1f2911d3e2316598435739c3d09555557327f0ec794e62b919a38670ee88e90 |
Close
Hashes for longport-1.0.26-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2ad95a4e3db75af91093ce79d50c50481d144f1199135a5cf5318ba128aff2c |
|
MD5 | 57ee109555f6828abc105f07a11a1b4f |
|
BLAKE2b-256 | b4fd09406a11a09b61882eb1b0d0f5432ff92b30fa77f79c7c45ec79fe8463c6 |
Close
Hashes for longport-1.0.26-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 456bd72cdc3debd1da2fd5154b1635b43a128cb2b128d94c9313df11410e69ef |
|
MD5 | 52599b981ade660e1646bb3b7ce145d9 |
|
BLAKE2b-256 | bf94fe78c44957f72cdc3481de81c607eac2b0dc85b2aa60fa529c66e249bae5 |
Close
Hashes for longport-1.0.26-cp311-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fae7cbfcb12b47f466b624458f3ecb793d7dd34a7c792dce405648a90a821c58 |
|
MD5 | a7d5638b2df61b632183afce376a2ef5 |
|
BLAKE2b-256 | bd8fbc35decf12019217ab14c49947db193572b7104b021657b4a506321801b4 |
Close
Hashes for longport-1.0.26-cp311-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12f9620524a497fff998a76abb945bbae373a8834135d0587967c4a91d3e12c8 |
|
MD5 | 1ce4b8e6e04b9134b583c0b99c73a2f3 |
|
BLAKE2b-256 | 4c17b198f71a4a3ae8a237f79fd87c82728a9bb800eb0d27e18a7fb5f9850ff2 |
Close
Hashes for longport-1.0.26-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5509002559a6a2f0102f5e59aeb75409b6c84b5547d867f82fa726332d665ea1 |
|
MD5 | f2fd1f592499ab75249dd2a9dd3d8982 |
|
BLAKE2b-256 | a0e73f0c35854b94c6d097d35a9d45a889c8867cfbe83042b096b62fa95d80ef |
Close
Hashes for longport-1.0.26-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd7ac8512a55f00d286e6d7cc21175b15aea671cc2737c359da2c9ef5b457ec8 |
|
MD5 | 061f978b9ccee54227581d45a9354025 |
|
BLAKE2b-256 | 6bc81cd86142f8ce2756b8bb343d7f3e090d49b102f5fb102a00a91a29010258 |
Close
Hashes for longport-1.0.26-cp311-cp311-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a447acc9d92e8b1b9b3dd48dbcde6e8a5c5889e0bed19e5d90ac72416b41a2b3 |
|
MD5 | 6eeacb7e75e093b34c4f4426f367b889 |
|
BLAKE2b-256 | 3f21a17fede7da8cb429b036ed2478e954c45d777b6ec80e5af8a9bfa48a7d09 |
Close
Hashes for longport-1.0.26-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d41adcc5301ca03dbf58900fc16deebe1a0340b525b97edc90e7f84798fc2cdf |
|
MD5 | cc65ee53b57bc6473e20fcfe5a8b294b |
|
BLAKE2b-256 | d36ef1df5dbb2f7d37b25260f603b7ff488fa11b715c417af58aae8f34347792 |
Close
Hashes for longport-1.0.26-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 317e376f275655a63c026bde60fdf949f14d2e595b3a08bea2b450d945d6754a |
|
MD5 | a3c080b6ee6a629da4c69f9dd9d738e6 |
|
BLAKE2b-256 | 1e6ff773f0ce8aa11baef2b9d460293ce4e1f9dc8548cd545691cd7fc2c4eb1d |
Close
Hashes for longport-1.0.26-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c296bb9eb2ee4239fd7675bbf0f2c301b05f0698650cdea29f6b27a4c91e1573 |
|
MD5 | 05b4aa4e518a83a31b49df08e0d23e86 |
|
BLAKE2b-256 | 09003ae78a8ff80b6cd525fb0c5bd5af125d9c9f5bf0837a371e378b4670cb48 |
Close
Hashes for longport-1.0.26-cp310-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec4425b52682cc1007ace6d1a2288098d48fa74c8d1f5d564233b82ddbf2976d |
|
MD5 | 63c79f76030edfdb567b2725bc219ebe |
|
BLAKE2b-256 | f022c34d6a453a31cb43ae53d66ea0b1dd3d2152bb74a25996618bb5f411fa2e |
Close
Hashes for longport-1.0.26-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4c6a35deadb59097e7f07adc2f71843417354fe6dd876a7f8f3ac1e3b18f1a0 |
|
MD5 | 735616992287f38c2dc27707f6661c04 |
|
BLAKE2b-256 | ea4eaafd2637f55121a3cc96e73b309cf634b349ea50a9fc821bb4d121722d47 |
Close
Hashes for longport-1.0.26-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6697e4c9a67d04901292f11a9717d42d7518167d498bf98af613d5b007026187 |
|
MD5 | eef168380de9da0a8116825d60785a51 |
|
BLAKE2b-256 | c1b883bd8a63d793ce0031981d418ed0fe0be9d467753d3bf6468a9c55791d76 |
Close
Hashes for longport-1.0.26-cp310-cp310-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 436eacc98af46bf5054c6f416f71a69e17b4e791a2ec7a7f64433b01042e5f4e |
|
MD5 | dffc20e8b315620a5a7a5045a41b6b44 |
|
BLAKE2b-256 | 762749d93fe894bb19574359db7b112323f9bfe41a0ca1495d7cd63409f54c70 |
Close
Hashes for longport-1.0.26-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 695f0da6c09ef49d69813bcadaf6886c1db49596e0080d2ddee7f5792d33c338 |
|
MD5 | 5d1582cd3c0b949a378fd7b271d37a20 |
|
BLAKE2b-256 | c2d57f2435ffcad3ddabf2b964ba6436ac77255497c77fe3cdf2236021081d82 |
Close
Hashes for longport-1.0.26-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f77f281f3c6aba708981022478750d85e0d3414b59df3571fa7aa0209faba5c6 |
|
MD5 | b3c2fd8e72d4696c93c9225a2ef9bc77 |
|
BLAKE2b-256 | 409a426c0d01c4b0137ecb69a8bf59d185c96a2ac45942b5ee0ae5be224bbc36 |
Close
Hashes for longport-1.0.26-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1e93db551d3d6b475bcae5b167ffae90b742162874844cb72b8aa9464e2912b |
|
MD5 | 9f6e1d3c78e67bc35eabc35ccf92c780 |
|
BLAKE2b-256 | 75ffe4f1ed7adef6c12627d6a912387a1974e0798177be3c90e509a1a1598ae5 |
Close
Hashes for longport-1.0.26-cp39-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f0a95e86748b5081249dce3c79e5f7669e2726fc4c6eeaa8891d75217341c5f |
|
MD5 | 878c7e00d018ab344c28dc99ef403b69 |
|
BLAKE2b-256 | c85fd14903ff609d9c18bb77b4a8e1faa6825e934aa8767a12d66eb7ede24219 |
Close
Hashes for longport-1.0.26-cp39-cp39-manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8a39814c043e77d48bf9fc3299ccb4f53149a6f15b1e54123650d0fc25a1a06 |
|
MD5 | 501b3bfbb6dce2f6cdb7f003411473a9 |
|
BLAKE2b-256 | d069b07d1f61f1b4b0a3d973038ff508f64d8662ec509ffd00db536be7d694e8 |
Close
Hashes for longport-1.0.26-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0232373e1ad1b458abe113169893d7d9fd6f1c8b238ec7752d3a2fea117dd5c |
|
MD5 | 0375b5f27564e6a1647d269a0737e88e |
|
BLAKE2b-256 | cb3023a78c199ae468d99c51eaf422076975ba4286792ad5dd1e90a0faf37a82 |
Close
Hashes for longport-1.0.26-cp39-cp39-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99beb9bb58a6b79e0f698e92870ec8dd32b21882ad602508410c9127d4a76d49 |
|
MD5 | ced6388e5d3836a9a2e3eb2d734e7011 |
|
BLAKE2b-256 | 3ede6b6cab1d8488edf86b82d73155f8fb11418e07f2d19a71e0d149f9598a6c |
Close
Hashes for longport-1.0.26-cp39-cp39-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1162992192bffde98423d568811f26f5a04b3ee6012218d4a9059a9f47467f67 |
|
MD5 | f890795eadd72eb11c757aa67d621d4c |
|
BLAKE2b-256 | 8632a7dd79a23f2935a8567094b94805551247c581d0937c50acb3ffa39f9b05 |
Close
Hashes for longport-1.0.26-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 597755fd220cc9e7b25ffb91ad265f31c1d633b09586a1e2f208ab7304c6f5fd |
|
MD5 | 51cee14c01659309e7aeb280b0541d27 |
|
BLAKE2b-256 | 4c3223f8f903a39ad4463ddfa4b3949a81d5a7361972a18b4c64c251daedbac7 |
Close
Hashes for longport-1.0.26-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c29eb7c79cd6927cf728cdaaf10cab2a24282553b58b15ddecf3eaf1dbcf02c1 |
|
MD5 | bf24c015b367fee0bb708b7733ababf5 |
|
BLAKE2b-256 | 29ca302dd4e7ae4e24c121e3cf26a979991835fe3c010db379383be8ae2cf5bb |
Close
Hashes for longport-1.0.26-cp38-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9c2c7137e299a38f2faf9eb503f6a5ad0484e98d4dfebb841ff752ea1e3fb0c |
|
MD5 | 493a1acd342dbded76acd6095205f52e |
|
BLAKE2b-256 | bff0764c125021b9055465cc77fe5176a2dc209419e5a1ee77a2e77e0b8afc65 |
Close
Hashes for longport-1.0.26-cp38-cp38-manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b307cede15a7acff91e4c3cd356e9c718e3dc797d68207162bb832b42cdda2e |
|
MD5 | 6bb570b53d2659548c597a7995d00329 |
|
BLAKE2b-256 | e074209b44b0b43294753b54b4d0b0693b9c876baf22e958c1f791a757264682 |
Close
Hashes for longport-1.0.26-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9e5ea6fb8b82e327f81876e5a67c6bf6fc5716b46f1d5d1b656c81199720e6b |
|
MD5 | 464920473951a51a643d9cd48fa15817 |
|
BLAKE2b-256 | 9bc8da95e4f73bbb54483844ef5d0050435e45bc807f112e957265e26f902225 |
Close
Hashes for longport-1.0.26-cp38-cp38-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a51b654fb44f026137b34bbb3b60b3752e268e9c4dbb7045a0ecc13f85803c15 |
|
MD5 | d753d418326994085934ffa372a77a66 |
|
BLAKE2b-256 | 2bec5cca64c5cf32d24039873109ea43d9d1f6d366f8d437a0d5723d3aef50de |
Close
Hashes for longport-1.0.26-cp38-cp38-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ffb73aeb1e4807efec2aa4c1b4b463080690509bc23a956d76f30af11e0503bd |
|
MD5 | 22fbae5e5cb8a7023acda16f41fce49b |
|
BLAKE2b-256 | 2d847615953ed2bf66947747edbdcc76cbfd89f6a5eb31b193484a07e6d5780a |
Close
Hashes for longport-1.0.26-cp38-cp38-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 310ea1e6315bad84a2ed38240bd0a5ecd8f246eb93b62d19f66c83380c66c048 |
|
MD5 | 2cf5aa80fc6a8cc7879ab1bef213c638 |
|
BLAKE2b-256 | 343009dae0f66a5f8f4e1ef6ed6e3f5ad8a84734d2610a30baaa4ed4f240049e |
Close
Hashes for longport-1.0.26-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c51c8f1dec377497ee66e5a27d3868e9eb9ab9c10dcc2bb59d887c98e4a95a1f |
|
MD5 | ea85672576e004e5d8ddd20d84f9dbcd |
|
BLAKE2b-256 | 881249c7727ab15877a68c29cd8f4ec09bfad72836f47b39887fd87b18029151 |
Close
Hashes for longport-1.0.26-cp37-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0cb799b365c6d78023ff28c06913b2216e8e5a400c8ab061de54104bd715aa13 |
|
MD5 | fe8e747962a0aa8c26b8ef18531fa307 |
|
BLAKE2b-256 | cf89de30d9734b263b1dc498721f45758168bebee62dadf007d0bcf29abb82c2 |
Close
Hashes for longport-1.0.26-cp37-cp37m-manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71d558f6247291fe309b41478a3fef100f097f5d9232dd97ad65c760c7bbe1c4 |
|
MD5 | 416ad4591c58fde7cded76ba58140c66 |
|
BLAKE2b-256 | f4b391d6161244dd541e3c4ceaf2332c668ac406383fbd32e548bcd9483c3585 |
Close
Hashes for longport-1.0.26-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 491764191768ef307d89e066dfd11406192df01c24bab2974228c6cea42a7c08 |
|
MD5 | df931a66cde520a9ebda277f15296ac9 |
|
BLAKE2b-256 | 5896b3959ee36f8e613b1bede1c9cc9f97c426d46d27ccfd68b06b359a5875ff |
Close
Hashes for longport-1.0.26-cp37-cp37m-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fac6518249dfc31ce6e15e38613c87eff08ce1aaebb526d8c5f34c877db8b0c5 |
|
MD5 | cece5e5a005f61b227606dca66754ebb |
|
BLAKE2b-256 | 9306d7754b3141d99bff559198b9a1a396147df8fa2b3f1d5790e898e59120b9 |
Close
Hashes for longport-1.0.26-cp37-cp37m-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00884792a30a2a7dc88e6c42c6b87e5b7f83c2bab0b399b4725f790351685cf9 |
|
MD5 | 97890cc58c0dbd77794366b7149c8041 |
|
BLAKE2b-256 | 59541652eb0e08fc7696ffe4e8aa75c3e41ae5909aee9d8c2fd0266722b0a48a |