Introduction
Automation Platform
Botmain DAO
Building Trading Strategies
API References Dev Live Stream
@botmain/common / Class

Position

Botmain has an internal position calculation engine to provide information about size, PnL and other position characteristics by each instrument and/or portfolio. Position information is available on three levels:

  • Individual instrument position takes into account executions of all orders issued by the strategy for the given instrument, even if the orders are issued for different portfolios
  • Portfolio position represents the accumulated position of the strategy defined portfolio. It takes into account executions of all orders issued by the strategy for the given portfolio and calculates the total portfolio characteristics. Not all position characteristics are available for a portfolio position, as they do not always make sense in this context.
  • Position by an instrument inside a portfolio is an individual instrument position and is calculated by the execution of orders issued for the given symbol and for the given portfolio only.

Properties

NameTypeDescription
averageCost
number

Average cost per unit spent to open this position. This is a non-negative number. For portfolio positions this property does not make sense and is undefined

cost
number

The sum of all money spent to open this position. It is positive for long positions and negative for short ones. For portfolio positions, it is the sum of cost of all instrument positions in the portfolio

instrument
string

This is the instrument for an individual instrument position, or the portfolio name in case of a portfolio position

isPortfolioPosition
boolean

Indicates whether this is a portfolio position

marketPrice
number

The last price used to calculate a position. For portfolio positions this property does not make sense and is undefined

marketValue
number

The market value of the position. Positive for long position, and negative for a short one. A portfolio position's marketValue is the sum of the marketValue of all instrument positions in the portfolio

realizedPnL
number

This is the PnL of the closed part of the position. It is positive in case of profit and negative for loss. For portfolio positions, it is the sum of realizedPnL of all instrument positions in the portfolio

size
number

The current size of the position. Positive for long position, and negative for short positions. For portfolio positions this property does not make sense and is undefined

timestamp
number

The timstamp of the last position update. It changes on every new market data when the position is recalculated

unrealizedPnL
number

This is the PnL of the open part of the position for the position's marketPrice. It is positive in case of profit and negative for loss. For portfolio positions, it is the sum of unrealizedPnL of all instrument positions in the portfolio