class TradeStatusMessage(BasicMessageType): name = 'Trade Status Message' timestamp = Field(name='Timestamp', offset=0, length=8, data_type=Numeric(length=8)) message_type = Field(name='Message Type', offset=8, length=1, data_type=SingleCharacter(character='H')) stock_symbol = Field(name='Stock Symbol', offset=9, length=8, data_type=Alpha(length=8)) halt_status = Field(name='Halt Status', offset=17, length=1, data_type=Alpha(length=1)) reg_sho_action = Field(name='Reg SHO Action', offset=18, length=1, data_type=Numeric(length=1)) reserved_1 = Field(name='Reserved1', offset=19, length=1, data_type=Alpha(length=1)) reserved_2 = Field(name='Reserved2', offset=20, length=1, data_type=Alpha(length=1)) fields = [ timestamp, message_type, stock_symbol, halt_status, reg_sho_action, reserved_1, reserved_2 ]
def test_message(self): descriptions = [ { self.OFFSET: 0, self.LENGTH: 8, self.DATA_TYPE: Numeric(length=8), }, { self.OFFSET: 8, self.LENGTH: 1, self.DATA_TYPE: SingleCharacter(character='J'), }, { self.OFFSET: 9, self.LENGTH: 8, self.DATA_TYPE: Alpha(length=8), }, { self.OFFSET: 17, self.LENGTH: 1, self.DATA_TYPE: Alpha(length=1), }, { self.OFFSET: 18, self.LENGTH: 10, self.DATA_TYPE: Numeric(length=10), }, { self.OFFSET: 28, self.LENGTH: 10, self.DATA_TYPE: Numeric(length=10), }, ] self._test_message_type(AuctionSummaryMessage, descriptions)
class AuctionSummaryMessage(BasicMessageType): name = 'Auction Summary Message' timestamp = Field(name='Timestamp', offset=0, length=8, data_type=Numeric(length=8)) message_type = Field(name='Message Type', offset=8, length=1, data_type=SingleCharacter(character='J')) stock_symbol = Field(name='Stock Symbol', offset=9, length=8, data_type=Alpha(length=8)) auction_type = Field(name='Auction Type', offset=17, length=1, data_type=Alpha(length=1)) price = Field(name='Price', offset=18, length=10, data_type=Numeric(length=10)) shares = Field(name='Shares', offset=28, length=10, data_type=Numeric(length=10)) fields = [ timestamp, message_type, stock_symbol, auction_type, price, shares ]
def test_symbol_clear_message(self): descriptions = [ { self.OFFSET: 0, self.LENGTH: 8, self.DATA_TYPE: Numeric(length=8), }, { self.OFFSET: 8, self.LENGTH: 1, self.DATA_TYPE: SingleCharacter(character='d'), }, { self.OFFSET: 9, self.LENGTH: 12, self.DATA_TYPE: Base36Numeric(length=12), }, { self.OFFSET: 21, self.LENGTH: 1, self.DATA_TYPE: Alpha(length=1), }, { self.OFFSET: 22, self.LENGTH: 6, self.DATA_TYPE: Numeric(length=6), }, { self.OFFSET: 28, self.LENGTH: 8, self.DATA_TYPE: Alpha(length=8), }, { self.OFFSET: 36, self.LENGTH: 10, self.DATA_TYPE: Numeric(length=10), }, { self.OFFSET: 46, self.LENGTH: 1, self.DATA_TYPE: Alpha(length=1), }, { self.OFFSET: 47, self.LENGTH: 4, self.DATA_TYPE: Alpha(length=4), }, ] self._test_message_type(AddOrderMessageLong, descriptions)
def test_message(self): descriptions = [ { self.OFFSET: 0, self.LENGTH: 8, self.DATA_TYPE: Numeric(length=8), }, { self.OFFSET: 8, self.LENGTH: 1, self.DATA_TYPE: SingleCharacter(character='P'), }, { self.OFFSET: 9, self.LENGTH: 12, self.DATA_TYPE: Base36Numeric(length=12), }, { self.OFFSET: 21, self.LENGTH: 1, self.DATA_TYPE: Alpha(length=1), }, { self.OFFSET: 22, self.LENGTH: 6, self.DATA_TYPE: Numeric(length=6), }, { self.OFFSET: 28, self.LENGTH: 6, self.DATA_TYPE: Alpha(length=6), }, { self.OFFSET: 34, self.LENGTH: 10, self.DATA_TYPE: Numeric(length=10), }, { self.OFFSET: 44, self.LENGTH: 12, self.DATA_TYPE: Base36Numeric(length=12), }, ] self._test_message_type(TradeMessage, descriptions)
class AddOrderMessageLong(BasicMessageType): name = 'Add Order Message Long' timestamp = Field(name='Timestamp', offset=0, length=8, data_type=Numeric(length=8)) message_type = Field(name='Message Type', offset=8, length=1, data_type=SingleCharacter(character='d')) order_id = Field(name='Order ID', offset=9, length=12, data_type=Base36Numeric(length=12)) side_indicator = Field(name='Side Indicator', offset=21, length=1, data_type=Alpha(length=1)) shares = Field(name='Shares', offset=22, length=6, data_type=Numeric(length=6)) stock_symbol = Field(name='Stock Symbol', offset=28, length=8, data_type=Alpha(length=8)) price = Field(name='Price', offset=36, length=10, data_type=Numeric(length=10)) display = Field(name='Display', offset=46, length=1, data_type=Alpha(length=1)) participant_id = Field(name='Participant ID', offset=47, length=4, data_type=Alpha(length=4)) fields = [ timestamp, message_type, order_id, side_indicator, shares, stock_symbol, price, display, participant_id ]
class TradeMessage(BasicMessageType): name = 'Trade Message' timestamp = Field(name='Timestamp', offset=0, length=8, data_type=Numeric(length=8)) message_type = Field(name='Message Type', offset=8, length=1, data_type=SingleCharacter(character='P')) order_id = Field(name='Order ID', offset=9, length=12, data_type=Base36Numeric(length=12)) side_indicator = Field(name='Side Indicator', offset=21, length=1, data_type=Alpha(length=1)) shares = Field(name='Shares', offset=22, length=6, data_type=Numeric(length=6)) stock_symbol = Field(name='Stock Symbol', offset=28, length=6, data_type=Alpha(length=6)) price = Field(name='Price', offset=34, length=10, data_type=Numeric(length=10)) execution_id = Field(name='Execution ID', offset=44, length=12, data_type=Base36Numeric(length=12)) fields = [timestamp, message_type, order_id, side_indicator, shares, stock_symbol, price, execution_id]
class AuctionUpdateMessage(BasicMessageType): name = 'Auction Update Message' timestamp = Field(name='Timestamp', offset=0, length=8, data_type=Numeric(length=8)) message_type = Field(name='Message Type', offset=8, length=1, data_type=SingleCharacter(character='I')) stock_symbol = Field(name='Stock Symbol', offset=9, length=8, data_type=Alpha(length=8)) auction_type = Field(name='Auction Type', offset=17, length=1, data_type=Alpha(length=1)) reference_price = Field(name='Reference Price', offset=18, length=10, data_type=Numeric(length=10)) buy_shares = Field(name='Buy Shares', offset=28, length=10, data_type=Numeric(length=10)) sell_shares = Field(name='Sell Shares', offset=38, length=10, data_type=Numeric(length=10)) indicative_price = Field(name='Indicative Price', offset=48, length=10, data_type=Numeric(length=10)) auction_only_price = Field(name='Auction Only Price', offset=58, length=10, data_type=Numeric(length=10)) fields = [ timestamp, message_type, stock_symbol, auction_type, reference_price, buy_shares, sell_shares, indicative_price, auction_only_price ]
class RetailPriceImprovementMessage(BasicMessageType): name = 'Retail Price Improvement Message' timestamp = Field(name='Timestamp', offset=0, length=8, data_type=Numeric(length=8)) message_type = Field(name='Message Type', offset=8, length=1, data_type=SingleCharacter(character='R')) stock_symbol = Field(name='Stock Symbol', offset=9, length=8, data_type=Alpha(length=8)) retail_price_improvement = Field(name='Retail Price Improvement', offset=17, length=1, data_type=Alpha(length=1)) fields = [timestamp, message_type, stock_symbol, retail_price_improvement]
def test_message(self): descriptions = [ { self.OFFSET: 0, self.LENGTH: 8, self.DATA_TYPE: Numeric(length=8), }, { self.OFFSET: 8, self.LENGTH: 1, self.DATA_TYPE: SingleCharacter(character='H'), }, { self.OFFSET: 9, self.LENGTH: 8, self.DATA_TYPE: Alpha(length=8), }, { self.OFFSET: 17, self.LENGTH: 1, self.DATA_TYPE: Alpha(length=1), }, { self.OFFSET: 18, self.LENGTH: 1, self.DATA_TYPE: Numeric(length=1), }, { self.OFFSET: 19, self.LENGTH: 1, self.DATA_TYPE: Alpha(length=1), }, { self.OFFSET: 20, self.LENGTH: 1, self.DATA_TYPE: Alpha(length=1), }, ] self._test_message_type(TradeStatusMessage, descriptions)
class AlphaTest(DataTypesTestCase, TestCase): def setUp(self): self.a = Alpha(length=8) def test_valid_alpha(self): self.assertTrue(self.a.is_valid(' ')) self.assertTrue(self.a.is_valid('VALID ')) self.assertTrue(self.a.is_valid('VALIDTOO')) def test_invalid_alpha_wrong_base_set(self): self.assertFalse(self.a.is_valid('invalid ')) self.assertFalse(self.a.is_valid('invalid1')) self.assertFalse(self.a.is_valid('VALID0 ')) self.assertFalse(self.a.is_valid('01234567')) def test_invalid_alpha_wrong_justification(self): self.assertFalse(self.a.is_valid(' VALID')) def test_invalid_alpha_wrong_length(self): self._test_invalid_length(valid_length=self.a.length, valid_char=' ', data_type=self.a)
def test_message(self): descriptions = [ { self.OFFSET: 0, self.LENGTH: 8, self.DATA_TYPE: Numeric(length=8), }, { self.OFFSET: 8, self.LENGTH: 1, self.DATA_TYPE: SingleCharacter(character='R'), }, { self.OFFSET: 9, self.LENGTH: 8, self.DATA_TYPE: Alpha(length=8), }, { self.OFFSET: 17, self.LENGTH: 1, self.DATA_TYPE: Alpha(length=1), }, ] self._test_message_type(RetailPriceImprovementMessage, descriptions)
def test_symbol_clear_message(self): descriptions = [ { self.OFFSET: 0, self.LENGTH: 8, self.DATA_TYPE: Numeric(length=8), }, { self.OFFSET: 8, self.LENGTH: 1, self.DATA_TYPE: SingleCharacter(character='s'), }, { self.OFFSET: 9, self.LENGTH: 8, self.DATA_TYPE: Alpha(length=8), }, ] self._test_message_type(SymbolClearMessage, descriptions)
def setUp(self): self.a = Alpha(length=8)