Skip to content

CryptoFutureMarginModel - GetInitialMarginRequirement doesn't consider order type #7726

@fishstoryyy

Description

@fishstoryyy

Expected Behavior

GetInitialMarginRequirement calculates the margin required to open a position and in cases of a limit order, it should calculate the position value based on the limit price instead of the security's current price.

Actual Behavior

GetInitialMarginRequirement calculates the margin based on the security's latest price, which leads to inaccurate buying power calculation, especially when the order type is a limit order where the limit price is much lower than the current price. See here

var positionValue = security.Holdings.GetQuantityValue(quantity, security.Price);

Potential Solution

Maybe the InitialMarginParameters should take the orderticket as an input?

public class InitialMarginParameters
{
/// <summary>
/// Gets the security
/// </summary>
public Security Security { get; }
/// <summary>
/// Gets the quantity
/// </summary>
public decimal Quantity { get; }

Reproducing the Problem

N/A (can provide a failing limit order due to insufficient buying power due to this issue if needed, but the link to the implementation code explains the issue)

System Information

N/A

Checklist

  • I have completely filled out this template
  • I have confirmed that this issue exists on the current master branch
  • I have confirmed that this is not a duplicate issue by searching issues
  • I have provided detailed steps to reproduce the issue

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions