Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Common/Orders/TerminalLinkOrderProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,26 @@ public class TerminalLinkOrderProperties : OrderProperties
/// </summary>
public string Broker { get; set; }

/// <summary>
/// Whether a locate has been obtained for a short sale. When true, EMSX is told a locate is
/// attached to the order (EMSX_LOCATE_REQ = "Y"). Required by Reg SHO for short sales of
/// US equities. Defaults to false; leave alone for buys/sells where no locate is needed.
/// </summary>
public bool LocateRequired { get; set; }

/// <summary>
/// The EMSX locate broker code identifying the counterparty the shares are being borrowed
/// from for a short sale (EMSX_LOCATE_BROKER, e.g. "BMTB"). Maps to the LocBrkr field on
/// the EMSX trading ticket.
/// </summary>
public string LocateBroker { get; set; }

/// <summary>
/// The EMSX locate confirmation/ticket id returned by the lending broker (EMSX_LOCATE_ID).
/// Maps to the LocId field on the EMSX trading ticket.
/// </summary>
public string LocateId { get; set; }

/// <summary>
/// The EMSX order strategy details.
/// Strategy parameters must be appended in the correct order as expected by EMSX.
Expand Down
38 changes: 38 additions & 0 deletions Tests/Common/Orders/TerminalLinkOrderPropertiesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,43 @@ def getOrderProperties() -> TerminalLinkOrderProperties:
Assert.IsNull(orderProperties.Strategy.Fields[3].Value);
}
}

[Test]
public void LocateFieldsDefaultToEmpty()
{
// Locate fields are only meaningful for Reg SHO short equity sales; for any other
// order they must be unset so the brokerage doesn't emit EMSX_LOCATE_* on the request.
var properties = new TerminalLinkOrderProperties();
Assert.IsFalse(properties.LocateRequired);
Assert.IsNull(properties.LocateBroker);
Assert.IsNull(properties.LocateId);
}

[Test]
public void SetsLocateFieldsFromPython()
{
using (Py.GIL())
{
var module = PyModule.FromString("locateFieldsModule",
@"
from AlgorithmImports import *

def getOrderProperties() -> TerminalLinkOrderProperties:
properties = TerminalLinkOrderProperties()
properties.LocateRequired = True
properties.LocateBroker = ""BMTB""
properties.LocateId = ""LOC-123""
return properties
");

dynamic getOrderProperties = module.GetAttr("getOrderProperties");
var properties = (TerminalLinkOrderProperties)getOrderProperties();

Assert.IsNotNull(properties);
Assert.IsTrue(properties.LocateRequired);
Assert.AreEqual("BMTB", properties.LocateBroker);
Assert.AreEqual("LOC-123", properties.LocateId);
}
}
}
}
Loading