AlgoTraderAlgoTrader Documentation

Chapter 13. Forex Handling

13.1. Currency Handling
13.1.1. Futures
13.1.2. Forex
13.1.3. Currency Attribution
13.2. Forex-Hedging
13.2.1. Virtual FX Positions (IB only)
13.2.2. FX Future

The System provides full Forex and Currency Exchange Management. FX Rates can be retrieved in real-time. All portfolio figures are calculated based on up-to-date FX-Rates.

FX conversion is provided through the MarketDataService. When subscribing for a non-base currency instrument the system will automatically subscribe the Forex instrument necessary to convert the non-base currency balance (e.g. realized PnL and market value) into the base currency. In some cases multiple Forex / Currency Pairs (based on the same base and transaction currency) are available in the system which are traded through different brokers / exchanges.

For those cases a special setting misc.defaultMarketFeeds defines the priority in which market feeds and exchanges are used. The default value is the following:

misc.defaultMarketFeeds = BMEX:CNG,OKEX:CNG,BINA:CNG,BITF:CNG,BTHM:CNG,HITB:CNG,GDAX:CNG,
BITMEX:CNP,OKEX:CNP,BINANCE:CNP,HUOBI:CNP,BITFINEX:CNP,BITHUMB:CNP,HITBTC:CNP,KRAKEN:CNP,
BINA:BNC,BITF:BFX,BITS:BTS,FLYR:BFL,BMEX:BMX,IDEALPRO:IB

This is a comma separated list of preferred <exchange>:<feedType>. Exchange code is taken from the database security.exchange_code value and feed type is ch.algotrader.enumeration.FeedType. Optional specific security pairs are also supported, using '@' symbol, e.g. 'BTCUSD@BITF:CNG'. When the platform needs to make a conversion for a given forex, it will iterate over this list and determine the first match. Match means all of the below:

To change the default settings the following property needs to be updated inside conf.properties. Alternatively the properties can be changed via Section 2.3, “VM Arguments”

# default exchanges/feed types to use for market data. <SYMBOL>@<EXCHANGE_CODE>:<FEED_TYPE>
-Dmisc.defaultMarketFeeds=IDEALPRO:IB

For example, -Dmisc.defaultMarketFeeds=BTCUSD@BITF:CNG,BITF:BFX means that for BTCUSD conversions Bitmex via Coinigy will be used, for all others direct Bitfinex connection will be used (assuming both Coinigy and Bitfinex adapters are running).

In most cases securities are attributed in their currency (as defined by SecurityFamily). Their market value is attributed towards Market Value.

There are however the following exceptions.

The system provides automatic Forex-Hedging by the Service ch.algotrader.service.ForexService. This service will maintain multiple FX Positions to hedge all non base currency balances. For actual Forex-Hedging the following two options exist