Skip to main content

Unrealized P&L Query

UnrealizedGainsAndLoses

Input Parameters

ParameterTypeDescription
accountAccountAccount

Result Return

ParameterTypeDescription
IsSuccessboolWhether successful
Data*[]UnrealizedDataReturns unrealized P&L list
Message*stringReturns error message when IsSuccess = false

Unrealized Data Fields

ParameterTypeDescription
Date*stringInventory Creation Date
BranchNo*stringBranch Code
StockNo*stringStock Symbol
BuySellBsActionBuy/Sell Action: BsActionBuy Buy, BsActionSell Sell
OrderTypeOrderTypeOrder Type: OrderTypeStock Common, OrderTypeMargin Margin, OrderTypeShort Short Sell, OrderTypeDayTrade Day Trade, OrderTypeSbl SBL
CostPrice*stringCost Price
TradableQty*int64Tradable Balance
TodayQty*int64Today's Balance
UnrealizedProfit*int64Unrealized Profit
UnrealizedLoss*int64Unrealized Loss
info

For common stock trading, buy_sell is always Buy, and the net position is indicated by the positive/negative sign of the balance. For margin trading, buy_sell is Buy or Sell to indicate the transaction type.

Request Example

package main

import (
"fmt"
"fubon"
)

func main() {
sdk := fubon.NewSDK()
// ... Login, connection, and other initialization steps ...

// Query Unrealized P&L
unreal, err := sdk.Accounting.UnrealizedGainsAndLoses(account)
if err != nil {
fmt.Printf("❌ Unrealized P&L Format/Parser Error: %v\n", err)
return
}

if unreal.IsSuccess && unreal.Data != nil {
fmt.Printf("✅ Found %d positions\n", len(*unreal.Data))

totalProfit := int64(0)
totalLoss := int64(0)

for _, u := range *unreal.Data {
fmt.Printf("\nStock: %s\n", *u.StockNo)
fmt.Printf("Cost Price: %s\n", *u.CostPrice)
fmt.Printf("Today Balance: %d\n", *u.TodayQty)
fmt.Printf("Unrealized Profit: %d\n", *u.UnrealizedProfit)
fmt.Printf("Unrealized Loss: %d\n", *u.UnrealizedLoss)

totalProfit += *u.UnrealizedProfit
totalLoss += *u.UnrealizedLoss
}

netPnL := totalProfit - totalLoss
fmt.Printf("\nTotal Unrealized P&L: %d\n", netPnL)
}
}

Response Example

Result{
IsSuccess: true,
Message: nil,
Data: &[]UnrealizedData{
{
Date: "2021/08/09", // Inventory Creation Date
Account: "26", // Account
BranchNo: "6460", // Branch Code
StockNo: "2303", // Stock Symbol
BuySell: Buy, // Buy/Sell Action
OrderType: Short, // Order Type
CostPrice: "50.0", // Cost Price
TradableQty: 1000, // Tradable Balance
TodayQty: 1000, // Today's Balance
UnrealizedProfit: 45200, // Unrealized Profit
UnrealizedLoss: 0, // Unrealized Loss
},
},
}