Automated trading platform for C# developers Automatic trading platform developed in C# language.
Allows to develop market robots for any financial instrument

How does it work?

In this page we will have an overview of the way MKR Platform works. Following, we show a diagram to understand in a global view how the platform interacts with other elements. After the diagram will explain every element of it


Architecture of Market Robots engine

There are different ways to explain this diagram. We will start by the origin of the information. There are also different ways to use MKR trading platform, so for this example will use the case of running an automatic trading bot in real time. We suppose that the user already have connected to the trading platform and started running the bot on a real or paper trading account of IBKR platform

  1. IBKR terminal, aka TWS (Trader Work Station) queries quotes from the global exchange, in this example, the Chicago Mercantile Exchange CME, which is a reliable and regulated financial markets exchange. Information of the quotes of the selected instrument we chose for trading is sent to the data farms of IBKR, and from there to our computer, which is running the TWS Terminal.
  2. At the same time, Market Robots (MKR) terminal instance is running is our computer (not necessary has to be the same computer). MKR uses the Socket API from IBKR. It means both terminals communicate by the TCP/IP protocol, which allows them to communicate over public networks, private networks or in the same computer, which is the most common case.
  3. Now that the information of a new quote is on the MKR platform instance, the event "QuoteUpdate" will be fired. This event is fired every time a new quote has arrived to the platform, this covers a candle value update or a new candle arrival. 
  4. Every robot has to implement the QuoteUpdate event, so every time this event is fired, the code programmed in the robot will be executed. Robots analyze the data provided on the last quote and previous ones, besides information in the indicators and portfolio. The robot will make necessary calculations with the final objective to determine:
    1. If a new order must be sent to the terminal. Order can be used to open a new position, close an existing position, or both at the same time
    2. Calculate the parameters of the new order, if it's the case
    3. Optionally update internal variables of the robot
  5. When a robot creates and sends a new order, it calls the functions of an interface, called "TerminalBase". Depending on the terminal we connected (in this case is TWS, but could be another one like MetaTrader4), order will be sent to the instantiated terminal. Developer of Robots doesn't have to mind about the details of the terminal, as robot is programmed to run on any terminal with the same code.
  6. The details of the connection to the terminal are implemented in the source code of the specific terminal, which implements the interface called "TerminalBase". In this example, the order will be actually sent to TWS using IBKR sockets API. Before starting the automatic trading, the user is connected to the TWS using the platform.
  7. Once the order is sent to the terminal, the order will be live in the trading account. If it's a limit order, it will be in "open" state until filled. If it's a market order, it will be filled in matter of seconds. In any case, we will receive a confirmation of the execution via another event (OnExecution)
  8. Terminal exposes "OnExecution" event, so the robot can use this event to run any code according to its purpose. 
  9. Robot also can access the portfolio of the terminal to get how many "futures" or "stocks" has of the current trading instrument.
  10. MKR Platform can show/update the chart of the current session, so user or developer can check in real time what's going on with the operations. On the chart, these elements will be visualized:
    1. Quotes of selected instrument, in form of the well-known Japanese candles. User can move throw time using mouse or keyboard. User can also adapt zoom level or move chart vertically
    2. Indicators: Developer can program his own indicators on an easy way. They can be added to the chart at any time. Robots can also add and use indicators. Once indicators are added, user or robots can set visibility on/off
    3. Signals: In some situations, robots want to alert the user of some event, but it does not have to imply a new order. In this case, robot can use signals in the chart. Signals include a text description, a color and a shape. They point to a specific candle of the chart
    4. Orders: As in any trading platform, executed or open orders will be displayed in the chart. Robots can attach a text to the order, which will be also displayed on the chart and orders record. This is useful, for example, if a robot implements different strategies, the user may want to know which strategy triggered every order in the chart. If an order implies closing a position, the profit or loss will be also drawn in the chart or red or green color.
  11. MKR Platform hides all the details of connection to the trading terminal, for example:
    1. Will fire the OnQuote event every time a quote is updated or inserted, so the robot can run its program
    2. Will handle the order execution event to keep the portfolio updated. So the robot can also fire its code in the event and anytime can query the portfolio
    3. Will keep the chart updated. It will be available to the user or robot all the time. And also can be used to send reports via email or save the chart on the hard disk drive.
    4. If connection to the terminal is lost, MKR will try to connect again after some minutes to keep the robot working without need for human intervention.
    5. MKR will automatically update the values of all the indicators attached to the chart. Indicators can be set by the user or by the robot. Indicators are always visible by the robot, even if they are hidden in the chart

We already have seen the normal flow of a robot running in real time, getting quotes and making orders. But there are some parts of the diagram still unexplored:

On the right side of the diagram, we can see some entities of the database
  1. Robot parameters: Every robot can have an unlimited number of parameters. Parameters values are always a decimal or integer number. Better to understand what a parameter is with some examples:  -"take profit percentage",  "stop loss percentage" "maximum minutes in market"... In most cases, values of parameters are different on every instrument, so a group of parameters are always attached to the selected instrument. Developer can also set different groups of parameters and save each one with a given name. Before starting trading with a selected robot, the user has to select the group of parameters to use. As parameters can be optimized. It's possible to get different values of parameters on different periods of optimization. User may want to store, for example, optimized parameters for the whole year, optimized parameters for last 6 months, etc
  2. Orders: Executed orders are stored in database. An order may come from different sources, for example: real time manual trading, real time automatic trading, simulated trading etc. The purpose of storing orders in database is for future querying, analyze and make statistics from them. Having all orders stored, allows the platform to generate basic statics of trading and also generate the net liquidity over time chart.
  3. Quotes: Quotes can be downloaded from the TWS, but there are limits of the amount of quotes and sometimes it can be a slow process, so it's not convenient to get the quotes from TWS every time we want to make a backtesting/simulation. Query quotes from our own database is the most convenient and fast way to do it. MKR Platform can use the quotes to draw charts and do backtesting
  4. Instruments:  As in any other platform, we store all the instruments available for trading, including future contracts, stocks, etc.
  5. Financial information:  TWS API offer methods to query financial information from stocks. These are some examples of information we can get from any stock:
    1. Total revenues record, for every quarter of year, or trailing twelve months
    2. Earnings per share records
    3. Net Income available to common 
    4. Price to sales ratio TTM
    5. Dividends per share
    6. Cash flow per share
    7. Shares Outstanding
    8. Market capital
    9. Dividend dates and records
    10. Expert analysts mean consensus
  6. News: news can be query by API services or be scrapped from public websites. Once stored in the database, can be query by date and time to get the most relevant for trading.


Market Robots ®2024