From 09174069937e147ec3b67c4dc54a9468c2a463ea Mon Sep 17 00:00:00 2001 From: Alexandre Catarino Date: Wed, 27 May 2026 16:03:39 +0100 Subject: [PATCH] Add EMSX locate properties to TerminalLinkOrderProperties Add LocateBroker (string) and LocateId (string) so algorithms can attach Reg SHO locate information to short equity sales routed through Bloomberg EMSX. These map to the EMSX_LOCATE_BROKER and EMSX_LOCATE_ID fields on the EMSX order ticket (LocBrkr / LocId). The TerminalLink brokerage emits EMSX_LOCATE_REQ = "Y" automatically whenever either identifier is set on a short equity sale, so no separate "required" flag is exposed here. Without these properties the TerminalLink brokerage has no way to identify the lender on a short sale, and prime brokers reject the order. Co-Authored-By: Claude Opus 4.7 (1M context) --- Common/Orders/TerminalLinkOrderProperties.cs | 14 ++++++++ .../TerminalLinkOrderPropertiesTests.cs | 35 +++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/Common/Orders/TerminalLinkOrderProperties.cs b/Common/Orders/TerminalLinkOrderProperties.cs index 44b9a43105b6..333133dc0fa0 100644 --- a/Common/Orders/TerminalLinkOrderProperties.cs +++ b/Common/Orders/TerminalLinkOrderProperties.cs @@ -74,6 +74,20 @@ public class TerminalLinkOrderProperties : OrderProperties /// public string Broker { get; set; } + /// + /// 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. Setting this (or ) on a short equity sale + /// causes the brokerage to emit EMSX_LOCATE_REQ = "Y" alongside. + /// + public string LocateBroker { get; set; } + + /// + /// The EMSX locate confirmation/ticket id returned by the lending broker (EMSX_LOCATE_ID). + /// Maps to the LocId field on the EMSX trading ticket. + /// + public string LocateId { get; set; } + /// /// The EMSX order strategy details. /// Strategy parameters must be appended in the correct order as expected by EMSX. diff --git a/Tests/Common/Orders/TerminalLinkOrderPropertiesTests.cs b/Tests/Common/Orders/TerminalLinkOrderPropertiesTests.cs index 034e5b846559..df86a02882d1 100644 --- a/Tests/Common/Orders/TerminalLinkOrderPropertiesTests.cs +++ b/Tests/Common/Orders/TerminalLinkOrderPropertiesTests.cs @@ -65,5 +65,40 @@ 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.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.LocateBroker = ""BMTB"" + properties.LocateId = ""LOC-123"" + return properties +"); + + dynamic getOrderProperties = module.GetAttr("getOrderProperties"); + var properties = (TerminalLinkOrderProperties)getOrderProperties(); + + Assert.IsNotNull(properties); + Assert.AreEqual("BMTB", properties.LocateBroker); + Assert.AreEqual("LOC-123", properties.LocateId); + } + } } }