Skip to content

CryptoFutureMarginModel

QuantConnect.Securities.CryptoFuture.CryptoFutureMarginModel

CryptoFutureMarginModel(leverage: float = 25)

Bases: SecurityMarginModel

The crypto future margin model which supports both Coin and USDT futures

Creates a new instance

Parameters:

Name Type Description Default
leverage float

The leverage to use, used on initial margin requirements, default 25x

25

NULL

NULL: IBuyingPowerModel = ...

Gets an implementation of IBuyingPowerModel that does not check for sufficient buying power

required_free_buying_power_percent

required_free_buying_power_percent: float

The percentage used to determine the required unused buying power for the account.

This codeEntityType is protected.

get_initial_margin_requirement

get_initial_margin_requirement(
    parameters: InitialMarginParameters,
) -> InitialMargin

The margin that must be held in order to increase the position by the provided quantity

Parameters:

Name Type Description Default
parameters InitialMarginParameters

An object containing the security and quantity of shares

required

Returns:

Type Description
InitialMargin

The initial margin required for the option (i.e. the equity required to enter a position for this option).

get_maintenance_margin

get_maintenance_margin(
    parameters: MaintenanceMarginParameters,
) -> MaintenanceMargin

Gets the margin currently alloted to the specified holding.

Parameters:

Name Type Description Default
parameters MaintenanceMarginParameters

An object containing the security

required

Returns:

Type Description
MaintenanceMargin

The maintenance margin required for the option.

get_margin_remaining

get_margin_remaining(
    portfolio: SecurityPortfolioManager,
    security: Security,
    direction: OrderDirection,
) -> float

Gets the margin cash available for a trade

This codeEntityType is protected.

Parameters:

Name Type Description Default
portfolio SecurityPortfolioManager

The algorithm's portfolio

required
security Security

The security to be traded

required
direction OrderDirection

The direction of the trade

required

Returns:

Type Description
float

The margin available for the trade.

get_total_collateral_amount

get_total_collateral_amount(
    portfolio: SecurityPortfolioManager,
    security: Security,
    primary_collateral: Cash,
) -> float

Gets the total collateral amount for the given crypto future position. The base implementation returns only the primary collateral amount. Override in subclasses to include supplementary collateral currencies.

This codeEntityType is protected.

Parameters:

Name Type Description Default
portfolio SecurityPortfolioManager

The algorithm's portfolio

required
security Security

The crypto future security

required
primary_collateral Cash

The primary collateral cash (e.g. USDT for non-coin futures, BTC for coin futures)

required

Returns:

Type Description
float

Total collateral amount in terms of the primary collateral currency.

shares_collateral

shares_collateral(
    portfolio: SecurityPortfolioManager,
    collateral_currency: Cash,
    other_crypto_future: Security,
) -> bool

Determines whether the given security shares collateral with another crypto future.

This codeEntityType is protected.

Parameters:

Name Type Description Default
portfolio SecurityPortfolioManager

The algorithm's portfolio

required
collateral_currency Cash

The collateral cash for the current security

required
other_crypto_future Security

The other crypto future security to check

required

Returns:

Type Description
bool

True if both securities share the same collateral.

get_buying_power

get_buying_power(
    parameters: BuyingPowerParameters,
) -> BuyingPower

Gets the buying power available for a trade

Parameters:

Name Type Description Default
parameters BuyingPowerParameters

A parameters object containing the algorithm's portfolio, security, and order direction

required

Returns:

Type Description
BuyingPower

The buying power available for the trade.

get_initial_margin_required_for_order

get_initial_margin_required_for_order(
    parameters: InitialMarginRequiredForOrderParameters,
) -> InitialMargin

Gets the total margin required to execute the specified order in units of the account currency including fees

Parameters:

Name Type Description Default
parameters InitialMarginRequiredForOrderParameters

An object containing the portfolio, the security and the order

required

Returns:

Type Description
InitialMargin

The total margin in terms of the currency quoted in the order.

get_leverage

get_leverage(security: Security) -> float

Gets the current leverage of the security

Parameters:

Name Type Description Default
security Security

The security to get leverage for

required

Returns:

Type Description
float

The current leverage in the security.

get_maximum_order_quantity_for_delta_buying_power

get_maximum_order_quantity_for_delta_buying_power(
    parameters: GetMaximumOrderQuantityForDeltaBuyingPowerParameters,
) -> GetMaximumOrderQuantityResult

Get the maximum market order quantity to obtain a delta in the buying power used by a security. The deltas sign defines the position side to apply it to, positive long, negative short.

Parameters:

Name Type Description Default
parameters GetMaximumOrderQuantityForDeltaBuyingPowerParameters

An object containing the portfolio, the security and the delta buying power

required

Returns:

Type Description
GetMaximumOrderQuantityResult

Returns the maximum allowed market order quantity and if zero, also the reason.

get_maximum_order_quantity_for_target_buying_power

get_maximum_order_quantity_for_target_buying_power(
    parameters: GetMaximumOrderQuantityForTargetBuyingPowerParameters,
) -> GetMaximumOrderQuantityResult

Get the maximum market order quantity to obtain a position with a given buying power percentage. Will not take into account free buying power.

Parameters:

Name Type Description Default
parameters GetMaximumOrderQuantityForTargetBuyingPowerParameters

An object containing the portfolio, the security and the target signed buying power percentage

required

Returns:

Type Description
GetMaximumOrderQuantityResult

Returns the maximum allowed market order quantity and if zero, also the reason.

get_reserved_buying_power_for_position

get_reserved_buying_power_for_position(
    parameters: ReservedBuyingPowerForPositionParameters,
) -> ReservedBuyingPowerForPosition

Gets the amount of buying power reserved to maintain the specified position

Parameters:

Name Type Description Default
parameters ReservedBuyingPowerForPositionParameters

A parameters object containing the security

required

Returns:

Type Description
ReservedBuyingPowerForPosition

The reserved buying power in account currency.

has_sufficient_buying_power_for_order

has_sufficient_buying_power_for_order(
    parameters: HasSufficientBuyingPowerForOrderParameters,
) -> HasSufficientBuyingPowerForOrderResult

Check if there is sufficient buying power to execute this order.

Parameters:

Name Type Description Default
parameters HasSufficientBuyingPowerForOrderParameters

An object containing the portfolio, the security and the order

required

Returns:

Type Description
HasSufficientBuyingPowerForOrderResult

Returns buying power information for an order.

set_leverage

set_leverage(security: Security, leverage: float) -> None

Sets the leverage for the applicable securities, i.e, equities

Parameters:

Name Type Description Default
security Security
required
leverage float

The new leverage

required

get_amount_to_order

get_amount_to_order(
    security: Security,
    target_margin: float,
    margin_for_one_unit: float,
    final_margin: Optional[float],
) -> Tuple[float, float]

Helper function that determines the amount to order to get to a given target safely. Meaning it will either be at or just below target always.

Parameters:

Name Type Description Default
security Security

Security we are to determine order size for

required
target_margin float

Target margin allocated

required
margin_for_one_unit float

Margin requirement for one unit; used in our initial order guess

required
final_margin Optional[float]

Output the final margin allocated to this security

required

Returns:

Type Description
Tuple[float, float]

The size of the order to get safely to our target.