fix: populate Tick.Exchange on streaming Alpaca ticks#57
Merged
Romazes merged 6 commits intoApr 22, 2026
Merged
Conversation
- add alpaca exchange code dictionaries in AlpacaBrokerageExtensions - use TryGetExchange in trade/quote handlers to set Tick.Exchange
3 tasks
- map Alpaca SIP exchange code via Exchanges.GetPrimaryExchange with hard-coded fallbacks (H, S, U, V) - drop SaleCondition assignment; Alpaca codes are tape-specific and not valid hex for ParsedSaleCondition (tracked in QuantConnect#62)
- convert GetExchange into a string extension taking SecurityType - delegate to Lean's GetPrimaryExchange(SecurityType), drop S/V hard-codes - map "E" (Market Independent) explicitly to Exchange.UNKNOWN
4 tasks
- drop H/U mappings, delegate to GetPrimaryExchange for remaining codes
- call GetPrimaryExchange(SecurityType).Name directly at tick sites - remove now-redundant GetExchange wrapper
Contributor
Author
|
Thanks for cranking this out, @Romazes ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Populate
Tick.Exchangeon streaming trade and quote ticks from the Alpaca SIP feed by mapping the single-letter SIP exchange code to a LeanExchangename.Related PR(s)
Depends on Lean PR #9422 (adds equity-tape mappings for
S,T,V,H,UtoExchanges.GetPrimaryExchange). Without it, those Alpaca SIP codes fall through toExchange.UNKNOWNhere (andTis conflated withNASDAQ).Related Issue
Sale-condition follow-up: #62.
Motivation and Context
Alpaca's SDK exposes the SIP exchange tag on every trade/quote, but
HandleTradeReceived/HandleQuoteReceivedwere dropping it. Without the venue, microstructure strategies cannot distinguish lit exchange prints from off-exchange (FINRA/ADF) prints or compute venue-aware volume profiles.Implementation
At the two tick construction sites in
AlpacaBrokerage.Messaging.cs, setTick.Exchangedirectly from the SIP code via Lean'sGetPrimaryExchange(SecurityType).Name:Codes with no Lean counterpart resolve to
Exchange.UNKNOWN.Name(empty string), which matchesTick.Exchange's default.The Alpaca Exchange codes: doc
ExchangeenumAA,AMEXExchange.AMEXBB,NASDAQ BX,NASDAQ_BXExchange.NASDAQ_BXCC,NSX,NSEExchange.NSX(US market)DD,FINRAExchange.FINRAEHHExchange.MIAX_PEARLII,ISEExchange.ISEJJ,EDGAExchange.EDGAKK,EDGXExchange.EDGXLL,LTSEExchange.LTSEMM,CSEExchange.CSENN,NYSEExchange.NYSEPP,ARCAExchange.ARCAQQ,T,NASDAQ,NASDAQ_OMXExchange.NASDAQSS,NASDAQ_SCExchange.NASDAQ_SCTT,NASDAQ_INTExchange.NASDAQ_INTUU,MM,MEMXExchange.MEMXVIEXExchange.IEXWW,CBOEExchange.CBOEXX,NASDAQ PSX,NASDAQ_PSXExchange.NASDAQ_PSXYY,BYX,BATS Y,BATS_YExchange.BATS_YZZ,BATS,BATS Z,BATS_ZExchange.BATSTick.SaleConditionis intentionally not populated. Alpaca's SIP conditions are tape-specific single-character codes ("@","I","T"), not a hexuint, soTick.ParsedSaleConditionwould throwFormatException. A tape-aware decoder that folds Alpaca codes into Lean'sTradeConditionFlags/QuoteConditionFlagsis tracked in #62.Requires Documentation Change
N/A
How Has This Been Tested?
Live streaming test with Alpaca SIP (Algo Trader Plus) subscription via LEAN from source.
Types of changes
Checklist:
bug-<issue#>-<description>orfeature-<issue#>-<description>