Calculating P/L
Created at 15 Feb 2022, 12:26
Calculating P/L
15 Feb 2022, 12:26
Hi,
I saw a lot of threads here, that in order to calculate Lot Size in OPEN API we must follow Profit/Loss Calculation Tutorial provided there.
As i'm following the tutorial and trying to implement that on my code i have two things that i'm not understanding.
1. When i send the request at ProtoOASymbolsForConversionReq the response of it not returning bid and ask price to do this part of code:
fromAsset = "JPY"
toAsset = "USD"
// rate will be our conversion result
rate = 1
// symbols are the ProtoOASymbolsForConversionRes symbols field
symbols[] = ProtoOASymbolsForConversionRes(fromAsset,toAsset)
asset = fromAsset
FOR symbol in symbols:
IF positionDirection == SHORT:
closePrice = symbol.ask
ELSE:
closePrice = symbol.bid
IF symbol.baseAsset == asset:
rate = rate * closePrice
asset = symbol.quoteAsset
ELSE:
rate = rate * 1 / closePrice
asset = symbol.baseAsset
2. While reading the tutorial (maybe i'm missing something) the last part of code where is:
volume = positionVolumeMonetary / 100
My question here is where do we get this positionVolumeMonetary?
Regards, Albi!
amusleh
16 Feb 2022, 10:11
Hi,
To convert a symbol price you have to have all the symbol conversion chain symbols latest bid/ask prices, you can get the bid/ask prices of the symbols by using ProtoOASubscribeSpotsReq/ProtoOASubscribeSpotsRes and ProtoOASpotEvent.
Regarding your second point, positionVolumeMonetary is the volume of position you want to get it's profit/loss in monetary units which is the unit that is used on Open API.
To get a position volume you can use either ProtoOAReconcileReq/ProtoOAReconcileRes in case position is already open or ExecutionEvent.
We have a working desktop app sample and a web app sample that calculates the positions PL and live accounts PL at: spotware/OpenAPI.Net: cTrader Open API .NET Rx library (github.com)
@amusleh