Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions docs/quote/pull/broker-ids.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,40 @@ sidebar_position: 7
[业务指令](../../socket/protocol/request):`16`
:::

## Request

### Request Example

```python
# 获取券商席位 id
# https://open.longbridgeapp.com/docs/quote/pull/broker-ids
import os
import time
from google.protobuf import text_format
from longbridge.http import Auth, Config, HttpClient
from longbridge.ws import ReadyState, WsCallback, WsClient
# Protobuf 变量定义参见:https://github.com/longbridgeapp/openapi-protobufs/blob/main/quote/api.proto
from longbridge.proto.quote_pb2 import (Command, ParticipantBrokerIdsResponse)

class MyWsCallback(WsCallback):
def on_state(self, state: ReadyState):
print(f"-> state: {state}")

auth = Auth(os.getenv("LONGBRIDGE_APP_KEY"), os.getenv("LONGBRIDGE_APP_SECRET"), access_token=os.getenv("LONGBRIDGE_ACCESS_TOKEN"))
http = HttpClient(auth, Config(base_url="https://openapi.lbkrs.com"))
ws = WsClient("wss://openapi-quote.longbridge.global", http, MyWsCallback())

# 运行前请访问 “开发者中心“ 确保账户有正确的行情权限。
# 如没有开通行情权限,可以通过 "长桥" 手机客户端,并进入 “我的 - 我的行情 - 行情商城“ 购买开通行情权限。
result = ws.send_request(Command.QueryParticipantBrokerIds, "")
resp = ParticipantBrokerIdsResponse()
resp.ParseFromString(result)

print(f"Broker ids:\n\n")
for broker_number in resp.participant_broker_numbers:
print(f"{text_format.MessageToString(broker_number, as_utf8=True)}")
```

## Response

### Response Properties
Expand Down
30 changes: 30 additions & 0 deletions docs/quote/pull/brokers.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,36 @@ message SecurityRequest {
}
```

### Request Example

```python
# Get Security Brokers
# https://open.longbridgeapp.com/docs/quote/pull/brokers
import os
import time
from longbridge.http import Auth, Config, HttpClient
from longbridge.ws import ReadyState, WsCallback, WsClient
# Protobuf 变量定义参见:https://github.com/longbridgeapp/openapi-protobufs/blob/main/quote/api.proto
from longbridge.proto.quote_pb2 import (Command, SecurityRequest, SecurityBrokersResponse)

class MyWsCallback(WsCallback):
def on_state(self, state: ReadyState):
print(f"-> state: {state}")

auth = Auth(os.getenv("LONGBRIDGE_APP_KEY"), os.getenv("LONGBRIDGE_APP_SECRET"), access_token=os.getenv("LONGBRIDGE_ACCESS_TOKEN"))
http = HttpClient(auth, Config(base_url="https://openapi.lbkrs.com"))
ws = WsClient("wss://openapi-quote.longbridge.global", http, MyWsCallback())

# 运行前请访问 “开发者中心“ 确保账户有正确的行情权限。
# 如没有开通行情权限,可以通过 "长桥" 手机客户端,并进入 “我的 - 我的行情 - 行情商城“ 购买开通行情权限。
req = SecurityRequest(symbol="700.HK")
result = ws.send_request(Command.QueryBrokers, req.SerializeToString())
resp = SecurityBrokersResponse()
resp.ParseFromString(result)

print(f"Brokers:\n\n {resp}")
```

## Response

### Response Properties
Expand Down
30 changes: 30 additions & 0 deletions docs/quote/pull/candlestick.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,36 @@ message SecurityCandlestickRequest {
}
```

### Request Example

```python
# 获取标的 k 线
# https://open.longbridgeapp.com/docs/quote/pull/candlestick
import os
import time
from longbridge.http import Auth, Config, HttpClient
from longbridge.ws import ReadyState, WsCallback, WsClient
# Protobuf 变量定义参见:https://github.com/longbridgeapp/openapi-protobufs/blob/main/quote/api.proto
from longbridge.proto.quote_pb2 import (Command, SecurityCandlestickRequest, SecurityCandlestickResponse)

class MyWsCallback(WsCallback):
def on_state(self, state: ReadyState):
print(f"-> state: {state}")

auth = Auth(os.getenv("LONGBRIDGE_APP_KEY"), os.getenv("LONGBRIDGE_APP_SECRET"), access_token=os.getenv("LONGBRIDGE_ACCESS_TOKEN"))
http = HttpClient(auth, Config(base_url="https://openapi.lbkrs.com"))
ws = WsClient("wss://openapi-quote.longbridge.global", http, MyWsCallback())

# 运行前请访问 “开发者中心“ 确保账户有正确的行情权限。
# 如没有开通行情权限,可以通过 "长桥" 手机客户端,并进入 “我的 - 我的行情 - 行情商城“ 购买开通行情权限。
req = SecurityCandlestickRequest(symbol="700.HK", period=1000, count=10, adjust_type=0)
result = ws.send_request(Command.QueryCandlestick, req.SerializeToString())
resp = SecurityCandlestickResponse()
resp.ParseFromString(result)

print(f"Candlesticks:\n\n {resp}")
```

## Response

### Response Properties
Expand Down
30 changes: 30 additions & 0 deletions docs/quote/pull/depth.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,36 @@ message SecurityRequest {
}
```

### Request Example

```python
# 获取标的盘口
# https://open.longbridgeapp.com/docs/quote/pull/depth
import os
import time
from longbridge.http import Auth, Config, HttpClient
from longbridge.ws import ReadyState, WsCallback, WsClient
# Protobuf 变量定义参见:https://github.com/longbridgeapp/openapi-protobufs/blob/main/quote/api.proto
from longbridge.proto.quote_pb2 import (Command, SecurityRequest, SecurityDepthResponse)

class MyWsCallback(WsCallback):
def on_state(self, state: ReadyState):
print(f"-> state: {state}")

auth = Auth(os.getenv("LONGBRIDGE_APP_KEY"), os.getenv("LONGBRIDGE_APP_SECRET"), access_token=os.getenv("LONGBRIDGE_ACCESS_TOKEN"))
http = HttpClient(auth, Config(base_url="https://openapi.lbkrs.com"))
ws = WsClient("wss://openapi-quote.longbridge.global", http, MyWsCallback())

# 运行前请访问 “开发者中心“ 确保账户有正确的行情权限。
# 如没有开通行情权限,可以通过 "长桥" 手机客户端,并进入 “我的 - 我的行情 - 行情商城“ 购买开通行情权限。
req = SecurityRequest(symbol="700.HK")
result = ws.send_request(Command.QueryDepth, req.SerializeToString())
resp = SecurityDepthResponse()
resp.ParseFromString(result)

print(f"Depth:\n\n {resp}")
```

## Response

### Response Properties
Expand Down
30 changes: 30 additions & 0 deletions docs/quote/pull/intraday.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,36 @@ message SecurityIntradayRequest {
}
```

### Request Example

```python
# 获取标的分时
# https://open.longbridgeapp.com/docs/quote/pull/intraday
import os
import time
from longbridge.http import Auth, Config, HttpClient
from longbridge.ws import ReadyState, WsCallback, WsClient
# Protobuf 变量定义参见:https://github.com/longbridgeapp/openapi-protobufs/blob/main/quote/api.proto
from longbridge.proto.quote_pb2 import (Command, SecurityIntradayRequest, SecurityIntradayResponse)

class MyWsCallback(WsCallback):
def on_state(self, state: ReadyState):
print(f"-> state: {state}")

auth = Auth(os.getenv("LONGBRIDGE_APP_KEY"), os.getenv("LONGBRIDGE_APP_SECRET"), access_token=os.getenv("LONGBRIDGE_ACCESS_TOKEN"))
http = HttpClient(auth, Config(base_url="https://openapi.lbkrs.com"))
ws = WsClient("wss://openapi-quote.longbridge.global", http, MyWsCallback())

# 运行前请访问 “开发者中心“ 确保账户有正确的行情权限。
# 如没有开通行情权限,可以通过 "长桥" 手机客户端,并进入 “我的 - 我的行情 - 行情商城“ 购买开通行情权限。
req = SecurityIntradayRequest(symbol="700.HK")
result = ws.send_request(Command.QueryIntraday, req.SerializeToString())
resp = SecurityIntradayResponse()
resp.ParseFromString(result)

print(f"Intraday:\n\n {resp}")
```

## Response

### Response Properties
Expand Down
34 changes: 34 additions & 0 deletions docs/quote/pull/issuer.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,40 @@ sidebar_position: 13

:::

## Request

### Request Example

```python
# 获取轮证发行商 id
# https://open.longbridgeapp.com/docs/quote/pull/issuer
import os
import time
from google.protobuf import text_format
from longbridge.http import Auth, Config, HttpClient
from longbridge.ws import ReadyState, WsCallback, WsClient
# Protobuf 变量定义参见:https://github.com/longbridgeapp/openapi-protobufs/blob/main/quote/api.proto
from longbridge.proto.quote_pb2 import (Command, IssuerInfoResponse)

class MyWsCallback(WsCallback):
def on_state(self, state: ReadyState):
print(f"-> state: {state}")

auth = Auth(os.getenv("LONGBRIDGE_APP_KEY"), os.getenv("LONGBRIDGE_APP_SECRET"), access_token=os.getenv("LONGBRIDGE_ACCESS_TOKEN"))
http = HttpClient(auth, Config(base_url="https://openapi.lbkrs.com"))
ws = WsClient("wss://openapi-quote.longbridge.global", http, MyWsCallback())

# 运行前请访问 “开发者中心“ 确保账户有正确的行情权限。
# 如没有开通行情权限,可以通过 "长桥" 手机客户端,并进入 “我的 - 我的行情 - 行情商城“ 购买开通行情权限。
result = ws.send_request(Command.QueryWarrantIssuerInfo, "")
resp = IssuerInfoResponse()
resp.ParseFromString(result)

print(f"issuer info:\n\n")
for issuer in resp.issuer_info:
print(f"{text_format.MessageToString(issuer, as_utf8=True)}")
```

## Response

### Parameters
Expand Down
32 changes: 31 additions & 1 deletion docs/quote/pull/option-quote.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,36 @@ message MultiSecurityRequest {
}
```

### Request Example

```python
# 获取期权实时行情
# https://open.longbridgeapp.com/docs/quote/pull/option-quote
import os
import time
from longbridge.http import Auth, Config, HttpClient
from longbridge.ws import ReadyState, WsCallback, WsClient
# Protobuf 变量定义参见:https://github.com/longbridgeapp/openapi-protobufs/blob/main/quote/api.proto
from longbridge.proto.quote_pb2 import (Command, MultiSecurityRequest, OptionQuoteResponse)

class MyWsCallback(WsCallback):
def on_state(self, state: ReadyState):
print(f"-> state: {state}")

auth = Auth(os.getenv("LONGBRIDGE_APP_KEY"), os.getenv("LONGBRIDGE_APP_SECRET"), access_token=os.getenv("LONGBRIDGE_ACCESS_TOKEN"))
http = HttpClient(auth, Config(base_url="https://openapi.lbkrs.com"))
ws = WsClient("wss://openapi-quote.longbridge.global", http, MyWsCallback())

# 运行前请访问 “开发者中心“ 确保账户有正确的行情权限。
# 如没有开通行情权限,可以通过 "长桥" 手机客户端,并进入 “我的 - 我的行情 - 行情商城“ 购买开通行情权限。
req = MultiSecurityRequest(symbol=["AAPL230317P160000.US"])
result = ws.send_request(Command.QueryOptionQuote, req.SerializeToString())
resp = OptionQuoteResponse()
resp.ParseFromString(result)

print(f"Option quote:\n\n {resp.secu_quote}")
```

## Response

### Response Properties
Expand All @@ -40,7 +70,7 @@ message MultiSecurityRequest {
| ∟ open | string | 开盘价 |
| ∟ high | string | 最高价 |
| ∟ low | string | 最低价 |
| ∟ timestamp | int64 | 最新成交的交时间戳 |
| ∟ timestamp | int64 | 最新成交的时间戳 |
| ∟ volume | int64 | 成交量 |
| ∟ turnover | string | 成交额 |
| ∟ trade_status | int32 | 标的交易状态,详见 [TradeStatus](../objects#tradestatus---交易状态) |
Expand Down
30 changes: 30 additions & 0 deletions docs/quote/pull/optionchain-date-strike.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,36 @@ message OptionChainDateStrikeInfoRequest {
}
```

### Request Example

```python
# 获取标的的期权链到期日期权标的列表
# https://open.longbridgeapp.com/docs/quote/pull/optionchain-date-strike
import os
import time
from longbridge.http import Auth, Config, HttpClient
from longbridge.ws import ReadyState, WsCallback, WsClient
# Protobuf 变量定义参见:https://github.com/longbridgeapp/openapi-protobufs/blob/main/quote/api.proto
from longbridge.proto.quote_pb2 import (Command, OptionChainDateStrikeInfoRequest, OptionChainDateStrikeInfoResponse)

class MyWsCallback(WsCallback):
def on_state(self, state: ReadyState):
print(f"-> state: {state}")

auth = Auth(os.getenv("LONGBRIDGE_APP_KEY"), os.getenv("LONGBRIDGE_APP_SECRET"), access_token=os.getenv("LONGBRIDGE_ACCESS_TOKEN"))
http = HttpClient(auth, Config(base_url="https://openapi.lbkrs.com"))
ws = WsClient("wss://openapi-quote.longbridge.global", http, MyWsCallback())

# 运行前请访问 “开发者中心“ 确保账户有正确的行情权限。
# 如没有开通行情权限,可以通过 "长桥" 手机客户端,并进入 “我的 - 我的行情 - 行情商城“ 购买开通行情权限。
req = OptionChainDateStrikeInfoRequest(symbol="AAPL.US", expiry_date="20230120")
result = ws.send_request(Command.QueryOptionChainDateStrikeInfo, req.SerializeToString())
resp = OptionChainDateStrikeInfoResponse()
resp.ParseFromString(result)

print(f"Option chain info:\n\n {resp}")
```

## Response

### Response Properties
Expand Down
30 changes: 30 additions & 0 deletions docs/quote/pull/optionchain_date.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,36 @@ message SecurityRequest {
}
```

### Request Example

```python
# 获取标的的期权链到期日列表
# https://open.longbridgeapp.com/docs/quote/pull/optionchain-date
import os
import time
from longbridge.http import Auth, Config, HttpClient
from longbridge.ws import ReadyState, WsCallback, WsClient
# Protobuf 变量定义参见:https://github.com/longbridgeapp/openapi-protobufs/blob/main/quote/api.proto
from longbridge.proto.quote_pb2 import (Command, SecurityRequest, OptionChainDateListResponse)

class MyWsCallback(WsCallback):
def on_state(self, state: ReadyState):
print(f"-> state: {state}")

auth = Auth(os.getenv("LONGBRIDGE_APP_KEY"), os.getenv("LONGBRIDGE_APP_SECRET"), access_token=os.getenv("LONGBRIDGE_ACCESS_TOKEN"))
http = HttpClient(auth, Config(base_url="https://openapi.lbkrs.com"))
ws = WsClient("wss://openapi-quote.longbridge.global", http, MyWsCallback())

# 运行前请访问 “开发者中心“ 确保账户有正确的行情权限。
# 如没有开通行情权限,可以通过 "长桥" 手机客户端,并进入 “我的 - 我的行情 - 行情商城“ 购买开通行情权限。
req = SecurityRequest(symbol="AAPL.US")
result = ws.send_request(Command.QueryOptionChainDate, req.SerializeToString())
resp = OptionChainDateListResponse()
resp.ParseFromString(result)

print(f"Option chain date:\n\n {resp}")
```

## Response

### Response Properties
Expand Down
Loading