Professional Documents
Culture Documents
BJF FIX API Trader Manual
BJF FIX API Trader Manual
BJF FIX API Trader Manual
Release notes
Version 1.7, November 2015
Contents
Revision history ................................................................................................................................................................. 3
Introduction ...................................................................................................................................................................... 4
1. Installation steps ........................................................................................................................................................... 5
2 Getting Started ............................................................................................................................................................... 8
2.1 Program interface ................................................................................................................................................... 8
2.2 Editing FIX Connection info. .................................................................................................................................... 8
2.3. Editing External Connection info .......................................................................................................................... 11
2.4 Connecting to FIX broker....................................................................................................................................... 12
2.5 Logging .................................................................................................................................................................. 13
2.6 Manual Trading ..................................................................................................................................................... 14
2.7 Book information .................................................................................................................................................. 14
3 Using FIX Trader with Metatrader 4 terminal .............................................................................................................. 15
3.1 Offline charts ......................................................................................................................................................... 15
3.2 Connecting MT4 to FIX trader ............................................................................................................................... 16
3.3 New order detection methods .............................................................................................................................. 17
3.4 Additional information .......................................................................................................................................... 19
3.5 Using EA on offline charts ..................................................................................................................................... 19
4. Socket Commands Format .......................................................................................................................................... 21
Revision history
Ver 1.7
1. Changed symbols Common Name format from b/q to bq (so now it will be EURUSD instead of EUR/USD).
All direct trading operations from MT4 should use symbol Common Name or will be ignored.
2. Added ability to get information about position, change position S/L and T/P and close the position.
3. Added ability to get all current pending orders.
4. INTEGRAL,CQG and MATCHTRADE fix support.
5. Expert advisors instead of scripts for FIX connection.
Ver 1.8.3
1.
2.
3.
Introduction
FIX Trader software developed by BJF Trading Group is a special tool that allows
traders to apply their favorite MT4 tools and EAs to work with FIX API market data
and trading sessions. For more details about FIX Trader project please visit
http://offers.fxpartner.net/mt4-fix-api-trading/.
1. Installation steps
1. Click Next.
2. Click Browse and select the directory for MT4 terminal that will be used for
sending signals and analyses. Then click Next.
3. Select the program folder where FIX Trader should be installed and click Next.
Important note: If you installing next instance of the program, please make sure you
install it on the same logic disk (C:\, D:\ etc.)
5. If you run the program immediately after setup is finished, leave Launch FIX
Trader checkbox checked. If you need to see manual leave View FIX Trader
Manual check box checked. Then click Finish.
2 Getting Started
2.1 Program interface
Important: To run the program, right click on desktop shortcut BJF FIX Trader and
select Run as administrator. The other methods of program start can make
application work unproperly.
The The FIX Trader program interface is shown on Fig.1:
Fig.1 . FIX Trader interface: 1 Connection Status panel; 2 Market Watch window; 3
Manual Trading panel; 4- Book information panel; 5- Logging tabcontrol.
2.2 Editing FIX Connection info.
To start using program, you need to edit your FIX connection parameters. You can do it
by click on menu item FIX Connection -> Edit. The window will appear(fig. 2):
10
Multiplier column. When the order is translated by socket connection from MT4 or
other homemade program, the value of lot for FIX order command will be multiplied by
this value. In Digits column is stored the information how much digits is supported by
your FIX provider for this particular symbol. If your FIX provider (like LMAX) requires
security ids for symbol, in SymbolId column you need to specify that special Symbol ID
or otherwise keep in this column just different values (like 1,2,3 etc. by default).
11
After you finished with FIX credentials, it is time to set up your External connection
parameters. You can do it by clicking menu item External Connection -> Edit. The next
dialog will appear (fig. 5):
12
for the same terminal, so keep this checkbox checked only for one program instance to
avoid file i/o conflicts. In the group Symbols Timeframes you can select what symbols
and what timeframes you need to store for offline charts. To add a timeframe, select it
from the combobox with timeframes list or type timeframe manually if you need custom
timeframes (like M2, H3 etc.) and then click Add-> button.
On tab Command socket options you need to specify the parameters that will be used
for interaction with external connections via socket (fig. 6). Command socket port is the
TCP port that FIX Trader program will use to receive trading commands commands(note:
should be different for each program instance). Events socket port is the TCP port that
program will use to send quotes, connection status and orders execution results (note:
should be different for each program instance). Open buy orders / Open sell orders
indicates if the current instance of the program is allowed to transfer buy / sell orders to
FIX provider.
Connection status panel (see fig.1) displays information about current connection state
of FIX Market Data, FIX Trading and Command Socket and Events Socket sessions.
13
To connect all the sessions, click on menu item FIX Connection -> Connect. If you have
provided the correct FIX credentials, FIX Market Data and Trading sessions should be
established in a couple of seconds and show Connected status. If during a long time
period status is still Disconnected, than you need to perform next steps:
1) Study input parameters for FIX very carefully to make sure you entered the same
values as provided by your broker.
2) If you are sure with 1, than check if your firewall is not blocking external connections
to server and port of your FIX provider.
3) Check if your VPS provider is not blocking your external connections to server and
port of your FIX provider
4) Contact your FIX provider and ask if the IP you are trying to connect from is
whitelisted.
5) If steps 1,2,3,4 are passed and you can telnet your FIX provider, please contact us at
support@iticsoftware.com for further assistance.
2.5 Logging
In the Logging tabcontrol (see fig. 1) has 5 tabs, that contains logs for different events.
Activity log tab contains information about general application performance (session
connection/disconnections, order submission, common errors etc.).
Market data log tab contains send/received messages via FIX market data session.
Trading log tab contains send/received messages via FIX order session.
NOTE: Heartbeat messages are not stored in logs for do not overload application
memory.
Socket connection log tab contains messages received/send by command socket
from/to MT4 terminal or other external connection.
Filled orders tab contains grid with the information about the orders that were filled by
FIX provider (Order Id, Order side, Order lots, Order symbol, price at what order was
filled and fill time).
You can extract the information from logs to text buffer or file. To select the lines you
need to extract, press Shift (to select consecutive lines ) or Ctrl (to select non
consecutive lines). To select all the lines, select first line in the log and press
14
Ctrl+Shift+End. Then right click on the log and select Copy if you want to copy selected
lines to buffer or Save if you want to save them to file.
2.6 Manual Trading
FIX Trader allows to submit orders manually and simple position control with Manual
Trading panel (see fig. 1).
To place the order manually, please select the symbol in Symbol combobox. Then please
select order type (for now only market orders are supported for manual trading). In Lots
field please specify the desired order value.
If you need position control, before placing the order, please check Algorithmic trading
checkbox. That will enable all necessary input fields.
In S/L field you need to specify initial stop loss distance (in pips) from the position
average fill price. To move s/l to breakeven price (if it is possible) click
In T/P field you need to specify take profit distance (in pips) from the position average
fill price. To move t/p to breakeven price (if it is possible) click
To enable trailing stops, you need to put values in Trailing Stop and Trailing Step fields.
A Trailing Stop trails (moves) a stop in your favor by a specific distance as long as the
market is moving in a favorable direction. Trailing Stop trail your stop by a fixed amount
of pips (Trailing Stop) as the market moves in your favor. This results in a slower trailing
stop that waits for a certain number of pips (Trailing Step) to be accrued before moving
that amount of pips. For example, lets say we had an initial -100 pip stop loss, that we
set to trail with a Trailing Step of 10 and Trailing Stop 50. Our stop will stay at -100 until
the price moves in our favor a full 10 pips. Once +10 pips of floating profit is reached on
the trade, our fixed-step stop would jump from -100 to -40. Our stop would then stay at
-40 until the price moved in our favor another 10 pips (then it will be set to -30).
In the Risk field please specify the balance percent you want to risk from your current
balance ( should be input in Account Balance field) and your initial S/L value.
2.7 Book information
FIX Trader allows to see full book information via Book Information panel (see fig. 1). To
enable full book display, select symbol in Symbol field and check Show books. The
maximum supported depth is 8 levels.
15
Once the FIX Trader connected to FIX providers server and MT4 parameters are
prescribed (see section 2.3 ), the FIX Trader starting to fill the information in files that
can be used to display offline charts. Despite the confusing word offline, that charts
can be used for online data representation and trading.
To start working the offline chart, please open your MT4 terminal and click menu item
File -> Open offline. You will see the next dialog (fig.7):
16
To connect MT4 to FIX Trader for transferring orders to FIX providers, put EA Fix
Commands Connector EA on the chart (fig.9). In script inputs, in
port_4_buy_commands/ port_4_sell_commands specify the port on which the running
instance of program is responsible for sending buy/sell orders. If you are using single
instance of the program, this ports should coincide. NewOrderDetectionMethod stands
for the method the new order in terminal will be detected: 0 for Automatic method
and 1 for Manual method (see section 3.3 for explanations).
To connect MT4 to FIX Trader to receive order execution reports and quotes, put EA Fix
Events Connector EA on the chart. In script inputs, in port_4_events specify the port on
which the running instance of program will send quotes and execution reports.
NOTE: For running the connector scripts, you need to select for chart you are planning
to run them on, the symbol that is not used for collecting market data from FIX (see
section 2.3).
17
There are two ways for script to detect the new order request appearance. For users,
that do not have source code (mq4 files) of the EA, only Automatic method is
acceptable. In this case the script will catch new order request from terminal as soon as
it appears in terminal info and transfer it to the FIX Trader (please note, that script
catches not order execution event but sending event).
With Manual method in the source code of the EA before OrderSend and OrderClose
commands should be inserted line of the code that creates new Global Variable with the
name that contains information about the orders. The template for the Global Variable
name is (see Table 1 for proper values):
SO_ClientOrderID_OrderSIde_OrderType_OrderLots_OrderSymbol_OrderStopPrice_Ord
erLimitPrice_OrderSlippage_OrderTTL
So, for example, to open new market order to sell 0.1 EURUSD you need to insert next
line before order send command:
GlobalVariableSet("SO_3819696185399_1_1_0.1_EURUSD,0);
To close that order, you need to insert next line before order close command:
GlobalVariableSet("SO_3819696186899_0_1_0.1_EURUSD,0);
18
To open the new limit order to sell 0.1 EURUSD at 1.42345 you need to insert next line
before order send command:
GlobalVariableSet("SO_3819696185399_1_2_0.1_EURUSD_0_1.42345_0_0,0);
To open the new stop order to buy 0.1 EURUSD at 1.42345 you need to insert next line
before order send command:
GlobalVariableSet("SO_3819696185399_0_3_0.1_EURUSD_1.42345_0_0_0,0);
NOTE: Do not delete the created global variables, they will be automatically deleted
from the script when the order command is transferred to FIX Trader.
NOTE: To generate unique ClientOrderId in MQL4 you need to use following code
construction:
MathSrand(GetTickCount());
string ClOrderId = IntegerToString(GetTickCount())+IntegerToString(MathRand());
Once the order is executed and transferred from FIX trader, the new global variable will
appear in format:
RO_ClOrderId_OrderSide_OrderType_OrderLots_OrderSymbol_OrderPrice_StopPrice_Li
mitPrice_OrderStatus_NewClOrderId
where ClOrderId coincides with the ClOrderId that was sent, OrderStatus can have 4
values: 1 filled; 2 opened; 3 rejected; 4 canceled, NewClOrderId new client
order Id for order modify command.
To Cancel existing pending order, create a global variable
CO_ClOrderId_OrderSide
To Modify existing pending order, create a global variable
MO_ClOrderId_OrderSide_OrderType_OrderLots_OrderSymbol_StopPrice_LimitPrice
The positions on symbols received from Fix Trader, are stored in the global variables in
format:
SETPOS_Symbol_AvgFillPrice_StopLoss_TakeProfit_OpenTime
19
The value of the global variable represents the position size (value is positive if the
position is long, and negative if the position is short). OpenTIme has aUnix Timestamp
format (integer number of seconds that have elapsed since 00:00:00 Coordinated
Universal Time (UTC), Thursday, 1 January 1970).
To request the position information, you need to create global variable in format:
GETPOS_Symbol_0_0_1
To modify the position, you need to create global variable in format:
GETPOS_Symbol_NewPositionStopLoss_NewPositionTakeProfit_2
To close the position, you need to create global variable in format:
GETPOS_Symbol_0_0_3
3.4 Additional information
Quotes for symbols are also stored in global variables with names
FIXTRADER_SymbolName_Side (Side can take the values BID and ASK). Available
volumes are stored in global variables with names FIXTRADER_SymbolName_VOLSide
(Side can take the values BID and ASK). Last tick times are stored in global variables with
names FIXTRADER_SymbolName_Side_TIME(global variable value is local PC UNIX
time). For the example of usage of global variables please see EA
The Market data Session status and Trading Session status are stored in global variables
Status_MarketData and Status_Trading (value 0 means disconnected and 1 means
connected).
FIX Broker name is stored in global variable FIXBROKER_BrokerName.
Symbol digits are stored in global variables DIGITS_SymbolName.
3.5 Using EA on offline charts
Before placing the EA on offline chart to start trading, please make sure automated
trading is allowed and Offline chart checkbox is unchecked (see section 3.1). For
testing you can use the EA NewBarCatcher, that will appear in your MT4 terminal after
program installation. It is very simple EA, its logic is the next: if there is no opened orders
(with particular magic number) on symbol on bar opening, it opens new sell order.
Otherwise, if the orders exists, it closes it. The source code of EA is available as
20
21
Description
Command type
Client order Id
Order request type
Required
Yes
Yes
Yes
Type
integer
string
integer
102
Order side
Yes
integer
103
104
105
106
107
108
Order symbol
Order lots
Order price
Order stoploss
Order takeprofit
Order status
Yes
Yes
No
No
No
No
string
double
double
double
double
integer
109
110
111
Tag
1
200
201
202
203
204
Order slippage
No
double
Order TTL
No
integer
New Client OrderId
No
string
Table 2. New quote event
Description
Command type
Symbol
BidPrice
AskPrice
BidVolume
AskVolume
Required
Yes
Yes
Yes
Yes
Yes
Yes
Type
integer
string
double
double
double
double
Allowed values
1
Unique value
1 market
2 limit
3 stop
0 buy
1 - sell
1 filled
2 opened
3 rejected
4 canceled
5 - replaced
22
Description
Command type
Session type
Required
Yes
Yes
Type
integer
integer
301
Session status
Yes
integer
Allowed values
3
0 market data
1 orders
0 disconnected
1 connected
Description
Command type
Information type
Required
Yes
Yes
Type
integer
integer
401
200
Information value
Symbol
Yes
No
String
String
Allowed values
4
1 Broker name
2 Instrument digits
Description
Command type
Client order Id
Order request type
Required
Yes
Yes
Yes
Type
Integer
string
integer
102
Order side
Yes
integer
103
104
105
106
107
112
Order symbol
Order lots
Order price
Order stoploss
Order takeprofit
Operation
Yes
Yes
No
No
No
Y
string
double
double
double
double
integer
Allowed values
5
Unique value
1 market
2 limit
3 stop
0 buy
1 - sell
1 cancel
2 - modify
23
Description
Command type
Position symbol
Position size
Required
Yes
Yes
Yes
Type
Integer
string
double
105
106
107
112
No
No
No
Yes
double
double
double
integer
113
114
Text message
Position open time
No
Yes
string
long integer
Allowed values
6
positive for long
negative for short
zero position closed
1 get info
2 modify
3 close
UNIX Timestamp
Description
Command type
Order type
Required
Yes
Yes
Type
Integer
Integer
103
112
Order symbol
Operation
Yes
Yes
string
integer
Allowed values
7
2 limit
3 stop
1 get info