CFD Calculator Widget & API

This calculator was build according to MT4 / MT5 way of thinking, to answer MiFID regulation demands.
For the html widget, call the DOMAIN/fxcalc url. For the API version, call DOMAIN/fxcalc_json url.

Function Input

POST the following fields to the "fxcalc_json". Function is NOT Case Sensitive. Some of the values are index based (like html select field).
IF you do not understand something, run the html version of the calculator and view it's code. The API version is using the same field names and values.
Field Name Description
Platform This field has no meaning, and it is just for presentation. Default value = 0.
Account Currency Mandatory. The trader account currency. Possible values: EUR, USD, GBP, CAD, AUD, JPY.
Instrument Mandatory. Any symbol from TP servers.
Command Mandatory. Index based field. Possible values: 0=Buy; 1=Sell;
Volume Real world amount of asset (or currency). This field is Real number.
Examples: 100000 for EUR/USD; 5000 for CrudeOIL; 10 for Bitcoin...
IF you pass ZERO as value, then the function will set the basic contract size as volume !
Leverage Mandatory. String field. Possible values:
400:1   200:1   100:1   50:1   33:1   25:1   20:1   10:1   5:1   1:1
Open Price For any P&L calculation, the user should fill in the Open Price.
Close Price With this value (and Open Price), you will have 'Profit & Loss' calculated.
Stop Price With this value (and Open Price), you will have 'Stop Order profit & loss' calculated.
Limit Price With this value (and Open Price), you will have 'Limit Order profit & loss' calculated.
Open Date
Close Date
Fill-in both fields to calculate swap for specific period. otherwise 'Swap Days' will be ONE day. Field mask: YYYY-MM-DD
Hyper's api service is very flexible. You can use http POST or GET. You can use original field names with spaces or without ('Open Date' = 'opendate')

Function Output

As you can see on the example below, The function will return 2 objects in json format.
"InputFields" will contain the calculator input values, including default that were not passed by you.
"OutputFields" will contain the calculator result, as explained on the following table:
Field Name Description
Type 1=Currencies; 2=Commodities; 3=Shares; 4=Index; 5=Other; 6=Interest Based;
ContractSize The contract size in TP server.
ExposureSymbolA The asset you are buying in this contract.
ExposureSymbolB The currency you are using for buying the asset (which is SymbolA)
Bid
Last known BID & ASK from TP. Hyper is being updated every 45 seconds
Margin Calculated margin for this trade, according to Leverage & Volume. Result is in "Account Currency"
SpreadCost = Spread * Volume * Convertion (from SymbolB to AccountCurrency)
InstrumentSpreadPIPS = ASK - BID; the diffrence between prices.
SwapDays How many days are calculated now.
When using OpenDate and CloseDate, there is a meaning for Wednesday & Friday for calculating Weekend swap !
BuySwapsOvernightInterestCost = Long_Interest (for period) * Volume * Convertion (from SymbolB to AccountCurrency)
SellSwapsOvernightInterestCost = Short_Interest (for period) * Volume * Convertion (from SymbolB to AccountCurrency)
ProfitLoss = (ClosePrice - OpenPrice) * Volume * Convertion (from SymbolB to AccountCurrency)
StopOrderProfitLoss = (StopPrice - OpenPrice) * Volume * Convertion (from SymbolB to AccountCurrency)
LimitOrderProfitLoss = (LimitPrice - OpenPrice) * Volume * Convertion (from SymbolB to AccountCurrency)

Message Examples

Posted Http Form (GET or POST):
DOMAIN/fxcalc_json?Leverage=100:1&Instrument=CHFHUF&AccountCurrency=EUR&command=sell&opendate=2018-01-03

For successful running, the following message will be received:
{
  "Calculator_Success": "Yes",
  "OutputFields": {
    "Data": {
      "Type": "1",
      "ContractSize": "100000",
      "ExposureSymbolA": "CHF",
      "ExposureSymbolB": "HUF",
      "Bid": "263.64",
      "Ask": "264.07",
      "Margin": "851.52",
      "SpreadCost": "138.88",
      "InstrumentSpreadPIPS": "0.43000",
      "SwapDays": "10",
      "BuySwapsOvernightInterestCost": "-57.2114233",
      "SellSwapsOvernightInterestCost": "-14.4333129",
      "ProfitLoss": "0",
      "StopOrderProfitLoss": "0",
      "LimitOrderProfitLoss": "0"
    }
  },
  "InputFields": {
    "Data": {
      "Platform": "0",
      "AccountCurrency": "EUR",
      "Instrument": "CHFHUF",
      "Command": "1",
      "Volume": "100000",
      "Leverage": "100:1",
      "OpenPrice": "0",
      "ClosePrice": "0",
      "StopPrice": "0",
      "LimitPrice": "0",
      "OpenDate": "2018-01-03",
      "CloseDate": "2018-01-10"
    }
  }
}