API functions: Strategy

Portfolio123
Written by Portfolio123Last updated 17 days ago

Strategy Functions

strategy

This operation returns the data from the Summary, Current Holdings and Statistics tabs of a strategy or book.

strategy_copy (new)

Copy an existing strategy to a new strategy.

strategy_holdings

Get strategy holdings on a particular date (defaults to today).

strategy_rebalance

Get rebalance recommendations.

strategy_rebalance_commit

Commit rebalance transactions.

strategy_rerun

Rerun a strategy simulation

strategy_trading_system

Returns the trading system settings

strategy_trading_system_update

Updates the trading system settings

strategy_transactions

Get transaction history for a date or date range

strategy_transaction_import

Import transactions.

strategy_transaction_delete

Delete strategy transactions.

Book Functions

book_copy (new)

Copy an existing book to a new book.

book_rerun

Rerun a book simulation

book_trading_system_update

Live book trading system update

Book and Strategy Functions

strategy_info (new)

Retrieve basic strategy or book info by ID.

NOTE: Each function has an cost of 1 API credit.

strategy(id)

This operation returns the data from the following pages:

  • Summary

  • Statistics: Performance, Risk Measurements, Trading (except for simulated books)

Args:
    id: Existing strategy ID.

Returns:
    An object containing the strategy statistics.

strategy_copy(id, name, type)

Copy an existing strategy to a new strategy.

Copies a live or simulated strategy to a new live or simulated strategy. Note that live strategies are set to manual rebalance.

Args:
    id: Existing strategy ID.
    name: Name for the new strategy.
    type: Type of strategy to create. 
          Use "PTF" for a live strategy or "SIM" for simulated strategy.
Returns:
    An object containing the new strategy's id.

Examples:
    >>> client.strategy_copy(123, 'Sim copy', 'SIM')
    IdResult(id=12345)

book_copy(id, name, type)

Copy an existing strategy to a new strategy.

Copies a live or simulated book to a new live or simulated book. Copied live books are set to manual rebalance.

Args:
    id: Existing book ID.
    name: Name for the new book.
    type: Type of book to create. 
          Use "BOOK" for a live book or "BOOKSIM" for simulated book.

Returns:
    An object containing the new book's id.

Examples:
    >>> client.book_copy(123, 'Sim book copy', 'BOOKSIM')
    IdResult(id=12345)

strategy_holdings(id [, date])

Get the holdings for this strategy as of a single date (defaults to today).

Args:
    id: Existing strategy ID.
    date: "YYYY-MM-DD" or None

Returns:
    The holdings

strategy_info(id | name)

Retrieve basic strategy info by ID.

Args:
    id: Strategy ID.
    or
    name: Name of the strategy

Returns:
    An object containing the basic strategy info.

Examples:
    >>> client.strategy_info(id=123)
    StrategyInfoResult(strategyId=123, name='Strategy name')

strategy_rebalance(id, params)

Get rebalance recommendations for a strategy or book. To reject recommendation and get replacements, call the method again with the P123 ids to reject in the "reject" parameter. Book rebalance ignores op, pitMethod, and reject and returns a compatible payload, without ranks.

Args:
    id: Existing strategy ID.
    params: Rebalance params dictionary:
       {
       "pitMethod": 'Complete' | 'Prelim',
       "reject": [ int, int, ... ], # list of P123ID
       "figi": "Share Class" | "Country Composite"
       # Required for Dynamic Weight
       "op": "Rebal" | "Recon" | "ReconRebal",       
       "minRebalTran": 0 # Applies only to Books 
       }
)

strategy_rebalance_commit(id, params)

Commit rebalance transactions for a strategy or book. To get recommendations, call the strategy_rebalance() method. Omit op and ranks when using for Books.

Args:
  id: Existing strategy ID.
  params: Rebalance commit params dictionary:
  { 
    "op": <op from strategy_rebalance()>,
    "ranks": <ranks from strategy_rebalance()>,
    "trans": [
      { "p123Uid": 123, "action": "BUY", "price": 0.1, "shares": 0.1,
         "comm": 0.1, "slip": 0.1, "note": "string"}, 
      {...}
    ]
  }

IMPORTANT:

  • Edit "trans" with actual trading information. For example exclude transactions that were not filled or change the price, shares, commission and slippage.

  • To update the holding' s ranks you must call this function even if there are no transactions

strategy_rerun(id, params)

book_rerun(id, params)

Rerun a strategy or book simulation

Args:
  id: Existing strategy ID.
  params: dictionary of settings
Returns:
  

strategy_trading_system(id)

Retrieve a strategy trading system

Args:
  id: Existing strategy ID.
Returns:
  Strategy settings

strategy_trading_system_update(id, params)

Update a strategy trading system

Args:
  id: Existing strategy ID.
  params: dictionary of settings

book_trading_system_update(id, params)

Update a live boo trading system

Args:
  id: Existing live book ID.
  params: dictionary of settings

strategy_transactions(id, start, end [, to_pandas])

Get transaction history from a strategy for a date range.

Args:
  id: Existing strategy ID.
  start: "YYYY-MM-DD", 
  end: "YYYY-MM-DD", 
  to_pandas: False
Returns:
  List of transactions

strategy_transactions_import(id, data, content_type [, update_existing, make_rebal_dt_curr])

Import transactions into a strategy. When a transaction is imported in the past the dividends and splits are automatically computed unless they are provide in the list.

Args:
  id: Existing strategy ID.
  data: str | IO[str]
  content_type: "text/csv" | "text/tsv"
  update_existing: False,
  make_rebal_dt_curr: False

Data:

The transaction data parameter can be either passed in directly of via a file-like object (e.g. obtained via open).

  • Supported formats: CSV and TSV

  • Preferred Country will be used to resolve tickers that do not have a country suffix. If the ticker does not exist in the Preferred Country, then we will look for the best match (Primary first followed by Foreign Primary).

  • Type must be one of: BUY, SELL, COVER, SHORT, DIV, SPLIT, CASH

  • Price and commission are assumed to be in the same currency as the strategy.

  • Notes is optional.

Columns must be in this order (notes is optional): date, ticker, type, shares, price, commission, notes

Transaction Data Example

2025-04-28,IBM,BUY,100,123.45,1.0,Optional Note
2025-04-28,MSFT,SELL,200,123.45,1.0,Optional Note
2025-04-27,,CASH,,1000.0,,Starting Cash

strategy_transaction_delete(id, params)

Delete strategy transactions by transaction IDs.

Args:
  id: Existing strategy ID.
  items: [tranId,...] 

Go to:

Did this article help you solve your issue?

Portfolio123 - Help Center

© 2026 Portfolio123 - Help Center. All rights reserved.

Knowledge Base Software by Customerly