Futures
Access hundreds of perpetual contracts
CFD
Gold
One platform for global traditional assets
Options
Hot
Trade European-style vanilla options
Unified Account
Maximize your capital efficiency
Demo Trading
Introduction to Futures Trading
Learn the basics of futures trading
Futures Events
Join events to earn rewards
Demo Trading
Use virtual funds to practice risk-free trading
CFD
Stock CFD Derivatives
US Stocks
Access real US stocks and ETFs
HK Stocks
Trade quality Hong Kong-listed stocks
Korean Stocks
SK Hynix
Real Korean stocks and top assets
Stock Futures
High leverage, 24/7 trading
Tokenized Stocks
Backed by real stock assets
IPO Access
Unlock full access to global stock IPOs
GUSD
3.8%
Mint GUSD for Treasury RWA yields
Stocks Activities
Trade Popular Stocks and Unlock Generous Airdrops
Launch
CandyDrop
Collect candies to earn airdrops
Launchpool
Quick staking, earn potential new tokens
HODLer Airdrop
Hold GT and get massive airdrops for free
IPO Access
Unlock full access to global stock IPOs
Alpha Points
Trade on-chain assets and earn airdrops
Futures Points
Earn futures points and claim airdrop rewards
Promotions
AI
Gate AI
Your all-in-one conversational AI partner
Gate AI Bot
Use Gate AI directly in your social App
GateClaw
Gate Blue Lobster, ready to go
Gate for AI Agent
AI infrastructure, Gate MCP, Skills, and CLI
Gate Skills Hub
10K+ Skills
From office tasks to trading, the all-in-one skill hub makes AI even more useful.
fable just walked me through a logic error in my own trades report design. quite impressed with this.
basically I am trying to get at reconciling EoM balances with PnL.
for this I need realized PnL (easy) + unrealized PnL.
the first problem is pretty basic and was already solved for:
unrealized PnL carries over from balances already accounted for in previous months.
for example you have $1000 in balance, and in May you have a position up $100. Let's say that position is now $300 unrealized in June. Your balance was $1,100 at the end of May and if everything is correct, it should be $1,300 in June.
but if you factor in the entire position open PnL your trade report will say that your balance should be $1,400 because you're duplicating the already accounted for $100 from May.
so we have to subtract unrealized PnL from previous periods.
it becomes a bit more tricky because I do a lot of daily rebalances so we have thousands of transactions that we need to account for their fills, when, and their contribution to that position's unrealized PnL this month.
so far fine, pretty basic stuff.
the problem fable found was that I was not thinking about when we account the realized PnL for current month (the correct value from an accounting perspective) we have to factor in the portion of the PnL that was accounted as unrealized in previous month's balances, otherwise we are double counting their effect.
in our previous example lets say that in June we book the full $300 profit when we close the position. THIS is the correct value as far as an accountant is concerned.
however to match with the balances tracker, it means I have to remove the portion that was realized/added in previous months from the unrealized PnL , almost like a deduction of booked values from previous months.
this is a bit of conflict between internal tracking and for accounting purposes but they must match otherwise i can't always be sure my values are correct. I mean I know they are because of the exchange report of realized trades, which again is what matters for accounting purposes for now, but I am a bit anal about it.
PnL now reconciles perfectly with EoM balances.
I should've known better, getting dumber by the day as we use AI as a crutch for every problem we got.