Plots

Introduction

In the Automated Trading System (ATS), you can monitor your trading activities through visual plots—currently, only time-series data is supported. These plots are consistent across both live-trading and back-testing modes.

The BaseExchange class manages plot data using the PlotData class. If you wish to configure custom plots, such as technical indicators, you can do so by utilizing the PlotData object within your exchange class (which extends BaseExchange). Adding custom plots to your strategy is straightforward because the exchange object is injected into the strategy object. You can access the PlotData object by calling get_plot_data() on the exchange object.

However, ATS also provides a default set of preconfigured plots at the BaseExchange level. This means you can generate basic plots immediately without any additional customization. The following is a list of available default plots:

Plot Name
Description

Candle Close Price

Time series of candle close price.

LIMIT Order Placed: Buy

A time series containing the locations of LIMIT Buy order placements.

LIMIT Order Placed: Sell

A time series containing the locations of LIMIT Sell order placements.

LIMIT Order Completed: Buy

A time series containing the locations of LIMIT Buy order fulfilments.

LIMIT Order Completed: Sell

A time series containing the locations of LIMIT Sell order fulfilments.

MARKET Order Completed: Buy

A time series containing the locations of MARKET Buy order placements.

MARKET Order Completed: Sell

A time series containing the locations of MARKET Sell order placements.

Order Canceled: Buy

A time series containing the locations of Buy order cancellations.

Order Canceled: Sell

time series containing the locations of Sell order cancellations.

Order Rejected: Buy

A time series containing the locations of Buy order rejections.

Order Rejected: Sell

A time series containing the locations of Sell order rejections.


Time Series Data Types

The PlotData class currently supports two types of time series data:

  1. Markers: Used for generating scatter plots. Each marker data point includes the following parameters:

    • topic: The topic associated with the marker.

    • time: The timestamp of the marker.

    • num: The numerical value of the marker.

    • label: A string label for the marker, such as an order ID or whether it is a buy or sell order. When hovering over the data point in the scatter plot, this label will be displayed.

  2. Lines: Used for creating continuous line chart time series plots. Each data point for a line plot includes the following parameters:

    • topic: The topic associated with the line.

    • time: The timestamp of the data point.

    • num: The numerical value of the data point within the line.


Plot Data Config Structure

The Plot Topics API allows you to configure the plots you wish to view and provides guidelines on how these plots are arranged. For example, you can define specific plots to be layered on top of one another or create subplots arranged in a grid view.

A plot configuration consists of an array of JSON objects that define the layout and details of each plot. The structure of a plot layout configuration JSON object is outlined below. Please note that these objects are wrapped within an array, allowing for multiple layout configurations. Even if there is only one element, it will still be contained within an array.

{
  "cols": 1,
  "rows": 2,
  "length": -1,
  "name": "Price Chart",
  "plot_compressed": true,
  "plot_compressed_size": 10000,
  "plots": [{...}, {...}]
}
Property
Description

cols

Number of columns in the layout

rows

Number of rows in the layout

length

Length of data to be plotted (last n time series data). Use -1 for plotting everything.

name

This is the plot name. It is just a title and is not related to plot names configured in the PlotData object within the Exchange or the Strategy objects.

plot_compressed

Boolean variable. If set to true, the plot is compressed into plot_compressed_size number of bins. As an example assume that you have a time series with 1000000 data. But due to your browsers memory requirements, you need to represent the plot in just 10000 points (low resolution plot). In that case, you can set this flag to true and compressed the plot data passed to the front end.

plots

plots parameter contains an array of plots. In each object, a plot is referred by its name and it also has a column number and a row number indicating where to place the plot. See the following examples to understand more about the configuration.

Below are some examples of different plot configurations (You will find the entire config in the JSON config file provided in Sample Trading Configs):

Creating a Price Chart Based on Closed Price

In this example, the plot configuration defines a plot arranged in a 1-column by 1-row layout, displaying all data points in the time series (with the length set to 1). The plot is titled "My Cool Price Chart" and is configured to be compressed into 10,000 bins. The layout places one plot in column 1, row 1, which represents the "Candle Close Price" time series.

[
  {
    "cols": 1,
    "rows": 1,
    "length": -1,
    "name": "My Cool Price Chart",
    "plot_compressed": true,
    "plot_compressed_size": 10000,
    "plots": [
      {
        "col": 1,
        "row": 1,
        "topic": "Candle Close Price"
      }
    ]
  }
]

This produces a chart similar to the following.

Plotting Order Locations on a Price Chart

In the following example, we are extending the plots in the same 1-column by 1-row layout but with scatter plots to show order locations, order fulfilments, order cancellations and order rejections.

To understand scatter plot marker shape and color configurations, please refer to Adding a New Plot section.

[
  {
    "cols": 1,
    "rows": 1,
    "length": -1,
    "name": "My Cool Price Chart",
    "plot_compressed": true,
    "plot_compressed_size": 10000,
    "plots": [
      {
        "col": 1,
        "row": 1,
        "topic": "Candle Close Price"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "LIMIT Order Placed: Buy"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "LIMIT Order Placed: Sell"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "LIMIT Order Completed: Buy"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "LIMIT Order Completed: Sell"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "MARKET Order Completed: Buy"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "MARKET Order Completed: Sell"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "Order Canceled: Buy"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "Order Canceled: Sell"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "Order Rejected: Buy"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "Order Rejected: Sell"
      }
    ]
  }
]

This configuration creates a plot similar to the following.

Plotting an Indicator on Below the Price Chart

In this example, we are expanding the previous configuration by create a 1-column by 2-row layout and placing the RSI indicator plot just below the price chart.

Note that the rows is set to 2 and at the end of the configuration, we have added the RSI index plot and placed it in column number 1 and row number 2.

[
  {
    "cols": 1,
    "rows": 2,
    "length": -1,
    "name": "Price Chart",
    "plot_compressed": true,
    "plot_compressed_size": 10000,
    "plots": [
      {
        "col": 1,
        "row": 1,
        "topic": "Candle Close Price"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "LIMIT Order Placed: Buy"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "LIMIT Order Placed: Sell"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "LIMIT Order Completed: Buy"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "LIMIT Order Completed: Sell"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "MARKET Order Completed: Buy"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "MARKET Order Completed: Sell"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "Order Canceled: Buy"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "Order Canceled: Sell"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "Order Rejected: Buy"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "Order Rejected: Sell"
      },
      {
        "col": 1,
        "row": 2,
        "topic": "RSI"
      }
    ]
  }
]

This is a sample plot layout generated by the above configuration.

Configuring Multiple Plot Layouts

In earlier sections, we covered how to configure a single layout. However, it's also possible to include multiple layout configurations within the same plot configuration JSON.

Refer to the plot configuration example provided in the Sample Trading Configs section to understand how to set up multiple plot configurations.

When multiple plot layouts are configured, the resulting plot view will appear as shown below.

Last updated