跳到主要內容

獲取股票持倉

該接口用於獲取包括賬戶、股票代碼、持倉股數、可用股數、持倉均價(按賬戶設置計算均價方式)、幣種在內的股票持倉信息。

SDK Links

Python
longport.openapi.TradeContext.stock_positions
Rust
longport::trade::TradeContext#stock_positions
Go
TradeContext.StockPositions
Node.js
TradeContext#stockPositions

Request

HTTP MethodGET
HTTP URL/v1/asset/stock

Parameters

Content-Type: application/json; charset=utf-8

NameTypeRequiredDescription
symbolstring[]NO股票代碼,使用 ticker.region 格式,例如:AAPL.US

Request Example

# 獲取股票持倉
# https://open.longportapp.com/docs/trade/asset/stock
from longport.openapi import TradeContext, Config

config = Config.from_env()
ctx = TradeContext(config)
resp = ctx.stock_positions()
print(resp)

Response

Response Headers

  • Content-Type: application/json

Response Example

{
"code": 0,
"data": {
"list": [
{
"account_channel": "lb",
"stock_info": [
{
"symbol": "700.HK",
"symbol_name": "騰訊控股",
"currency": "HKD",
"quantity": "650",
"market": "HK",
"available_quantity": "-450",
"cost_price": "457.53",
"init_quantity": "214"
},
{
"symbol": "9991.HK",
"symbol_name": "寶尊電商-SW",
"currency": "HKD",
"market": "HK",
"quantity": "200",
"available_quantity": "0",
"cost_price": "32.25",
"init_quantity": "214"
},
{
"symbol": "TCEHY.US",
"symbol_name": "騰訊控股 (ADR)",
"currency": "USD",
"market": "US",
"quantity": "10",
"available_quantity": "10",
"init_quantity": "18"
},
{
"symbol": "2628.HK",
"symbol_name": "中國人壽",
"currency": "HKD",
"market": "HK",
"quantity": "9000",
"available_quantity": "0",
"init_quantity": "8000"
},
{
"symbol": "5.HK",
"symbol_name": "匯豐控股",
"currency": "HKD",
"market": "HK",
"quantity": "2400",
"available_quantity": "2000",
"init_quantity": "2000"
},
{
"symbol": "BABA.US",
"symbol_name": "阿里巴巴",
"currency": "USD",
"market": "US",
"quantity": "2000209",
"available_quantity": "2000209",
"init_quantity": "214"
},
{
"symbol": "2.HK",
"symbol_name": "中電控股",
"currency": "HKD",
"market": "HK",
"quantity": "2000",
"available_quantity": "2000",
"init_quantity": "2000"
},
{
"symbol": "NOK.US",
"symbol_name": "諾基亞",
"currency": "USD",
"market": "US",
"quantity": "1",
"available_quantity": "0",
"init_quantity": "1"
}
]
}
]
}
}

Response Status

StatusDescriptionSchema
200返回成功stock_rsp
400內部錯誤None

Schemas

stock_rsp

NameTypeRequiredDescription
listobject[]false股票持倉信息
∟ account_channelstringtrue賬戶類型
∟ stock_infoobject[]false股票列表
∟∟ symbolstringtrue股票代碼
∟∟ symbol_namestringtrue股票名稱
∟∟ quantitystringtrue持倉股數
∟∟ available_quantitystringfalse可用股數
∟∟ currencystringtrue幣種
∟∟ marketstringtrue市場
∟∟ cost_pricestringtrue成本價格 (具體根據客戶端選擇平均買入還是攤薄成本)
∟∟ init_quantitystringfalse開盤前初始持倉