Unrealized P&L Query
UnrealizedGainsAndLoses
Input Parameters
| Parameter | Type | Description |
|---|---|---|
| account | Account | Account |
Result Return
| Parameter | Type | Description |
|---|---|---|
| IsSuccess | bool | Whether successful |
| Data | *[]UnrealizedData | Returns unrealized P&L list |
| Message | *string | Returns error message when IsSuccess = false |
Unrealized Data Fields
| Parameter | Type | Description |
|---|---|---|
| Date | *string | Inventory Creation Date |
| BranchNo | *string | Branch Code |
| StockNo | *string | Stock Symbol |
| BuySell | BsAction | Buy/Sell Action: BsActionBuy Buy, BsActionSell Sell |
| OrderType | OrderType | Order Type: OrderTypeStock Common, OrderTypeMargin Margin, OrderTypeShort Short Sell, OrderTypeDayTrade Day Trade, OrderTypeSbl SBL |
| CostPrice | *string | Cost Price |
| TradableQty | *int64 | Tradable Balance |
| TodayQty | *int64 | Today's Balance |
| UnrealizedProfit | *int64 | Unrealized Profit |
| UnrealizedLoss | *int64 | Unrealized 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
},
},
}