Margin higher than expected
Margin higher than expected
15 Jul 2023, 02:46
Hello dear ctradudes and dudenes,
I am coding on my cbots for quite some time now, and there is one part of which I cannot wiggle my head around.
And unfortunately I am not able to find help in the questions from others.
If I open a position, the Margin of the Position is higher than I formerly have calculated.
double wantedMargin = 50;
double wantedMarginInCorrectAsset = AssetConverter.Convert(wantedMargin, Assets.GetAsset("EUR"), Symbol.QuoteAsset);
double helper = wantedMarginInCorrectAsset / Symbol.Ask; // since Symbol.Ask is in Symbol.QuoteAsset
double volume = helper * Leverage; // in my case 5
double normVolume = Symbol.NormalizeVolume(volume, RoundingMode.Down); // to not exceed bugdet
TradeResult result = executeMarketOrder(TradeType.Buy, Symbol, normVolume, "myLabel");
// BUT after succesfull opening:
// result.Position.Margin == 66.07 != 50 == wantedMargin
//
// WHY?
I am struggeling with this task for a long time now, and hopefully someone can help.
All kind of related threads are always forex trades and I am not sure how that changes something if I trade a stock.
Base question is how to get the correct value that executeMarketOrder expects with a given amount of margin I want to invest?
All the best to you!