StockOrderMixin#

class swordfish.plugins.backtest.StockOrderMixin#
final submit_stock_order(code, time, order_type, order_price, quantity, direct, /, label=None, account_type=AccountType.DEFAULT)#

Submit a stock order.

Parameters:
  • code (str) – A STRING scalar indicating the stock code.

  • time (Timestamp) – A TIMESTAMP scalar indicating the order timestamp.

  • order_type (int) –

    An INT scalar indicating the order type. Available values:

    • Shanghai Stock Exchange:

      • 0: best five levels immediate or cancel (IOC).

      • 1: best five levels immediate-or-convert-to-limit.

      • 2: best price on own side.

      • 3: best price on counterparty side.

      • 5: Limit order.

      • 6: Cancel order.

    • Shenzhen Stock Exchange:

      • 0: best five levels immediate or cancel (IOC).

      • 1: immediate or cancel (IOC).

      • 2: best price on own side.

      • 3: best price on counterparty side.

      • 4: fill or kill (FOK).

      • 5: Limit order.

      • 6: Cancel order.

  • order_price (float) – A FLOAT scalar indicating the order price.

  • quantity (int) – An INT scalar indicating the order quantity.

  • direct (int) –

    An INT scalar indicating the trade direction. Optional values:

    • 1: Buy open

    • 2: Sell open

    • 3: Sell close

    • 4: Buy close

  • label (str, optional) – A STRING scalar indicating the tag for categorizing the order.

  • account_type (AccountType, optional) –

    Account type. Optional values:

    • SPOT: Cash account

    • STOCK: Stock account

    • FUTURES: Futures account

    • OPTION: Options account

final get_today_pnl(symbol)#

This interface is applicable only to stocks and is used to retrieve account profit and loss (P&L).

Parameters:

symbol (str) – A STRING scalar, representing the stock symbol.

Returns:

A dictionary with the following structure:

Key

Description

symbol

Security code

pnl

Profit or loss amount of the specified security in the current account

todayPnl

Profit or loss amount of the specified security for the current trading day

Return type:

Dictionary

property stock_total_portfolios#

Retrieve the current equity metrics of the stock strategy.

Returns:

A dictionary with the following key-value pairs:

  • tradeDate: The date

  • cash: Available cash

  • totalMarketValue: Total market value of the account

  • totalEquity: Total equity of the account

  • netValue: Net value per unit of the account

  • totalReturn: Cumulative return up to the current day

  • ratio: Daily return of the account

  • pnl: Profit and loss of the account for the current day

Return type:

Dictionary