A Python library for Longbridge Open API
Project description
Longbridge OpenAPI SDK for Python
longbridge
provides an easy-to-use interface for invokes Longbridge OpenAPI
.
Quickstart
Install Longbridge OpenAPI SDK
pip install longbridge
Setting environment variables(MacOS/Linux)
export LONGBRIDGE_APP_KEY="App Key get from user center"
export LONGBRIDGE_APP_SECRET="App Secret get from user center"
export LONGBRIDGE_ACCESS_TOKEN="Access Token get from user center"
Setting environment variables(Windows)
setx LONGBRIDGE_APP_KEY "App Key get from user center"
setx LONGBRIDGE_APP_SECRET "App Secret get from user center"
setx LONGBRIDGE_ACCESS_TOKEN "Access Token get from user center"
Quote API (Get basic information of securities)
from longbridge.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 longbridge.openapi import Config, QuoteContext, SubType, PushQuote
# Load configuration from environment variables
config = Config.from_env()
# A callback to receive quote data
def on_quote(self, symbol: str, quote: PushQuote):
print(symbol, quote)
# 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 longbridge.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 Distribution
longbridge-0.2.18.tar.gz
(264.7 kB
view hashes)
Built Distributions
Close
Hashes for longbridge-0.2.18-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18e74c6c392867b96d9aae1022999980260b6a8f69bcf3ef930d76c4678667e7 |
|
MD5 | d5a98be3a5646be8f55a457f6cf2710d |
|
BLAKE2b-256 | 15a63273b150ae501316d628c4e094c65a4ac8614b63db7bda484ada29689d88 |
Close
Hashes for longbridge-0.2.18-cp310-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3cc8437a8a7c26b958fdf91c84eb4989b70804b8fa773a330da0ac36cd613b17 |
|
MD5 | ac4a5940a837bc790434e2d780a5fbc2 |
|
BLAKE2b-256 | 8f200e1845967b8970530627ee57a0ef29ffb0bf2d7770f9ff9d83c945362480 |
Close
Hashes for longbridge-0.2.18-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 713e90bbd37940186f19287d3b8447d7eb560fdcee365e9351faaa6fdc45a955 |
|
MD5 | e2935c14c39451e61e168c52748f40f2 |
|
BLAKE2b-256 | 1b889e1f00af09507db1743f3cb5477c0f487a7d2562bfb907da83ae1fab99a1 |
Close
Hashes for longbridge-0.2.18-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a986d88b32b2ab7651d6538d3ef4f91951c4b3fe85baabd291cc55ebfa720a72 |
|
MD5 | dcbcde6432891c9c0d44648a4b51648f |
|
BLAKE2b-256 | 8ee1849d3973070e78a66dcca806dd0029a49cf00198c7816d513d2e52f8cc0c |
Close
Hashes for longbridge-0.2.18-cp310-cp310-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22f3497d8373841d6dbf3bf20fd79c20efae25d3c1d5d5424192ed1ce4644076 |
|
MD5 | 20f88d0f89a73d9becfb4f9812e4aed9 |
|
BLAKE2b-256 | 056338eb2998d67fb8216111016e79f57916a0647aab8fe5836d928ae765aeeb |
Close
Hashes for longbridge-0.2.18-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c9a3d33219abfb9ae8fddc2056f4505bcea87dc5116546bb0e6385d55ef1ad7 |
|
MD5 | 1fa9d58ca2ace621abb165a076a2176a |
|
BLAKE2b-256 | c217561d6dc8ce7c071ca660faac19f87efe56abe0297c81c64a71687b553c64 |
Close
Hashes for longbridge-0.2.18-cp310-cp310-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b90f834586e795aeed9eac465c9c324ed630382aef52ec48dba592130fa3932 |
|
MD5 | 325df3e9e3ea6020f77cf46599bcc6cc |
|
BLAKE2b-256 | 95513f479c6957864c6d580dca23b96b78e10452c2b71da227cd7f0ba0992872 |
Close
Hashes for longbridge-0.2.18-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8295323cda1335267fe732f76089004f0f28b396201073a485c643b104d596c4 |
|
MD5 | 7c56054faf8f37114e7f0ce524fff5ad |
|
BLAKE2b-256 | e96d95d0288b1622cb4328ded7b819071a3765e9b99dcc7760abf41b938ceab1 |
Close
Hashes for longbridge-0.2.18-cp39-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e9871a772085f1f6cb0b36b9c385def5ae748fd529390959e8d0d61ca9b9202 |
|
MD5 | ead66f36dbff6bb97167585b9d920035 |
|
BLAKE2b-256 | 342acb5e5e827b65f0fa9843c0531c838b104f6f8abb2408124ab851e0471c04 |
Close
Hashes for longbridge-0.2.18-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6c0397e21f392e455498d1c3440f170267416de78f2ccf01d25b9717a4610a3 |
|
MD5 | fc424bd476351a4e5e29127b59fccbc4 |
|
BLAKE2b-256 | d0d20099f64bb71bed2dc3cb0bb9c952e37876b8a8670cc02d5c2419ce764596 |
Close
Hashes for longbridge-0.2.18-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 998e5df92c211379771451433f8e63b61593bf373797df24a2bbab450560468b |
|
MD5 | 33f0549edf8b33f850be3a05aab71bcb |
|
BLAKE2b-256 | c9c44cc24145e98147135479c614d8b2d84f603a0cd7ca4470e44dcf1daf8783 |
Close
Hashes for longbridge-0.2.18-cp39-cp39-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d791a8d65ecb9052bedfef25fcb5c194bcfbddddfc90614df23b7b5f70d52be7 |
|
MD5 | 4f2835ac51e131e091218963d5f6bb06 |
|
BLAKE2b-256 | 8693a067fb400711a9ba318ba496c43f7cfb986e55dd7ca8b30901099a9fd09c |
Close
Hashes for longbridge-0.2.18-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b0afc7c6debcdf673000154052c52679937c9a467bac5aa96b2571b17f2ac17 |
|
MD5 | 30480c867f19c903963e38df527b994c |
|
BLAKE2b-256 | 7d0e87b6c2ad67e72d6d566e0bd07735e3381fa74b68f18398e1a5b6107134f4 |
Close
Hashes for longbridge-0.2.18-cp39-cp39-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67632485ccbd2ff4588374db6c95d53834d467972cf583b20ebcb94fa6874485 |
|
MD5 | c073291c35e4c034de3a64b37bc7efd2 |
|
BLAKE2b-256 | 01c31133cc4e80d84b6c655cd0ab3693762db0a4524a5696ffaa0a57e14adb16 |
Close
Hashes for longbridge-0.2.18-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6d3ed0c0d841b3986e84b17f5351b77cc1d58d3a305ec47c843ac65ee190a97 |
|
MD5 | 05f39be9b91aac02823393f0d8c4ff0c |
|
BLAKE2b-256 | a0f014db4b0495a617e994e0cb8138c313cd7ee1db3a15b14bb54f48354deb32 |
Close
Hashes for longbridge-0.2.18-cp38-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad2f30a5f2f5caaadd2fb286efc654a1fcc94ff8a4e601a71ff1dcbcfcff12a6 |
|
MD5 | 7b3f01e49f6bfc509e7fcf3121e9b3d0 |
|
BLAKE2b-256 | d6978f8a12587d98d152001e746334b59002b4469c6d40dd227e3048f9ff1546 |
Close
Hashes for longbridge-0.2.18-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1cf22f28a5fbd346c50da96a5dc34bb7d8ff51442e2aac35f94e789e768d51db |
|
MD5 | fa483c1c9395d910fd2b3a2cf1ece64b |
|
BLAKE2b-256 | e66e8a9ebf24c8935be34cef6feadc74726ea1660ba6a6ee27682b5978458125 |
Close
Hashes for longbridge-0.2.18-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0412125070a62ea25c84390bc5e22107613f2cc3c3f9e380da5143c28eb5961f |
|
MD5 | df7c3f97cccab6475f7f7f94bb701ba8 |
|
BLAKE2b-256 | f54b2f2a380554af6aafb16a17880110429a5f7d23669a95c25c4d5591690c84 |
Close
Hashes for longbridge-0.2.18-cp38-cp38-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6aaf1e988a2010c08b182733eda1b3a00903db403e6018cc3cc7bb63672585d |
|
MD5 | ff417c0aefa09356538aa60f84f5952e |
|
BLAKE2b-256 | 282f95b39edc4c067c56a9b553042a64ee6361196b14899ced1a246cd0d9fa0d |
Close
Hashes for longbridge-0.2.18-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a74dd640f8fc16880d16680a84daaab7a15bcc2c809ce7ed5890b6fe3457942d |
|
MD5 | 4c495a93b39e00436274c4b55d68d8e3 |
|
BLAKE2b-256 | d71efa8c6cd7e3be3a9e7b74ca4d7bf01600c980fb4a4d91d8afed73c1dd5c8e |
Close
Hashes for longbridge-0.2.18-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c18cdc0bf7d2c734215c08a09229bbe391f069617539cac91582de1b9c9f8714 |
|
MD5 | 77b4224546796c77edbc81453933a892 |
|
BLAKE2b-256 | 7a3bd831c0b2d98e835abb84fe43d5e2ce65a9a571168cd1c16739f76ef40e70 |
Close
Hashes for longbridge-0.2.18-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb99e9dbd32a7623684da03d09098fccb4fdc05caf1a7c6965804be9efcd1d46 |
|
MD5 | 84ba0ac0ae627bfeedf90ba77b28f23b |
|
BLAKE2b-256 | d2ad2887d3e3e63033b710be50de49703c9f0ee47e9a5fd629e86c3c800f2f26 |
Close
Hashes for longbridge-0.2.18-cp37-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8080f736b4ad461f633c4c00e7028501ece87e4a7decf26a2715fd0002cf0a1b |
|
MD5 | a95d8d7556f760cf65ed97a84aaf4d62 |
|
BLAKE2b-256 | c72db3880ec4d2cc6608f85969065e17ba0afaf4c7385e239da99847f8bfdd9c |
Close
Hashes for longbridge-0.2.18-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb8c81384f0fa448bd8de469e082c706c8de5ff947056afc22fcead72daae8ad |
|
MD5 | 9f57f0796467646b95812967c38928c9 |
|
BLAKE2b-256 | a3286469736fd54cd5c0e3cec0b996828b2a0dff84e016bd9aaf39dda6f43c85 |
Close
Hashes for longbridge-0.2.18-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 453aafe09e838400f05f998344860ab07b74e0b10f5c75afe04f7151b5a4dc6f |
|
MD5 | 9edbd17a6e6c579d1c3d51e7a36321fd |
|
BLAKE2b-256 | 0b4a4718bfc4c2bb05847cad2ef111e17df29890e301a57df02a65e814c16bda |
Close
Hashes for longbridge-0.2.18-cp37-cp37m-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c606ee1eb0f163fd40e5d4ded242ee1b79233abb877757c5cd8f0211d94a676 |
|
MD5 | 3520b8474adecccdbd7c63a028c5a5ca |
|
BLAKE2b-256 | 89ba3312092a59a97696a7592d7493fec6b5433c51834e4e54625e4853e4149f |
Close
Hashes for longbridge-0.2.18-cp37-cp37m-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 126984cd4559e81e3420e04dd3dcf7d718c05fbed8153a57a3ea72577ce01dd5 |
|
MD5 | 0c250417862939152e6092b70d598d1f |
|
BLAKE2b-256 | cc6b896fdec46073ea8f165e4fbf32a49b6d9ecc348852d4a15b1143060e8a83 |