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.21-cp312-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f376ecab6ced9039949c1cf820662fe5244c82145e82a13096d12267d286562 |
|
MD5 | 058eb68b86ef8c82a7861af03cb0bcfb |
|
BLAKE2b-256 | c4ff493a8d54701e9bcb8b3220f1aeb0a07ff53a296d8ff1fa8193ab8109fcbe |
Close
Hashes for longport-1.0.21-cp312-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 055f5f6b0b8862e60196378f20dba8f6b5e7adf28fca55bdcde46ca47112720f |
|
MD5 | c97801418cf5d1660b2431fd86ec523f |
|
BLAKE2b-256 | 8115482e0599c0ebb1b13de90b6d777a18b8655f715f6b84919904246d89ea54 |
Close
Hashes for longport-1.0.21-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f2ec3bcad8db41c4dbe8281c620c031b104570b546522a79a7767f67820e241 |
|
MD5 | 90ea9a43fd2aa3118f0cf3b0e860705b |
|
BLAKE2b-256 | 847f178712561ee900d4bda8f80d28a584d627eae7169f7ed37c3faf82a5a009 |
Close
Hashes for longport-1.0.21-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb0b0a0db79200b60cecbbb8eb002f3cab6061bfcf43e5cae80cd442117852f3 |
|
MD5 | b6c42d805c25c290148268d015a09566 |
|
BLAKE2b-256 | 3bdd085eece732d042f9eedb54e3b39927a6bdb78c2c408d2193f59fbb74dca8 |
Close
Hashes for longport-1.0.21-cp312-cp312-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e985dfe20d228be089074310c6812af7cda808dd941648fc1707db3eb8b806f |
|
MD5 | 109d4994bdf6fd08048bfd26a2afb80e |
|
BLAKE2b-256 | 7381819a010957249b22b0578fe419138ee5374d47098d5133a2dde287c7576a |
Close
Hashes for longport-1.0.21-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52e85cb2e0b4f6abf892b896e70395fcc549712d7007e5c5f5770f24143866c2 |
|
MD5 | 6f8728e7478827dc0f1cccfe5dc5acba |
|
BLAKE2b-256 | f89fb7bc12af09945c6626a9712e9a5411d70ba85fb92ff985ea6d0e27d64c64 |
Close
Hashes for longport-1.0.21-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 778e0c7a0a6c9fd326a1aa40ba0cd167ca88cdbf1e96d764766a35a2dbf3e0dc |
|
MD5 | ecf72a8ce8d43b8716f029d535cd8340 |
|
BLAKE2b-256 | efb5c17cd3b80918ced2415bc384cf6b1ba68a29b0bebfff17108a4995d5a002 |
Close
Hashes for longport-1.0.21-cp311-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f156fb50afdec8c369e8da924ca6cef34b665de79f82af550e8ea0693992940 |
|
MD5 | 3787ba624b31bb9a8c3fb75eb0ced257 |
|
BLAKE2b-256 | cad4f1d09e28b2df2d7a0a972abab0d8eceffa00dc1247d9bed3178da8f0ceb3 |
Close
Hashes for longport-1.0.21-cp311-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c1ffd9dc065a3ed6801eee8399509b3b5b9aff394e62165b4ddb54c1b9b4912 |
|
MD5 | 66588b71b284636fadf20070b202b221 |
|
BLAKE2b-256 | 5ad1c00a421c7f6f0a44bb5851617b3a578aa57b7edfdaef7ee858cc0a0a6d2a |
Close
Hashes for longport-1.0.21-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b4a1cc147cc447246db11cfdbd02deecef0b95d32e0c2647d05228b9f905763 |
|
MD5 | 07d453e53b244bc04d185e737513edd1 |
|
BLAKE2b-256 | 7a53b87f789b35c8e488d2eeb731585a443f5bbb7cd5a34e8abe60edf4f9c3b5 |
Close
Hashes for longport-1.0.21-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72479fde0fb32b85cd98b303da34ad3a14c8d680d4250f59d9c20c90f46ccc8a |
|
MD5 | e3251a724b6da4d45eb981688734d00b |
|
BLAKE2b-256 | 12a464d2214b377dea77c9756483b77122c9b3ecd96c1519addb22e9d44dee69 |
Close
Hashes for longport-1.0.21-cp311-cp311-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85310c33ae3c15e375c39988a1012943b4d4d6e2dfd8fa5261a47ad26995d87a |
|
MD5 | ce7931925a24772701b5d9d091ba7936 |
|
BLAKE2b-256 | 37d4355e71f150164463b14e7e10f63acfe94b2c3b3e43537dfd0379f869596c |
Close
Hashes for longport-1.0.21-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58b91f8fd6ab2bb2ef564d8cfd17c1bc13c40719bc028081bb47c14539d8f3de |
|
MD5 | 9ee5bacbb02b07c18022b66617350668 |
|
BLAKE2b-256 | 85bf47d7cf06e5f97219f18ac81000c6f47c4b00ff92b0bb5e23a11056f1e8ee |
Close
Hashes for longport-1.0.21-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a7f9bad7c31c0c8c334b46f113aeae08f9e2ba7f3cf35d16944dab8dbdc0570 |
|
MD5 | 22e81d5acb3b0e7ccdf4c82173509b24 |
|
BLAKE2b-256 | 6b18dc4d29aa5cb6dc33ab2a28a624587dde6f857351f92674bee270bcf30f35 |
Close
Hashes for longport-1.0.21-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31f317890d84b7ab22235790530a11873cc1db30374456f063689d8d11279a01 |
|
MD5 | 9ac568ab21dbfcc0e70183914370373d |
|
BLAKE2b-256 | 1fa6144a118dd806eed47a34c7d62de753765590f9b5a4f6d7453291415ed92f |
Close
Hashes for longport-1.0.21-cp310-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ed9a2a1ce5c2b9ff0a25454b3120ef9f330125186b61c8f4a7c1f99ef9177d0 |
|
MD5 | ad0f9a3b98823c8b1d5bef43b0fc145f |
|
BLAKE2b-256 | ad78a494259cbbd1ad477c628d504f1b9966d34288f4e2afef17a90b7ab6e261 |
Close
Hashes for longport-1.0.21-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4af2e668c50189a32bf633eb57ce3d663d961b681c7ce5d2dfd7e586d7fd20ea |
|
MD5 | 12130a9d5efe8478977f11c09280d022 |
|
BLAKE2b-256 | 87faa2a0f3951af9806458f5166d6ad35ce767a30c4c8efae7d6068a6ce26d29 |
Close
Hashes for longport-1.0.21-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c1350164829ecf227fb5d866be67d39a8782da3d5a975dadc25c52978203fec |
|
MD5 | 194a40160c294225f7a687af35c0c671 |
|
BLAKE2b-256 | 9106e7c167e930fb395ed3d698fd58ad30bf7477af91055678ab8e374c0130f8 |
Close
Hashes for longport-1.0.21-cp310-cp310-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60fa638c5adaa2b3e8c8e5cd849033b6a64a04932c4e05d6c6170623897c786c |
|
MD5 | ae8fa4c480f379f3672b5d755896fb7e |
|
BLAKE2b-256 | b58731759992c579191cb8c4bd3563d98bb692bdbc45f28f322b50e38638c5af |
Close
Hashes for longport-1.0.21-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39fb74357d5ad2c3aa5daf35f966f5675db40ce240d8fa687546abea1217352a |
|
MD5 | 4194ee680758e6e6c630febd6aaf6a24 |
|
BLAKE2b-256 | a9fa1ee811ba9c50c336d655a84d07604f11137c9e08c9a340ce0a88d41c71a2 |
Close
Hashes for longport-1.0.21-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ff30fea861abed9d8c529221bc089ff70a3a44e208798bb9d59e6061c96ed7b |
|
MD5 | 0904594a9e93a768f169c23ab62594c1 |
|
BLAKE2b-256 | 6827c87105f578700a2f2e1a4082e02985fcf5d28702de21872c52c91c3545e3 |
Close
Hashes for longport-1.0.21-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27832d85206d05af6676731198eeab6bf4fa3daa28515217940b2b6c12f37775 |
|
MD5 | c5b313afe7e1110f7dc5b09df45639da |
|
BLAKE2b-256 | 3b110099340d0e3fe764c35e717b5df979d7183b1f485b7be0dbbc3fafd92df1 |
Close
Hashes for longport-1.0.21-cp39-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4cebefac8f3c0755f6c7c92b58b6fe2b85dab139fd0898ab1d22bdaef89747bb |
|
MD5 | c537bb25c8fea239611bac1aab93114a |
|
BLAKE2b-256 | 8d8b3c50b9add64806d1361c3e6c36317d91a8c184094a72e5d06916d10b7bce |
Close
Hashes for longport-1.0.21-cp39-cp39-manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2003682a25f92e5b2c4681b36999ecbb422c3b36084e183167b0e64f828869e |
|
MD5 | 2ae7e98dc06c21236a26a85a209b6d70 |
|
BLAKE2b-256 | 28de1b5fa210c57092505422eb70e7ee5050f3796755050240db8e2ef8807cc9 |
Close
Hashes for longport-1.0.21-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b27055a382f58a8689b143d36d79a6c8a7b3fb8fc3d769620d730375e8904134 |
|
MD5 | 70b9dafbb2b9127083dabad21277ea32 |
|
BLAKE2b-256 | 93821f2191f4840c8ba57fa69cff39b54ed96f46d6dd4597c36493200d40cbb0 |
Close
Hashes for longport-1.0.21-cp39-cp39-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | adc9bc6ec6ec093c8a5473f985eb78eb12c8aeeba183371952854fad009a2718 |
|
MD5 | 52eea6b778a94e2c35f307f342c4f2af |
|
BLAKE2b-256 | bfbbf213cf25e648f24276394761af19ac01ebd7ccf9fc41b2b686a21c7e9721 |
Close
Hashes for longport-1.0.21-cp39-cp39-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbabf113aabfa484e320974bc3060976f4039a0947ae0a72407ac4ddd2d94240 |
|
MD5 | 394b7368f1214d07fbaa1e497dc8c5c2 |
|
BLAKE2b-256 | e5b4de6fe19617239e7d60f9baeabbde8c0c1ed02b1133100a0e2ba8b4a6ca4f |
Close
Hashes for longport-1.0.21-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa196f5df113b0a13ba527def2ceaf66e26e6eebfe91b60397c3410857f4ee4a |
|
MD5 | ae539c0eea9249bcbce93e5f3fec4318 |
|
BLAKE2b-256 | ef202b34de31aa5bac393db7f74a72448b2d28f4e0aaa397123c5045d1ee33f3 |
Close
Hashes for longport-1.0.21-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dce285d3bf121370dd9744c83d3ac513a65f20fa0af04cadc3d6b0e4b1c5f528 |
|
MD5 | 7cf33b4e0c9301936ffcde2a720f103b |
|
BLAKE2b-256 | 7803f594d05d560f44c2f6de8d17c6f12241f7c5de035ee9e7e2271affbe7cec |
Close
Hashes for longport-1.0.21-cp38-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ead27e64ceb93177d8494e942155e90097b1066c15cea41ebb3c9aefeb849ae |
|
MD5 | d8e54c309361a63686cdedebeca5e24f |
|
BLAKE2b-256 | 0bc25da48147db22ddaea6896398aa1f447b0e8a462666a3dd5f23fab6ee3219 |
Close
Hashes for longport-1.0.21-cp38-cp38-manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3c494958764d57cfc131ad74ac3afa3faa21e9daf1c0d2a9adf02138949edac |
|
MD5 | e8785ecd808f5a5d6fb3b006ac414ca3 |
|
BLAKE2b-256 | 488f7af6a57aaa4e0252cf8d1f5b573192d277615225393978d274571464f1b5 |
Close
Hashes for longport-1.0.21-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 362f20a009b456f8261dc2aca667aeddf8c722a29b7e0b1ccf5f2b3363f4b097 |
|
MD5 | 5452120e9ecda15973ba58fed3bbe3ee |
|
BLAKE2b-256 | af20d781a5577fe8ee148fe04fc05a29dd36bc33dcfbd3df4d00e9dbbe709c65 |
Close
Hashes for longport-1.0.21-cp38-cp38-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24d693a5627a98c397352b78b12827b3b9af0fe77a59292e5fb11be0c9e77337 |
|
MD5 | 00588e1a8c9d161b7e8dfb8f198329f3 |
|
BLAKE2b-256 | 4bff89f5407649c88b56375a614d66d4a5169c18d6bd8b230768a041debe95c8 |
Close
Hashes for longport-1.0.21-cp38-cp38-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf7ce5f217864e87594a16e0e0055b332ab458762ea667e2f4ce0c5e30552fd3 |
|
MD5 | e96e7d102f135cbb8ae9a3ba3b5302c2 |
|
BLAKE2b-256 | bf60a864d4ea3c6949389f33e52539042b2c8a2e81940dc1d21e3cf0ac71fb10 |
Close
Hashes for longport-1.0.21-cp38-cp38-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 710c328760d013f9d8ea118d8a6bc3c9f8a715788b447631cf63337e95957dd1 |
|
MD5 | af2d5af74424215112278eb06a9dfc6f |
|
BLAKE2b-256 | 7a6143f8cde0e8b66551f530f35095106c60bbd14d5eb2ac37e0e946e27935b1 |
Close
Hashes for longport-1.0.21-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ec6cb762a2447d06248703d480032c4eca78adae90d8986e21b6c8e955e19da |
|
MD5 | fbc52c9c8f08f2f6ae79dd24d152c5c6 |
|
BLAKE2b-256 | 0324f70a4aae2b2ab3bb7bee013c2c288e9365c755d43a5afcab0a27da300112 |
Close
Hashes for longport-1.0.21-cp37-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42a33fdaa5cb8bfbd7f1c7d92f1381d3a138c321fcdb7dc8e8991c43f620412a |
|
MD5 | 787cd60b886103c89ec1824130063f76 |
|
BLAKE2b-256 | 5ae004af9f07b5c6e1d1ec695ef5a3031da1a6e273196405f452136a55926506 |
Close
Hashes for longport-1.0.21-cp37-cp37m-manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3164f74a7d019a8323b8ba5ad6a5cf99eb5d8e865a40a96c1735cbde4b55c12 |
|
MD5 | fca2b4a9045b10b5fe3f7cc0ba2a226f |
|
BLAKE2b-256 | c7905ebd216021636d2f8adb57d687bded72d0a35ef0006ae14e4c9cda1a8c95 |
Close
Hashes for longport-1.0.21-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbd0bfca036153d310b1fc0a38760363b61cf51bc62a2a02b4865bd8ce530839 |
|
MD5 | 2f82b13e4ee7c2d21f6c878176872fbc |
|
BLAKE2b-256 | 433ca9fe83cd78085529d5b9674b22eaf19c7ca6400b977e0c8783bb477ff489 |
Close
Hashes for longport-1.0.21-cp37-cp37m-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7656da543f2ea0483176bcfb989deaeab5574ac398367d4bd65c206dfbe26563 |
|
MD5 | f708e5f4b3d56352037ce13908d62606 |
|
BLAKE2b-256 | 84a845a367ad12e4bcfcef3de6a114e86fcd171e49e231ec6eea9f77942605ef |
Close
Hashes for longport-1.0.21-cp37-cp37m-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c01251c41ed3a31173b01286ce8994b288c151299b632404364ac23c8a775245 |
|
MD5 | 2a429605f6aedcdf0becdcaaebbd7b1f |
|
BLAKE2b-256 | 6f2b65eaed15726fda600464108ee8cf891354e720cb9f27a6dc7500f5f10e64 |