IntroductionI am working on a full automatic trading solution. as part of my evaluation before opening a trade it should be possible to know the (exact) commission (in pips) that i have to pay for opening the position.
ProblemActually there are 3 "problems"
- get the commission when the system starts (so get it without opening/closing an order first)
- get the commission when the system is running (so that we always know the current commission rate)
- get the commission in pips without using instruments that we do not trade
Getting the commission when the system startsThe current commission rate is available in
Portfolio->my commission, however i don't want to manually look it up and input it in my trading system.
A workaround could be to do a small trade (1000 base units) and calculate the commission, however this is inaccurate (commission is rounded at small trades, for example 1000000 EUR/USD @ 18 costs 24.95 USD one way but 1000 cost me 0.02 USD)
Another problem with the workaround is that you need to receive different instrument quotes to do the calculation (if account currency is EUR, and you do a USD/JPY trade, you also need the EUR/USD quotes to calculate).
Solution: It would be nice to create a method like
(double) IAccount.getCommission that returns the commissions in USD$ per MIL.
Get the commission when the system is runningWhen the system is running we want to be sure to get the current commission rate, after we started it could be changed (because we do a lot of trades for example). So it would be nice to update the commission.
In my opinion there are different ways to do this
- Every time we want to know the commission we run the above method (IAccount.getCommission). this is not preferred is costs time/CPU and is a bad practice.
- Calculate/save commission based on the commission costs of the most recent order. this is not preferred either because it is inaccurate for small trades/orders due to rounding
- Include the current commission rate in the order stats. this is not preferred because the commission could be downgraded when we don't trade a lot and we don't know this if we don't do an order for some time.
- Save the commission when we receive an iMessage telling us that the commission rate changed. this is preferred
The best way (in my opinion) is to send an iMessage when the commission rate is changed. one way of doing it is to include the new commission rate in the message content. another way is to run the new method (IAccount.getCommission) when the message is recieved.
Get the commission in pips without using instruments that we do not tradeAnother great feature would be to know/retrieve the commission rate in Pips. if we know the rate (with the suggested method) we still need to do some conversions to get the pip value (for example base currency EUR, and want to know pip value for EUR/JPY. then we need to know the EUR/USD quote).
It is not hard to calculate it if we have the quotes but i don't want to receive all the quotes all the time for the different instruments that i don't trade.
Solution: A better way should be to to send them once every while so that the API has some quotes available when the new method is run: (double)
Instrument.getCommissionInPipsThere is a chance that the quotes for the non-traded instruments are out-dated if they are send once every while, however when calculating the commission a small 'rounding' error has not much impact.