Longbridge Developers
立即开始

美股资产概览

Longbridge US 账户

此方法仅适用于美国数据中心账户。

获取美股账户资产概览——买入力、现金、股票、期权和加密货币。

>_ CLI
# 美股账户资产概览
longbridge positions

Parameters

SDK 方法参数。

无需参数。

Request Example

from longbridge.openapi import TradeContext, Config, OAuthBuilder

oauth = OAuthBuilder("your-client-id").build(lambda url: print("请访问:", url))
config = Config.from_oauth(oauth)
ctx = TradeContext(config)
resp = ctx.us_asset_overview()
print(resp)
import asyncio
from longbridge.openapi import AsyncTradeContext, Config, OAuthBuilder

async def main() -> None:
    oauth = await OAuthBuilder("your-client-id").build_async(lambda url: print("请访问:", url))
    config = Config.from_oauth(oauth)
    ctx = AsyncTradeContext.create(config)
    resp = await ctx.us_asset_overview()
    print(resp)

if __name__ == "__main__":
    asyncio.run(main())
const { Config, TradeContext, OAuth } = require('longbridge')

async function main() {
  const oauth = await OAuth.build('your-client-id', (_, url) => {
    console.log('请访问此 URL 授权:' + url)
  })
  const config = Config.fromOAuth(oauth)
  const ctx = TradeContext.new(config)
  const resp = await ctx.usAssetOverview()
  console.log(resp)
}
main().catch(console.error)
import com.longbridge.*;
import com.longbridge.trade.*;

class Main {
    public static void main(String[] args) throws Exception {
        try (OAuth oauth = new OAuthBuilder("your-client-id").build(url -> System.out.println("Open to authorize: " + url)).get();
             Config config = Config.fromOAuth(oauth);
             TradeContext ctx = TradeContext.create(config)) {
            var resp = ctx.getUsAssetOverview().get();
            System.out.println(resp);
        }
    }
}
use std::sync::Arc;
use longbridge::{oauth::OAuthBuilder, trade::TradeContext, Config};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let oauth = OAuthBuilder::new("your-client-id").build(|url| println!("请访问:{url}")).await?;
    let config = Arc::new(Config::from_oauth(oauth));
    let ctx = TradeContext::new(config);
    let resp = ctx.us_asset_overview().await?;
    println!("{:?}", resp);
    Ok(())
}
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/longbridge/openapi-go/config"
	"github.com/longbridge/openapi-go/oauth"
	"github.com/longbridge/openapi-go/trade"
)

func main() {
	o := oauth.New("your-client-id").
		OnOpenURL(func(url string) { fmt.Println("Open this URL to authorize:", url) })
	if err := o.Build(context.Background()); err != nil {
		log.Fatal(err)
	}
	conf, err := config.New(config.WithOAuthClient(o))
	if err != nil {
		log.Fatal(err)
	}
	c, err := trade.NewFromCfg(conf)
	if err != nil {
		log.Fatal(err)
	}
	defer c.Close()
	resp, err := c.USAssetOverview(context.Background())
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", resp)
}

Response

Response Example

{
  "account_type": "US",
  "asset_timestamp": 1751866334,
  "cash_buy_power": "12500.00",
  "overnight_buy_power": "10000.00",
  "currency": "USD",
  "cash_list": [
    {
      "currency": "USD",
      "total_cash": "12500.00",
      "settled_cash": "12000.00",
      "total_amount": "12500.00",
      "outstanding": "500.00",
      "frozen_buy_cash": "0.00"
    }
  ],
  "stock_list": [
    {
      "symbol": "AAPL.US",
      "quantity": "10",
      "currency": "USD",
      "average_cost": "180.00",
      "last_done": "185.00",
      "prev_close": "183.00",
      "asset_type": "stock",
      "trade_status": "Normal"
    }
  ],
  "crypto_list": [
    {
      "symbol": "BTCUSD.BKKT",
      "average_cost": "50000.00",
      "currency": "USD",
      "asset_type": "crypto",
      "industry_name": "Cryptocurrency"
    }
  ]
}

Response Status

状态码描述结构
200成功USAssetOverview
400请求错误None

Schemas

USAssetOverview

名称类型必填描述
account_typestring账户类型标识
asset_timestampint64资产数据快照时间(Unix 秒)
cash_buy_powerstring可用买入力(现金)
overnight_buy_powerstring隔夜买入力
currencystring基础货币
cash_listUSCashEntry[]按货币分列的现金余额
stock_listUSStockEntry[]股票持仓
option_listobject[]期权持仓
crypto_listUSCryptoEntry[]加密货币持仓

USCashEntry

名称类型描述
currencystring货币代码
total_cashstring总现金
settled_cashstring已结算现金
total_amountstring含未结算的总金额
outstandingstring未结算金额
frozen_buy_cashstring待成交买单冻结金额

USStockEntry

名称类型描述
symbolstring股票代码(如 AAPL
full_symbolstring完整代码(如 AAPL.US
asset_typestring资产类型
quantitystring持有数量
currencystring货币代码
average_coststring平均持仓成本价
marketstring市场标识
trade_statusstring交易状态
prev_closestring上一收盘价
last_donestring最新成交价
market_pricestring当前市场价格
today_plstring当日盈亏
namestring证券名称
position_sidestring持仓方向(多/空)
industry_namestring行业/板块名称

USCryptoEntry

名称类型描述
symbolstring加密货币交易对代码,如 BTCUSD.BKKT
average_coststring平均持仓成本价
currencystring计价货币
asset_typestring资产类型
industry_namestring行业/分类名称