Longbridge Developers
Get Started

Profit Analysis Detail

Get detailed P&L for a specific security including transaction flow and cost breakdown.

>_ CLI
longbridge profit-analysis detail TSLA.US
longbridge profit-analysis detail AAPL.US

Parameters

SDK method parameters.

NameTypeRequiredDescription
symbolstringYESSecurity symbol, e.g. AAPL.US
startstringNOStart date, YYYY-MM-DD
endstringNOEnd date, YYYY-MM-DD

Request Example

from longbridge.openapi import PortfolioContext, Config, OAuthBuilder

oauth = OAuthBuilder("your-client-id").build(lambda url: print("Visit:", url))
config = Config.from_oauth(oauth)
ctx = PortfolioContext(config)

resp = ctx.profit_analysis_detail("TSLA.US")
print(resp)
import asyncio
from longbridge.openapi import AsyncPortfolioContext, Config, OAuthBuilder

async def main() -> None:
    oauth = await OAuthBuilder("your-client-id").build_async(lambda url: print("Visit:", url))
    config = Config.from_oauth(oauth)
    ctx = AsyncPortfolioContext.create(config)

    resp = await ctx.profit_analysis_detail("TSLA.US")
    print(resp)

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

async function main() {
  const oauth = await OAuth.build('your-client-id', (_, url) => {
    console.log('Open this URL to authorize: ' + url)
  })
  const config = Config.fromOAuth(oauth)
  const ctx = PortfolioContext.new(config)
  const resp = await ctx.profit_analysis_detail()
  console.log(resp)
}
main().catch(console.error)
import com.longbridge.*;
import com.longbridge.portfolio.*;

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);
             PortfolioContext ctx = PortfolioContext.create(config)) {
            var resp = ctx.getProfitAnalysisDetail().get();
            System.out.println(resp);
        }
    }
}
use std::sync::Arc;
use longbridge::{oauth::OAuthBuilder, portfolio::PortfolioContext, Config};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let oauth = OAuthBuilder::new("your-client-id").build(|url| println!("Open: {url}")).await?;
    let config = Arc::new(Config::from_oauth(oauth));
    let ctx = PortfolioContext::new(config);
    let resp = ctx.profit_analysis_detail().await?;
    println!("{:?}", resp);
    Ok(())
}
#include &lt;iostream&gt;
#include <longbridge.hpp>

using namespace longbridge;
using namespace longbridge::portfolio;

int main() {
    OAuthBuilder("your-client-id").build(
        [](const std::string& url) { std::cout << "Open: " << url << std::endl; },
        [](auto res) {
            if (!res) return;
            Config config = Config::from_oauth(*res);
            PortfolioContext ctx = PortfolioContext::create(config);
            ctx.profit_analysis_detail([](auto resp) {
                if (resp) std::cout << "OK" << std::endl;
            });
        });
    std::cin.get();
}
package main

import (
	"context"
	"fmt"
	"log"

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

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 := portfolio.NewFromCfg(conf)
	if err != nil {
		log.Fatal(err)
	}
	defer c.Close()
	resp, err := c.ProfitAnalysisDetail(context.Background())
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", resp)
}

Response

Response Example

{
  "code": 0,
  "message": "success",
  "data": {
    "name": "Apple",
    "currency": "USD",
    "profit": "100.00",
    "start": "1763769600",
    "end": "1778724973",
    "start_date": "2025-11-22",
    "end_date": "2026-05-14",
    "default_tag": 0,
    "updated_at": "1778724973",
    "updated_date": "2026-05-14",
    "underlying_details": {
      "profit": "100.00",
      "holding_value": "1790.16",
      "holding_value_at_beginning": null,
      "holding_value_at_ending": "1790.16",
      "long_holding_value": "1790.16",
      "short_holding_value": "0.00",
      "cumulative_credited_amount": "0.00",
      "cumulative_debited_amount": "0.00",
      "cumulative_fee_amount": "0.00",
      "credited_details": [],
      "debited_details": [],
      "fee_details": []
    },
    "derivative_pnl_details": {
      "profit": "0.00",
      "holding_value": "0.00",
      "holding_value_at_beginning": null,
      "holding_value_at_ending": "0.00",
      "long_holding_value": "0.00",
      "short_holding_value": "0.00",
      "cumulative_credited_amount": "0.00",
      "cumulative_debited_amount": "0.00",
      "cumulative_fee_amount": "0.00",
      "credited_details": [],
      "debited_details": [],
      "fee_details": []
    }
  }
}

Response Status

StatusDescriptionSchema
200SuccessProfitAnalysisDetailResponse
400Bad requestNone

Schemas

ProfitAnalysisDetailResponse

NameTypeRequiredDescription
namestringfalseSecurity name
currencystringfalseCurrency
profitstringfalseTotal profit/loss
startintegerfalsePeriod start
endintegerfalsePeriod end
start_datestringfalseStart date
end_datestringfalseEnd date
default_tagintegerfalseDefault display tag
underlying_detailsobjectfalseUnderlying asset P&L breakdown
updated_atstringfalseLast update timestamp
updated_datestringfalseLast update date
derivative_pnl_detailsobjectfalseDerivatives P&L breakdown

ProfitDetails

NameTypeRequiredDescription
profitstringfalseTotal profit/loss
holding_valuestringfalseCurrent holding value
holding_value_at_beginningstringfalseHolding value at period start
holding_value_at_endingstringfalseHolding value at period end
long_holding_valuestringfalseLong position value
short_holding_valuestringfalseShort position value
cumulative_credited_amountstringfalseCumulative credited amount
cumulative_debited_amountstringfalseCumulative debited amount
cumulative_fee_amountstringfalseCumulative fee amount
credited_detailsobject[]falseCredit transaction details
debited_detailsobject[]falseDebit transaction details
fee_detailsobject[]falseFee transaction details