MarginOrderMixin#

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

Submit a margin trading order.

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

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

  • order_type (int) –

    An INT scalar indicating the order type. Available values include:

    • 0: Market order

    • 5: Limit 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. Available values include:

    • 1: Collateral purchase

    • 2: Collateral sale

    • 3: Margin purchase

    • 4: Short sale

    • 5: Direct repayment

    • 6: Sell for repayment

    • 7: Direct return of borrowed shares

    • 8: Buy for return of borrowed shares

  • label (str, optional) – A STRING scalar indicating the label assigned to the order for classification.

  • account_type (AccountType, optional) –

    The account type. Available values include:

    • SPOT: Cash account

    • STOCK: Stock account

    • FUTURES: Futures account

    • OPTION: Options account

final get_margin_secu_position(symbols=None)#

Query the collateral purchase position information.

Parameters:

symbols (List[str], optional) – A STRING vector indicating the list of stock symbols. If omitted, the function returns all collateral purchase positions.

Returns:

  • When the length of symbolList is 1, the function returns a dictionary.

  • When the length of symbolList is not 1, an error is raised.

  • When symbolList is omitted, the function returns a table.

The returned table’s structure is as follows:

Name

Description

symbol

Stock symbol.

lastDayLongPosition

Collateral purchase position quantity at the previous day’s close.

lastDayBuyValue

Collateral purchase value at the previous day’s close.

longPosition

Current collateral purchase position quantity.

buyValue

Current collateral purchase value.

todayBuyVolume

Collateral purchase traded quantity for the current day.

todayBuyValue

Collateral purchase traded value for the current day.

Return type:

Dictionary or Table

final get_margin_trading_position(symbols=None)#

Queries margin purchase position information.

Parameters:

symbols (List[str], optional) – A STRING vector indicating the list of stock symbols. If omitted, the function returns margin purchase positions for all stocks.

Returns:

  • When symbolList contains only one symbol, a dictionary is returned.

  • When symbolList contains more than one symbol, an error is raised.

  • When symbolList is omitted, a table is returned.

The returned table’s structure is as follows:

Field

Type

Description

symbol

STRING

Stock symbol

lastDayLongPosition

DECIMAL128(8)

Margin purchase position at previous day’s close

lastDayBuyValue

DECIMAL128(8)

Margin purchase amount at previous day’s close

lastDayMarginDebt

DECIMAL128(8)

Margin debt at previous day’s close

longPosition

DECIMAL128(8)

Current margin purchase position

buyValue

DECIMAL128(8)

Current margin purchase amount

todayBuyVolume

DECIMAL128(8)

Margin purchase traded volume today

todayBuyValue

DECIMAL128(8)

Margin purchase traded amount today

marginBuyProfit

DECIMAL128(8)

Profit or loss of margin purchase

financialFee

DECIMAL128(8)

Financing interest

Return type:

Dictionary or Table

final get_secu_lending_position(symbols=None)#

Query short sale positions.

Parameters:

symbols (List[str], optional) – A STRING vector indicating a list of stock symbols. If omitted, all short-sale positions will be returned by default.

Returns:

  • When the length of symbolList is 1, a dictionary is returned.

  • When the length of symbolList is not 1, an error is raised.

  • If symbolList is omitted, a table is returned.

The returned table’s structure is as follows:

Name

Description

symbol

The underlying stock symbol

lastDayShortPosition

Short-sale position at previous close

lastDayShortValue

Short-sale value at previous close

lastDaySecuLendingDebt

Short-sale debt at previous close

shortPosition

Current short-sale position

shortValue

Current short-sale value

todayShortVolume

Executed short-sale volume for the day

todayShortValue

Executed short-sale value for the day

secuLendingProfit

Profit or loss from short selling

secuLendingFee

Fees for short selling

Return type:

Dictionary or Table