Exemplo n.º 1
0
    def suscribeMD(self):
        print(
            "SUSCRIBE MD***************************************************************************"
        )
        if len(self.tickers) == 0 or len(self.entries) == 0:
            return

        allowed_entries = ['0', '1', '2', '4', '5', '6', '7', '8', 'B', 'C']
        if not all(elem in allowed_entries for elem in self.entries):
            return

        msg = fix50.MarketDataRequest()
        header = msg.getHeader()
        header.setField(fix.SenderCompID(self.usrID))
        header.setField(fix.TargetCompID(self.targetCompID))
        # ---------------------
        msg.setField(fix.MDReqID("ListaMktData"))
        msg.setField(fix.SubscriptionRequestType('1'))
        msg.setField(fix.MarketDepth(1))
        msg.setField(fix.MDUpdateType(0))
        msg.setField(fix.AggregatedBook(True))

        # BlockMDReqGrp
        group = fix50.MarketDataRequest().NoMDEntryTypes()
        for field in self.entries:
            group.setField(fix.MDEntryType(str(field)))
            msg.addGroup(group)

        # Symbols
        norelatedsym = fix50.MarketDataRequest().NoRelatedSym()
        for ticker in self.tickers:
            norelatedsym.setField(fix.Symbol(ticker))
            logfix.warning("--> Suscribe Ticker >> (%s)" % ticker)
            msg.addGroup(norelatedsym)
        fix.Session.sendToTarget(msg)
Exemplo n.º 2
0
    def compose_market_data_request(self):
        market_data_request = quickfix44.MarketDataRequest()

        market_data_request.setField(quickfix.MDReqID('1'))
        market_data_request.setField(quickfix.SubscriptionRequestType(quickfix.SubscriptionRequestType_SNAPSHOT_PLUS_UPDATES))
        market_data_request.setField(quickfix.MarketDepth(0))
        market_data_request.setField(quickfix.NoMDEntryTypes(2))
        market_data_request.setField(quickfix.MDUpdateType(quickfix.MDUpdateType_INCREMENTAL_REFRESH))

        group = quickfix44.MarketDataRequest().NoMDEntryTypes()
        group.setField(quickfix.MDEntryType(quickfix.MDEntryType_BID))
        market_data_request.addGroup(group)
        group.setField(quickfix.MDEntryType(quickfix.MDEntryType_OFFER))
        market_data_request.addGroup(group)

        market_data_request.setField(quickfix.NoRelatedSym(self.reference_data.get_count()))

        symbol = quickfix44.MarketDataRequest().NoRelatedSym()

        for instrument in self.reference_data.get_instruments():
            symbol.setField(quickfix.SecurityExchange(instrument.exchange))
            symbol.setField(quickfix.Symbol(instrument.symbol))
            market_data_request.addGroup(symbol)

        return market_data_request
    def subscribe(self):
        if self.marketSession is None:
            self.logger.info(
                "FIXSIM-CLIENT Market session is none, skip subscribing")
            return

        for subscription in self.subscriptions:
            message = self.fixVersion.MarketDataRequest()
            message.setField(quickfix.MDReqID(self.idGen.reqID()))
            message.setField(
                quickfix.SubscriptionRequestType(
                    quickfix.SubscriptionRequestType_SNAPSHOT_PLUS_UPDATES))
            message.setField(
                quickfix.MDUpdateType(quickfix.MDUpdateType_FULL_REFRESH))
            message.setField(quickfix.MarketDepth(0))
            message.setField(quickfix.MDReqID(self.idGen.reqID()))

            relatedSym = self.fixVersion.MarketDataRequest.NoRelatedSym()
            relatedSym.setField(quickfix.Product(quickfix.Product_CURRENCY))
            relatedSym.setField(
                quickfix.SecurityType(
                    quickfix.SecurityType_FOREIGN_EXCHANGE_CONTRACT))
            relatedSym.setField(quickfix.Symbol(subscription.symbol))
            message.addGroup(relatedSym)

            group = self.fixVersion.MarketDataRequest.NoMDEntryTypes()
            group.setField(quickfix.MDEntryType(quickfix.MDEntryType_BID))
            message.addGroup(group)
            group.setField(quickfix.MDEntryType(quickfix.MDEntryType_BID))
            message.addGroup(group)

            self.sendToTarget(message, self.marketSession)
Exemplo n.º 4
0
    def onLogon(self, sessionID):
        self.sessionID = sessionID
        print("onLogon - sessionID: " + sessionID.toString())

        currency_pairs = ['GBP/USD', 'EUR/USD']

        for ccy in currency_pairs:
            mdr = fix.Message()
            mdr.getHeader().setField(fix.BeginString(fix.BeginString_FIX44))
            mdr.getHeader().setField(fix.MsgType(fix.MsgType_MarketDataRequest))

            current_milli_time = lambda: int(round(time.time() * 1000))
            mdr.setField(fix.MDReqID(str(current_milli_time())))      # a random string
            mdr.setField(fix.SubscriptionRequestType(fix.SubscriptionRequestType_SNAPSHOT_PLUS_UPDATES))        # what stater required
            mdr.setField(fix.MarketDepth(1))        # what stater required

            mdr.setField(fix.AggregatedBook(True))

            mdr.setField(fix.NoMDEntryTypes(1))     # what stater required
            mdr.setField(fix.MDUpdateType(fix.MDUpdateType_INCREMENTAL_REFRESH))        # what stater required

            group = fix44.MarketDataRequest().NoMDEntryTypes()
            group.setField(fix.MDEntryType(fix.MDEntryType_BID))
            mdr.addGroup(group)
            group.setField(fix.MDEntryType(fix.MDEntryType_OFFER))
            mdr.addGroup(group)

            mdr.setField(fix.NoRelatedSym(1))

            symbol = fix44.MarketDataRequest().NoRelatedSym()
            symbol.setField(fix.Symbol(ccy))
            mdr.addGroup(symbol)

            fix.Session.sendToTarget(mdr, sessionID)
Exemplo n.º 5
0
    def createOrderBookRequest(self):
        orderBookRequest = fix44.MarketDataRequest()
        noRelatedSym = fix44.MarketDataRequest.NoRelatedSym()
        noRelatedSym.setField(fix.Symbol('BTC/CNY'))
        orderBookRequest.addGroup(noRelatedSym)

        orderBookRequest.setField(
            fix.MDReqID("123"))  # Unique ID assigned to this request
        orderBookRequest.setField(
            fix.SubscriptionRequestType('1'))  # 0 = Snapshot
        # 1 = Snapshot + Subscribe
        # 2 Unsubscribe
        orderBookRequest.setField(
            fix.MDUpdateType(1))  # 0 = full refresh, 1: incremental refresh
        orderBookRequest.setField(fix.MarketDepth(0))  # 0 = full book,

        group1 = fix44.MarketDataRequest.NoMDEntryTypes()
        group1.setField(fix.MDEntryType('0'))  # bids
        orderBookRequest.addGroup(group1)

        group2 = fix44.MarketDataRequest.NoMDEntryTypes()
        group2.setField(fix.MDEntryType('1'))  # asks
        orderBookRequest.addGroup(group2)

        return orderBookRequest
    def send_mkt_data_req(self, symbol):
        """
        :param symbol: str
        """
        print("send_mkt_data_req: ", symbol)
        message = fix44.MarketDataRequest()
        message.setField(fix.MDReqID(self.next_id()))
        message.setField(
            fix.SubscriptionRequestType(
                fix.SubscriptionRequestType_SNAPSHOT_PLUS_UPDATES))
        message.setField(fix.MarketDepth(3))

        message.setField(fix.MDUpdateType(
            fix.MDUpdateType_INCREMENTAL_REFRESH))

        symbol_group = fix44.MarketDataRequest.NoRelatedSym()
        symbol_group.setField(fix.Symbol(symbol))
        message.addGroup(symbol_group)

        types = fix44.MarketDataRequest.NoMDEntryTypes()
        types.setField(fix.MDEntryType(fix.MDEntryType_BID))
        message.addGroup(types)

        types = fix44.MarketDataRequest.NoMDEntryTypes()
        types.setField(fix.MDEntryType(fix.MDEntryType_OFFER))
        message.addGroup(types)

        fix.Session_sendToTarget(message, self.sessionID)
Exemplo n.º 7
0
    def market_data_request(self, sender_comp_id, target_comp_id, symbols):
        md_types = [
            fix.MDEntryType_BID, fix.MDEntryType_OFFER, fix.MDEntryType_TRADE
        ]

        message = fix44.MarketDataRequest()

        header = message.getHeader()
        header.setField(fix.SenderCompID(sender_comp_id))
        header.setField(fix.TargetCompID(target_comp_id))

        message.setField(fix.MDReqID(self._generate_id()))
        message.setField(
            fix.SubscriptionRequestType(
                fix.SubscriptionRequestType_SNAPSHOT_PLUS_UPDATES))
        # message.setField(
        #     fix.SubscriptionRequestType(
        #         fix.SubscriptionRequestType_SNAPSHOT
        #     )
        # )
        """
        Valid values:

        0 = Full Book

        1 = Top of Book

        N>1 = Report best N price tiers of data
        """

        message.setField(fix.MarketDepth(0))
        """
        Valid values:
        0 = Full Refresh
        1 = Incremental Refresh
        """

        message.setField(fix.MDUpdateType(
            fix.MDUpdateType_INCREMENTAL_REFRESH))

        group = fix44.MarketDataRequest().NoMDEntryTypes()

        for md_type in md_types:
            group.setField(fix.MDEntryType(md_type))
            message.addGroup(group)

        group = fix44.MarketDataRequest().NoRelatedSym()

        for symbol in symbols:
            group.setField(fix.Symbol(symbol))
            message.addGroup(group)

        try:
            fix.Session.sendToTarget(message)
        except fix.SessionNotFound:
            raise Exception(f"No session found {message}, exiting...")
Exemplo n.º 8
0
def main():
    sessionID = fix.SessionID('FIX.4.4', SENDERCOMPID, 'PAYMIUM')

    params = fix.Dictionary()
    params.setString('ConnectionType', 'initiator')
    params.setString('StartTime', '00:00:00')
    params.setString('EndTime', '00:00:00')
    params.setString('HeartBtInt', '30')
    params.setString('CheckLatency', 'Y')
    params.setString('SocketConnectHost', '195.154.171.115')
    params.setString('SocketConnectPort', '8359')
    params.setString('DataDictionary', FIX44FILE)
    params.setString('EncryptMethod', '0')

    settings = fix.SessionSettings()
    settings.set(sessionID, params)

    application = MyApplication()
    factory = fix.FileStoreFactory("store")
    acceptor = fix.SocketInitiator(application, factory, settings,
                                   fix.ScreenLogFactory(DEBUG, DEBUG, DEBUG))
    acceptor.start()

    time.sleep(2)

    mdr = fixMsg.MarketDataRequest()
    mdr.setField(fix.MDReqID("MDRQ-%d" % (time.time() * 1000000)))
    # We want the full book here, not just the top
    mdr.setField(fix.MarketDepth(1))
    # We want to get a snapshot and also subscribe to the market depth updates
    mdr.setField(
        fix.SubscriptionRequestType(
            fix.SubscriptionRequestType_SNAPSHOT_PLUS_UPDATES))
    # We'll want only incremental refreshes when new data is available
    mdr.setField(fix.MDUpdateType(fix.MDUpdateType_INCREMENTAL_REFRESH))
    # Specify the currency
    instruments = fixMsg.MarketDataRequest().NoRelatedSym()
    instruments.setField(fix.Symbol("EUR/XBT"))
    mdr.addGroup(instruments)
    # Specify that we'll want the bids and asks
    mdr.setField(fix.NoMDEntryTypes(2))
    group = fixMsg.MarketDataRequest().NoMDEntryTypes()
    group.setField(fix.MDEntryType(fix.MDEntryType_BID))
    group.setField(fix.MDEntryType(fix.MDEntryType_OFFER))
    mdr.addGroup(group)

    fix.Session.sendToTarget(mdr, sessionID)

    while True:
        time.sleep(10)

    acceptor.stop()
Exemplo n.º 9
0
    def send_MarketDataRequest(self, symbol='EURUSD'):

        # If no symbols provided, exit with error.
        if len(symbol) is 0:
            raise RuntimeError('No symbol specified for MarketDataRequest')

        reqid = self.app.check_new_symbol(
            symbol)  # fffff: ok to reference it here?
        self.app.add_symbol_to_positions(symbol)

        # Create new message of type MarketDataRequest
        message = fix.Message()
        header = message.getHeader()

        # Set message type to MarketDataRequest (35=V)
        header.setField(fix.MsgType(fix.MsgType_MarketDataRequest))

        # Assign request ID (262)
        header.setField(fix.MDReqID(str(reqid)))

        # Set Subscription Request Type (263) to SNAPSHOT + UPDATES (1)
        header.setField(
            fix.SubscriptionRequestType(
                fix.SubscriptionRequestType_SNAPSHOT_PLUS_UPDATES))

        # Set MDUpdateType (required when SubscribtionRequestType is S+U)
        header.setField(fix.MDUpdateType(fix.MDUpdateType_INCREMENTAL_REFRESH))

        # Set market depth (264)
        header.setField(fix.MarketDepth(0))  # 0 = full book, 1 = top of book

        # Create NoRelatedSym group (to place 146=1 before Symbol)
        group = fix44.MarketDataRequest.NoRelatedSym()

        group.setField(fix.Symbol(symbol))
        message.addGroup(group)

        # Set Currency (15). not really needed?
        # message.setField(fix.Currency(_currency))

        # Send message to Counter-Party and await response.
        if self.sessionID_Quote is not None:

            fix.Session.sendToTarget(message, self.sessionID_Quote)
        else:
            print(
                '[ERROR] send_MassQuoteAcknowledgement() failed. sessionID_Quote is None!'
            )
Exemplo n.º 10
0
    def marketDataRequest(self):
        # pag 63
        msg = fix50.MarketDataRequest()
        header = msg.getHeader()
        # header.setField(fix.BeginString(fix.BeginString_FIXT11))
        # header.setField(fix.MsgType(msgType))
        header.setField(fix.SenderCompID("pjseoane232"))
        header.setField(fix.TargetCompID("ROFX"))

        # msg = self.buildMsgHeader("V")

        msg.setField(fix.MDReqID("ListaMktData2"))
        msg.setField(fix.SubscriptionRequestType('2'))
        msg.setField(fix.MarketDepth(1))
        msg.setField(fix.MDUpdateType(0))
        msg.setField(fix.AggregatedBook(True))

        # msg.setField(fix.NoMDEntryTypes(2))

        # ---- define Group

        group = fix50.MarketDataRequest().NoMDEntryTypes()
        group.setField(fix.MDEntryType('0'))
        msg.addGroup(group)

        # group = fix50.MarketDataRequest().NoMDEntryTypes()
        group.setField(fix.MDEntryType('1'))
        msg.addGroup(group)

        # group3 = fix50.MarketDataRequest().NoMDEntryTypes()
        # group3.setField(fix.MDEntryType('2'))
        # msg.addGroup(group3)
        # -----------------------------------------

        msg.setField(fix.NoRelatedSym(1))
        group = fix50.MarketDataRequest().NoRelatedSym()
        group.setField(fix.Symbol("RFX20Sep19"))
        msg.addGroup(group)

        fix.Session.sendToTarget(msg)