Commission Calculation
Commission Calculation
27 Nov 2021, 18:53
Hi Guys,
Just want to confirm a couple of things with regards to commissions;
1. Is it possible to get or calculate the commission charges for a specific currency pair using the cTrader Automate API?
2. If not, is there a way to get or calculate the CommissionPerMillion in USD for a specific currency pair using the cTrader Automate API or any of the other API's (Fix/Open)?
Example code for calculating the values if it isn't available via cTrader Automate API
using System;
using System.Collections.Generic;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Internals;
namespace FibonacciTradingEngine.Calculators
{
public class CommissionPerMillion
{
public string CurrencyPair { get; set; }
public double Rate { get; set; }
}
// Need to find a way to get this dynamically
public static class CommissionCalculator
{
private static List<CommissionPerMillion> GetAllCommissionRates()
{
return new List<CommissionPerMillion>()
{
new CommissionPerMillion()
{
CurrencyPair = "EURUSD",
Rate = 45
},
new CommissionPerMillion()
{
CurrencyPair = "USDJPY",
Rate = 45
},
};
}
private static CommissionPerMillion GetCommissionPerMillion(this string currencyPair)
{
return GetAllCommissionRates().FirstOrDefault(x => x.CurrencyPair == currencyPair);
}
private static double GetExchangeRate(this Symbols symbols, string currencyA, string currencyB)
{
if (currencyA.Equals(currencyB)) return 1;
var currencyPairA = String.Concat(currencyA, currencyB);
var currencyPairB = String.Concat(currencyB, currencyA);
var validCurrencyPair = symbols.Exists(currencyPairA)
? symbols.GetSymbol(currencyPairA)
: symbols.GetSymbol(currencyPairB);
if (validCurrencyPair == null) return double.NaN;
if (validCurrencyPair.Name.Equals(currencyPairA)) return validCurrencyPair.Bid;
if (validCurrencyPair.Name.Equals(currencyPairB)) return 1 / validCurrencyPair.Bid;
return double.NaN;
}
public static double CalculateCommission(this IAccount account, Symbols symbols, Symbol symbol, double volume)
{
var symbolName = symbol.Name;
var symbolBaseCurrency = symbolName.Substring(0, 3);
var accountCurrency = account.Asset.Name;
var commissionPerMillionInUsd = symbolName.GetCommissionPerMillion();
var baseCurrencyToUsdExchangeRate = symbols.GetExchangeRate(symbolBaseCurrency, "USD");
var accountCurrencyExchangeRate = symbols.GetExchangeRate(accountCurrency, symbolBaseCurrency);
var volumeInUsd = volume * baseCurrencyToUsdExchangeRate;
var commission = (commissionPerMillionInUsd.Rate / 1000000) * volumeInUsd * accountCurrencyExchangeRate;
// x2 For Open and Close Commission
return Math.Round(-commission, 2, MidpointRounding.AwayFromZero) * 2;
}
}
}
Replies
martin.myinvestments
29 Nov 2021, 12:16
RE:
amusleh said:
Hi,
The symbol commission is not available on Automate API, you can use Open API to get symbol commission.
Thank you, will try it out :)
@martin.myinvestments
amusleh
29 Nov 2021, 09:01
Hi,
The symbol commission is not available on Automate API, you can use Open API to get symbol commission.
@amusleh