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.32-cp312-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 452bae6da6884238e771dedb1dea0725bb87045766836290bf582b6589fbd0d7 |
|
MD5 | e00133cbe10b2e132bb89beda29f4f2a |
|
BLAKE2b-256 | a519bf1adba3cdb8a5f9fc19d70387b7e405e0b16a2e868af0e5518997a86e0f |
Close
Hashes for longport-1.0.32-cp312-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6b7dd8f1b6308e43c119d970071ef0ef94e2f824138a66110447a9eeda71953 |
|
MD5 | 71999f97046e2ea2230b83cbcbf55922 |
|
BLAKE2b-256 | 41028435b60fc4898804eb746bf773e0a7c88e995ac6505394459aaabb419302 |
Close
Hashes for longport-1.0.32-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26fe229eacd28bc349b804d5702a48dbe681fb992da66b63c5e9a9a07bd1e56b |
|
MD5 | d985525aa3299cedc41b14a1e77a6aae |
|
BLAKE2b-256 | bab03de5011f723e15b2707c874fc1e804447fa549e60da030329d9af74c5051 |
Close
Hashes for longport-1.0.32-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 893ae868e82160e3dbb7e91768f61d92d5ab54de4b3f1a0964972689ac676997 |
|
MD5 | 3cecfcd719a8a4ed29c51419432018c6 |
|
BLAKE2b-256 | cbff33cbf2206d76cf6aa339bacf64cc8f57637cd70bd1820bfe4e1187a51380 |
Close
Hashes for longport-1.0.32-cp312-cp312-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87dcec468eb22fc5128fbdf84a58388583eef939949cb53adbf4a58c41f4ccb8 |
|
MD5 | 806510407b8d8997c4cc3fb7ca2d6363 |
|
BLAKE2b-256 | 91e477e89c69935e1942379c11fd5e689de9d50ba667fdd4c0c8e2fc26c845f5 |
Close
Hashes for longport-1.0.32-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9641f3634824c9bc8ff918d76d2d7b5ec41997d1bd071787adaf3239bff9f910 |
|
MD5 | 66eea6ba7d434e053a259d05737be267 |
|
BLAKE2b-256 | 16fed948ee3a36a51dfd26487bc740b6e08a321177ba2c99938c97b45cafd745 |
Close
Hashes for longport-1.0.32-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20d8b865396d007568f4023ea791f270d475ed9c74d4f52b8585c1fe26717bff |
|
MD5 | be349b5459def166d36705a31761fde6 |
|
BLAKE2b-256 | bdba52a82dff0520b4f503fb3315060b4e71cc17dc34d5f10d80c76684b68e63 |
Close
Hashes for longport-1.0.32-cp311-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6b15ad052a61e3251551016a7d438199e720ededb507e332612fb0ead030f1f |
|
MD5 | 55c7e06d344b737d25e12b0d67424f9f |
|
BLAKE2b-256 | 2cffbc4170fa0b8c43c777ba3a9abba66482731fc27af6a420cf935e366d3cb8 |
Close
Hashes for longport-1.0.32-cp311-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc2402d129628cba756c451b28d72c4b1f268b56f7b9d532eb4d63b264f59a4d |
|
MD5 | 418c7c9a801a3e2e344a50dc3ef14a5a |
|
BLAKE2b-256 | dea9297dc7654229cf336113b7e92105a69a5ee739d257cffb0dc290fe732665 |
Close
Hashes for longport-1.0.32-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 317526bd45fbe22841e16936cd7e39ee30e000e92e43057d87a3ac8a89f090e0 |
|
MD5 | ae8fcc52dc3909cbd6360e431f2469d5 |
|
BLAKE2b-256 | 245958a84728f0b6b1b4e7a950852491fd579521447202e6a5b03d20b5d5cb18 |
Close
Hashes for longport-1.0.32-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5db51b338f1b974bf6d2ef11823cf7a99fe884fd0d6a3658af00b86e0146c71 |
|
MD5 | dafdeac453b17e3e149785443c4d0ccc |
|
BLAKE2b-256 | d531f26b7ec19023303f1741e2830e440c4bd5770afc05379936ab4445dc6ea0 |
Close
Hashes for longport-1.0.32-cp311-cp311-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b26219a1d2e5d1c57f88d777dd1fcf84bcf20c68e3a4eef24e2557b592b7126 |
|
MD5 | efb2c33ff1b57cf568734d922d44a81d |
|
BLAKE2b-256 | 06500cae3bc2cc685233d0f737f7339a9f3782e57678793583e6315bb61a8aa3 |
Close
Hashes for longport-1.0.32-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27271b0ead3b311f982c3606c012bdbe3ff79a75e9378d4c3de90266d05fb7f9 |
|
MD5 | 271793920501c66f38e21a5e61cfdbbb |
|
BLAKE2b-256 | f79ad50a578920e58966de96f17d43fef4de6be2615c9d7c28fbfec9305e9b86 |
Close
Hashes for longport-1.0.32-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6cc68f3685cab12ad206b99d5f2e41b0a89e33e1bd3927f76cfb42d2fc5710a5 |
|
MD5 | 91f12fb9b730e00a16a3eda15ea33717 |
|
BLAKE2b-256 | 94080e4e311c56900ef2769677fa87b38b112d0490c8bd8d7113673ee88f435b |
Close
Hashes for longport-1.0.32-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02974cb3b11d639024f443e2820134170dcfa0fb71ca68977c46e24e5197fb61 |
|
MD5 | c3f819d1ed5821b4dfc23c7ee9cda5e5 |
|
BLAKE2b-256 | 3182d0a0159016474a81d7b6adb15bca09121f334b73c66d2ae449aed04755aa |
Close
Hashes for longport-1.0.32-cp310-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d8e7f4af0085eb4e7c9bb5d61b16bbf0a8696fd365a2b6efd74554d69ae27bf |
|
MD5 | 3daa99d5b13d96e6586f954693a02007 |
|
BLAKE2b-256 | f54a910c20be1dabc483640a43d46d02ca0ef2eea651b0f0b15bb857cdf18c46 |
Close
Hashes for longport-1.0.32-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a47a8f600a908f2a2227554ad792166d4204e825da77aa033b9125c7bc098989 |
|
MD5 | b09c7ce4aa521e121f019459db7c1f4f |
|
BLAKE2b-256 | d183bed007b9dd1992bc05cc812769ebcc6240a92998d38e45798f31c53fc29d |
Close
Hashes for longport-1.0.32-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d9733c67771c7d77fe90c2cce1a27a7ebd3fe7e77c29f82c6ba4582d4565984 |
|
MD5 | 9e46c5e3d58ca59e199ed36b2b081552 |
|
BLAKE2b-256 | 1b56025e41deae305dfb9d227f45b9685f79aabe0069de4621e9779b3a999259 |
Close
Hashes for longport-1.0.32-cp310-cp310-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50d51ddcd36e1fd6a557c73777efbb4a78a3f1133b2692007a64102c7b4a3227 |
|
MD5 | 60cce05bf40fe9de396c2d9634f93f68 |
|
BLAKE2b-256 | 841580996fc33215b4d3ad69465c98d7166da3a4d9776582c2e1b3a3785b8b5b |
Close
Hashes for longport-1.0.32-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03bedfb635e5bb92b1e21ca0d23697ffb585c357cfe6ce7bf7039330ed1e2284 |
|
MD5 | ba33e64c41ef4f9e9b5b4c17a165fa70 |
|
BLAKE2b-256 | 17dfca9c08a130831f1339250bf01e6ac19eb492381b5066f2106afcb7aace81 |
Close
Hashes for longport-1.0.32-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a04623fb3ef5782008347c4ecf7a8918aaeaf99c5e26d6c5020bf152e358164f |
|
MD5 | bcab97d9e94f45a8640d933f334191b0 |
|
BLAKE2b-256 | bb217b8e506ec295a8f941163490e1eead63259e49cac6ad83de7f77fa917254 |
Close
Hashes for longport-1.0.32-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc0d50410a3063fdd3bd2f30473bb3fb798082c2c10c4970063eedb8353dc258 |
|
MD5 | 3e4e1fcf04aa324daf6aa7d03dd73627 |
|
BLAKE2b-256 | 246e6cc561dbe4a052d9631a782ec669924d5ccfb5d4aa06ced8a874a7d71c2f |
Close
Hashes for longport-1.0.32-cp39-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fbcee790ef6819d3d458237ac4bfe62fb361fb4f869bae3f796e33862d0c1b5c |
|
MD5 | 4aa05871d0f42696bea0ada71339611e |
|
BLAKE2b-256 | b944db356d0c8e01ca68b5a2d45422795f00e000462cd65b4abb091b83f3e106 |
Close
Hashes for longport-1.0.32-cp39-cp39-manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e77b10b46aa16543526b73e6a58fa1f3a0561c48ebfdf88bb88aa9fe3be70b0 |
|
MD5 | 4f52e3b51c964b42ba3c8eb45edd3333 |
|
BLAKE2b-256 | ba6541d664bb5f79a6bb529568719c73fe2af6f2a7ef89bdb6f550507d4642b7 |
Close
Hashes for longport-1.0.32-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e0db83db015e3308d8f99f5ad4e01461729f074cd10d77c88b8dd804075ddd1 |
|
MD5 | 2ef73a2e88fcdd1192fd86a62572029a |
|
BLAKE2b-256 | ac9fa1023ff7de4ca8ad42a873ace9b976d7f87c143dea48fc9e89419eb2bcbd |
Close
Hashes for longport-1.0.32-cp39-cp39-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fcdf11f9245f0e21ddd85cc54bf12e9f69f57ded71ab3085bcadc9c5987b9d3b |
|
MD5 | c072d0524c54c1a1bb93d6d8643059ac |
|
BLAKE2b-256 | cc901408915dba19d0c6816911edd68ae96d4026c14f15b7cd93b7b18284cd55 |
Close
Hashes for longport-1.0.32-cp39-cp39-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e4023796247d4c9134d9227eac80a985675dac366de81eb6e4eb99f6b50e0a5 |
|
MD5 | 4611bd6c0eeb9d3b176282b1dcf44993 |
|
BLAKE2b-256 | 0b61c877f8e8d0f419728534601bdd6c5ec47bfb8f845783eec8503f90f25e37 |
Close
Hashes for longport-1.0.32-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00d2298848574f7e133fb5e8aad04581b69a596b7048da61da63b7899b40b6a4 |
|
MD5 | 884b5713b6fecb2bc33b9c4813889c48 |
|
BLAKE2b-256 | 83b41daaf508ccf23c46f92f3db484efaf6e0f6421e84e6899c7d252cdbd5049 |
Close
Hashes for longport-1.0.32-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94eda065ff4a9be11b5d4c078e669071063b0f5ed2e57a0470ec76cdfe56b97c |
|
MD5 | f2238c493c3609ef2a0352a899d64211 |
|
BLAKE2b-256 | 40afa040092361f5190a528d1d9162acf54b1e2f76f8a33e2f98dc7fa61496eb |
Close
Hashes for longport-1.0.32-cp38-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce1fd388f3be403ce203718f7a690bed9fb95f223ef714870c1a545729fb0e9e |
|
MD5 | a97ae342e6f3bfd4d868fbcf9ef31176 |
|
BLAKE2b-256 | 6ccb402d455867f54f56c08a13a1e884734bb9d2d571a8d0e095eafc026650c9 |
Close
Hashes for longport-1.0.32-cp38-cp38-manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6fd1316e3866bd7167d392c661855c222671191dc52f8b76b43c4f044b33feb9 |
|
MD5 | d82e6178e3ba66b017a41cf91733bf08 |
|
BLAKE2b-256 | 3c15dc95c16cd0c12410326588200179b3c628f022703a74c73eaaafec5e69ab |
Close
Hashes for longport-1.0.32-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c87d2dd5740154326b436c40cce33c318827b5ebe2f6852018d8d117241e9fb |
|
MD5 | 896559d7502655ca10635acd91513428 |
|
BLAKE2b-256 | a2f098878bc9cef7f15674e0cda1b779ccb8b96c076034345cc6a86f3aecd6e2 |
Close
Hashes for longport-1.0.32-cp38-cp38-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76f402b249eb82c487074f479a0666d2cb561c62d325ea2a70fcc2b0cee8894a |
|
MD5 | 4cc8c3029f106ace27d04decead8ae6f |
|
BLAKE2b-256 | 06049642ec883ac5cd7e4b30775cea458fb66f90e2994289dfde0f2ac6bcffae |
Close
Hashes for longport-1.0.32-cp38-cp38-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9147496121c86ba656b7e182b65bd8c4843df867da5721d4e497dbd19d18e2a |
|
MD5 | 4ceb7f2d76f44046bb381070716f91a4 |
|
BLAKE2b-256 | 43589802ab783153fe15ec45ea30e99236b94626a965f72c94edc6bd18dcb368 |
Close
Hashes for longport-1.0.32-cp38-cp38-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1939a7951dddb3698568488ac865b299053bb3c7725d0a513f41c50e4a320ce4 |
|
MD5 | db808166d7f3bc911bd92188b355064c |
|
BLAKE2b-256 | 515b1885d4f345043d57dcf79da47df0cddc061aa43a19b2dc0715adca488a96 |
Close
Hashes for longport-1.0.32-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 954101cfc6c97ce8913f4c1f564d57876bb3ab40407156f8bea75f23a73238e1 |
|
MD5 | 16e8684d703d79b75738ddf440b2c764 |
|
BLAKE2b-256 | 509f1a0299450d7f379e50a1a2d6b5528115756fa9d61cfde5fe92210ac37851 |
Close
Hashes for longport-1.0.32-cp37-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ee27151d3c0d0317172fe011fd067c77ee19684a42828d2c176aa8cd10222cb |
|
MD5 | 824d6157f9e17c64fa909cfdd8d6ef9d |
|
BLAKE2b-256 | 9edc183e3590e58e3ecf70a798687bb3661d7006107782bb1f3f7bf31fb83693 |
Close
Hashes for longport-1.0.32-cp37-cp37m-manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5ca32ddd817e4a07750c01fbe794fe8fe0d803c27882cc11a0f02a55116d6c8 |
|
MD5 | 965297a5fe2a828f33ddd2bed0a63ea8 |
|
BLAKE2b-256 | ba4761c5f7a34c71c09a91613cb27f57e4e8d9a9fbce8b26aa5c43ce7c6e8ea6 |
Close
Hashes for longport-1.0.32-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8677880c824b8b66d677e92220253e23d9b5b87ea4ecdea1e24ea11468f6c3b |
|
MD5 | 1aee5e1f61abdb95204c942f337afa00 |
|
BLAKE2b-256 | 1be1a43652f3c728d11d6929e69e971f5d858e9095d53d5dd9fc9fc34fc48f0b |
Close
Hashes for longport-1.0.32-cp37-cp37m-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52057a3589fbae2f26fa3717272d9cd91b5d2be9fcd7c8f731fb2852940e044a |
|
MD5 | a910f7e0d50d05ae636aa133f8c70ad8 |
|
BLAKE2b-256 | 54410b12b703fe6da8828222213e355155509ad0545482a18ee7db99754be377 |
Close
Hashes for longport-1.0.32-cp37-cp37m-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de16b056bd4c38a47213b8c4536bd590389b0d95a1851b378d71f90b5366294e |
|
MD5 | 8d18245af56bd738dfc498c729973421 |
|
BLAKE2b-256 | a2cadcdb20ff9fa6ef64ec367a411ea243130c13739e331878e61bda497f493e |