Closed AVISHAY123 closed 3 years ago
please provide more information, screenshot, error logs or sample code.
I want to calcuate margin before opening position How can I do that? I use that code after openning position:
Dim accountRow As AccountTableRow Set accounts = tableManager.getTable(TableType_Accounts) Set accountRow = accounts.getRow(0) freeMargin = accountRow.UsableMargin UsedMargin=accountRow.Equity - accountRow.UsableMargin + accountRow.GrossPL
the values are not right
freeMargin=3760.1
UsedMargin= 1099.86
accountrow.UsedMargin - getting an error
here is example code how to get margins per symbol:
Sub showMarginRequirements(instrument As String, text As String) Dim loginRules As ILoginRules Set loginRules = mSession.getLoginRules() Dim tradingSetting As ITradingSettingsProvider Set tradingSetting = loginRules.getTradingSettingsProvider() Dim accountsResponse As IResponse Set accountsResponse = loginRules.getTableRefreshResponse(TableType_Accounts) Dim responseReaderFactory As IResponseReaderFactory Set responseReaderFactory = mSession.getResponseReaderFactory() Dim accounts As IAccountTableReader Set accounts = responseReaderFactory.createAccountsTableReader(accountsResponse) Dim accountRow As accountRow Set accountRow = accounts.getRow(0) Dim MMR As Double, EMR As Double, LMR As Double Call tradingSetting.getMargins(instrument, accountRow, MMR, EMR, LMR) MsgBox text + " mmr=" + MMR + "; emr=" + EMR + "; lmr=" + LMR End Sub
Thank you what is the difference between mmr emr lmr ? I get same data for them
Why is there a difference between the margins in the mt4 account and the ts2 account? ------------------------MT4--------------------------------TS2 aud/jpy------mmr=2.25 emr=2.25 lmr=2.25------mmr=9 emr=9 lmr=9 nzd/usd-----mmr=2 emr=2 lmr=2----------------mmr=8 emr=8 lmr=8
There are also pairs, which have no margins in TS2 and there in MT4 and vice versa -----------------------MT4-------------------------------TS2 us30-------- mmr=18.5 emr=18.5 lmr=18.5---mmr=-1 emr=-1 lmr=-1 nzd/jpy----- mmr=-1 emr=-1 lmr=-1--------- mmr=8 emr=8 lmr=8
Additionally, there are also pairs, which have no margins at all, in both TS2 and MT4
gbp/cad-----mmr=-1 emr=-1 lmr=-1------mmr=-1 emr=-1 lmr=-1 eur/nzd------mmr=-1 emr=-1 lmr=-1------mmr=-1 emr=-1 lmr=-1
please try to subscribe for these symbols, you can enable them from Trading Station or from API.
how to subscribe? And, When to unsubscribe and whether it is necessary?
just open Trading Station desktop, and check if these symbols are visible, if not then enable them, than check in your code if it works.
ok but, how do I do this from api?
please check GetOffers example form our package O2GRequest offersRequest = requestFactory.createRefreshTableRequest(O2GTableType.Offers); responseListener.SetRequestID(offersRequest.RequestID); session.sendRequest(offersRequest); if (!responseListener.WaitEvents()) { throw new Exception("Response waiting timeout expired"); } response = responseListener.GetResponse(); if (response != null) { responseListener.PrintOffers(session, response, null); }
thank you but this is not in VBA and, I don't have GetOffers in my package is there a link?
you need to download ForexConnect for COM http://www.fxcodebase.com/wiki/index.php/Using_ForexConnect_in_COM you will find the example in VBA
thank you I already have the new version but, there is no GetOffers in vba sample
Can you show me GetOffers function for vba, please?
please try "Subscription" example in VBA samples folder
Ok, thank you Now it works on mt4 account without some symbols like aus2000, usdzar, usdtry, eurtry, cooper, volx but in TS2 account it doesnt work for many symbols like audnzd us30 audchf and many others I tried TS2 account in VBA sample in excel, and those symbols did not change at all - what cam I do?
Additionally, there are significant differences in margins, between the mt4 account and the ts2 account, regardless of the API - why is that?
first make sure you see price update correctly on our GUI. say TS2 MT4 and TS2 accounts have different profiles that have different margin or price
There is a small difference between the MT4 update and the TS2 update now, I subscribe audnzd in the GUI, and I can get its margin and update via API But I want to subscribe via API
If I open a new account, there are many non-subscribed symbols VBA sample not help for that I need the code for that, please
Can you give VBA sample please for subscribe symbols?
please download com package http://www.fxcodebase.com/wiki/index.php/Using_ForexConnect_in_COM sample code under ForexConnectAPIx64\samples\com\VBA\Subscription
Also, some pairs giving wrong value, when using accountRow.UsableMargin accountRow.UsedMargin doesn't work at all in mt4 account