Пример #1
0
    def addEpicListener(self, epicName):
        if epicName not in self.subcriptionKeyStore:
            logger.debug("Adding epic listener...")
            # Make Subscription using MERGE mode
            subcription_prices = Subscription(mode="MERGE",
                                              items=['MARKET:' + epicName],
                                              fields=[
                                                  "UPDATE_TIME", "BID",
                                                  "OFFER", "CHANGE",
                                                  "MARKET_STATE"
                                              ])
            #'MARKET:CS.D.BITCOIN.TODAY.IP',
            #'MARKET:IX.D.FTSE.DAILY.IP'

            # Adding the "on_price_update" function to Subscription
            subcription_prices.addlistener(self.on_prices_update)
            # Registering the Subscription
            sub_key_prices = self.ig_stream_service.ls_client.subscribe(
                subcription_prices)

            # Store the subscription key under the epic name
            if sub_key_prices != 0:
                self.subcriptionKeyStore[epicName] = sub_key_prices
                logger.info("Successfully subscribed to epic: " + epicName)
                result = True
            else:
                logger.warning("Failed to subscribe to epic: " + epicName)
                result = False
        else:
            # Already subscribed
            result = True
        return (result)
Пример #2
0
    def addEpicListener(self, epicName):
        if epicName not in self.subcriptionKeyStore:
            logger.debug("Adding epic listener...")
            # Make Subscription using MERGE mode
            subcription_prices = Subscription(
                mode="MERGE",
                items=['MARKET:'+epicName],
                fields=["UPDATE_TIME", "BID", "OFFER", "CHANGE", "MARKET_STATE"]
                ) 
            #'MARKET:CS.D.BITCOIN.TODAY.IP',
            #'MARKET:IX.D.FTSE.DAILY.IP'

            # Adding the "on_price_update" function to Subscription
            subcription_prices.addlistener(self.on_prices_update)
            # Registering the Subscription
            sub_key_prices = self.ig_stream_service.ls_client.subscribe(subcription_prices)
            
            # Store the subscription key under the epic name
            if sub_key_prices != 0:
                self.subcriptionKeyStore[epicName] = sub_key_prices
                logger.info("Successfully subscribed to epic: " + epicName)
                result = True
            else:            
                logger.warning("Failed to subscribe to epic: " + epicName)
                result = False
        else:
            # Already subscribed
            result = True
        return(result)
Пример #3
0
    def _t_streaming_prices(self, dataname, q, tmout):
        '''
        Target for the streaming prices thread. This will setup the streamer.
        '''
        if tmout is not None:
            _time.sleep(tmout)

        self.igss.set_price_q(q, dataname)
        #igss = Streamer(q, ig_service=self.igapi)
        #ig_session = igss.create_session()
        #igss.connect(self.p.account)

        epic = 'CHART:' + dataname + ':TICK'
        # Making a new Subscription in MERGE mode
        subcription_prices = Subscription(
            mode="DISTINCT",
            items=[epic],
            fields=["UTM", "BID", "OFR", "TTV", "LTV"],
        )
        #adapter="QUOTE_ADAPTER")

        # Adding the "on_price_update" function to Subscription
        subcription_prices.addlistener(self.igss.on_prices_update)

        sub_key_prices = self.igss.ls_client.subscribe(subcription_prices)
def add_volume_trackers(ig_service, ig_stream_service, markets,
                        historical_data_fetcher, notification_callbacks,
                        pre_calculate):
    """
    Add Volume trackers to an IG stream session.
    """
    volume_trackers = {}
    for market in markets:
        name = market["name"]
        epic = market["epic"]
        resolutions = market["resolutions"]
        volume_trackers[epic] = [
            VolumeTracker(name,
                          epic,
                          resolution,
                          ig_service,
                          historical_data_fetcher,
                          notification_callbacks=notification_callbacks,
                          pre_calculate=pre_calculate)
            for resolution in resolutions
        ]
        for vt in volume_trackers[epic]:
            vt.initiate()

    def add_candle_to_vt(event):
        # LOGGER.log("Received event: %s", pprint.pformat(event["name"]))
        values = event["values"]
        item = event["name"]
        sub_type, epic, resolution = item.split(":")
        if values["CONS_END"] == u"1":
            # Only add completed candles
            for vt in volume_trackers[epic]:
                try:
                    vt.add_5min_candle(values, notify_on_anomaly=True)
                except ValueError:
                    LOGGER.error("Could not add candle data for %s: %s", item,
                                 values)

    # Making a new Subscription in MERGE mode
    items = [
        ":".join(("CHART", market["epic"], "5MINUTE")) for market in markets
    ]
    LOGGER.info("Subscribing to: %s", items)
    subscription_prices = Subscription(
        mode="MERGE",
        items=items,
        fields=INTERESTING_FIELDS,
    )

    # Adding the "on_price_update" function to Subscription
    subscription_prices.addlistener(add_candle_to_vt)

    # Registering the Subscription
    ig_stream_service.ls_client.subscribe(subscription_prices)
Пример #5
0
def main():
    logging.basicConfig(level=logging.INFO)
    # logging.basicConfig(level=logging.DEBUG)

    ig_service = IGService(config.username, config.password, config.api_key,
                           config.acc_type)

    ig_stream_service = IGStreamService(ig_service)
    ig_session = ig_stream_service.create_session()
    # Ensure configured account is selected
    accounts = ig_session[u'accounts']
    for account in accounts:
        if account[u'accountId'] == config.acc_number:
            accountId = account[u'accountId']
            break
        else:
            print('Account not found: {0}'.format(config.acc_number))
            accountId = None
    ig_stream_service.connect(accountId)

    # Making a new Subscription in MERGE mode
    subscription_prices = Subscription(
        mode="MERGE",
        items=['QB.D.FT1605UD.03.IP/MINUTE'],
        fields=["UPDATE_TIME", "BID", "OFFER", "CHANGE", "MARKET_STATE"],
    )
    #adapter="QUOTE_ADAPTER")

    # Adding the "on_price_update" function to Subscription
    subscription_prices.addlistener(on_prices_update)

    # Registering the Subscription
    sub_key_prices = ig_stream_service.ls_client.subscribe(subscription_prices)

    # Making an other Subscription in MERGE mode
    subscription_account = Subscription(
        mode="MERGE",
        items=['ACCOUNT:' + accountId],
        fields=["AVAILABLE_CASH"],
    )
    #    #adapter="QUOTE_ADAPTER")

    # Adding the "on_balance_update" function to Subscription
    subscription_account.addlistener(on_account_update)

    # Registering the Subscription
    sub_key_account = ig_stream_service.ls_client.subscribe(
        subscription_account)

    input("{0:-^80}\n".format("HIT CR TO UNSUBSCRIBE AND DISCONNECT FROM \
    LIGHTSTREAMER"))

    # Disconnecting
    ig_stream_service.disconnect()
Пример #6
0
def main():
    # logging.basicConfig(level=logging.DEBUG)
    logging.basicConfig(level=logging.INFO)

    # Establishing a new connection to Lightstreamer Server
    print("Starting connection")
    # lightstreamer_client = LSClient("http://localhost:8080", "DEMO")
    lightstreamer_client = LSClient("http://push.lightstreamer.com", "DEMO")
    try:
        lightstreamer_client.connect()
    except Exception as e:
        print("Unable to connect to Lightstreamer Server")
        print(traceback.format_exc())
        print(e)
        sys.exit(1)

    # Making a new Subscription in MERGE mode
    subscription = Subscription(
        mode="MERGE",
        items=[
            "item1",
            "item2",
            "item3",
            "item4",
            "item5",
            "item6",
            "item7",
            "item8",
            "item9",
            "item10",
            "item11",
            "item12",
        ],
        fields=["stock_name", "last_price", "time", "bid", "ask"],
    )

    # Adding the "on_item_update" function to Subscription
    subscription.addlistener(on_item_update)

    # Registering the Subscription
    sub_key = lightstreamer_client.subscribe(subscription)
    print(sub_key)

    input("{0:-^80}\n".format("HIT CR TO UNSUBSCRIBE AND DISCONNECT FROM \
    LIGHTSTREAMER"))

    # Unsubscribing from Lightstreamer by using the subscription key
    # lightstreamer_client.unsubscribe(sub_key)

    lightstreamer_client.unsubscribe()

    # Disconnecting
    lightstreamer_client.disconnect()
Пример #7
0
    def addAccountListener(self, accountId):
        logger.debug("Adding account listener...")
        # Makie Subscription using MERGE mode
        subscription_account = Subscription(
            mode="MERGE",
            items=['ACCOUNT:'+accountId],
            fields=["AVAILABLE_CASH"],
            )

        # Adding the "on_balance_update" function to Subscription
        subscription_account.addlistener(on_account_update)
        # Registering the Subscription
        sub_key_account = self.ig_stream_service.ls_client.subscribe(subscription_account)

        logger.debug("Success")
Пример #8
0
    def _init_stream(self):
        ig_stream_service = IGStreamService(self.broker.session)
        ig_session = ig_stream_service.create_session()
        # Ensure configured account is selected
        account = self.broker.current_account
        if account is not None:
            ig_stream_service.connect(account)
            subscription = Subscription(
                    mode=self.mode,
                    items=self.items,
                    fields=self.fields,
                )
            subscription.addlistener(self.on_update)

            sub_key_prices = ig_stream_service.ls_client.subscribe(subscription)
def main():
    logging.basicConfig(level=logging.INFO)
    # logging.basicConfig(level=logging.DEBUG)

    ig_service = IGService(config.username,
                           config.password,
                           config.api_key,
                           config.acc_type,
                           acc_number=config.acc_number)

    ig_stream_service = IGStreamService(ig_service)
    ig_stream_service.create_session()
    #ig_stream_service.create_session(version='3')

    # Making a new Subscription in MERGE mode
    subscription_prices = Subscription(
        mode="MERGE",
        #items=["L1:CS.D.GBPUSD.CFD.IP", "L1:CS.D.USDJPY.CFD.IP"], # sample CFD epics
        items=["L1:CS.D.GBPUSD.TODAY.IP",
               "L1:IX.D.FTSE.DAILY.IP"],  # sample spreadbet epics
        fields=["UPDATE_TIME", "BID", "OFFER", "CHANGE", "MARKET_STATE"],
    )

    # Adding the "on_price_update" function to Subscription
    subscription_prices.addlistener(on_prices_update)

    # Registering the Subscription
    sub_key_prices = ig_stream_service.ls_client.subscribe(subscription_prices)

    # Making an other Subscription in MERGE mode
    subscription_account = Subscription(
        mode="MERGE",
        items=["ACCOUNT:" + config.acc_number],
        fields=["AVAILABLE_CASH"],
    )

    # Adding the "on_balance_update" function to Subscription
    subscription_account.addlistener(on_account_update)

    # Registering the Subscription
    sub_key_account = ig_stream_service.ls_client.subscribe(
        subscription_account)

    input("{0:-^80}\n".format("HIT CR TO UNSUBSCRIBE AND DISCONNECT FROM \
    LIGHTSTREAMER"))

    # Disconnecting
    ig_stream_service.disconnect()
Пример #10
0
    def addAccountListener(self, accountId):
        logger.debug("Adding account listener...")
        # Makie Subscription using MERGE mode
        subscription_account = Subscription(
            mode="MERGE",
            items=['ACCOUNT:' + accountId],
            fields=["AVAILABLE_CASH"],
        )

        # Adding the "on_balance_update" function to Subscription
        subscription_account.addlistener(on_account_update)
        # Registering the Subscription
        sub_key_account = self.ig_stream_service.ls_client.subscribe(
            subscription_account)

        logger.debug("Success")
Пример #11
0
def main():

    # setup
    global priceObj

    # logging.basicConfig(level=logging.INFO)
    config = IGServiceConfig()
    ig_service = IGService(config.username, config.password, config.api_key,
                           config.acc_type)
    ig_stream_service = IGStreamService(ig_service)
    ig_session = ig_stream_service.create_session()

    accounts = ig_session[u'accounts']
    for account in accounts:
        if account[u'accountId'] == config.acc_number:
            accountId = account[u'accountId']
            break
    ig_stream_service.connect(accountId)

    # save to DB thread
    sched = BackgroundScheduler()
    sched.add_job(saveToDB, 'interval', seconds=5)
    sched.start()

    # Making a new Subscription in MERGE mode
    subscriptionCap = 38
    subscriptionCurrent = 0
    i = 0
    listSubscription = []
    while i < len(priceObj):
        items = list(priceObj.keys())[i:i + subscriptionCap]
        subscription_prices = Subscription(mode="MERGE",
                                           items=items,
                                           fields=["BID", "OFFER"])
        subscription_prices.addlistener(onPriceUpdate)
        sub_key_prices = ig_stream_service.ls_client.subscribe(
            subscription_prices)
        listSubscription.append(sub_key_prices)
        time.sleep(2)
        # print(subscription_prices)
        print(items)
        i += subscriptionCap

    input("{0:-^80}\n".format("Press Enter to close"))

    # Disconnecting
    ig_stream_service.disconnect()
Пример #12
0
def main():
    logging.basicConfig(level=logging.INFO)
    # logging.basicConfig(level=logging.DEBUG)

    ig_service = IGService(config.username, config.password, config.api_key,
                           config.acc_type)

    ig_stream_service = IGStreamService(ig_service)
    ig_session = ig_stream_service.create_session()
    accountId = ig_session[u'accounts'][0][u'accountId']
    ig_stream_service.connect(accountId)

    # Making a new Subscription in MERGE mode
    subcription_prices = Subscription(
        mode="MERGE",
        items=['L1:CS.D.GBPUSD.CFD.IP', 'L1:CS.D.USDJPY.CFD.IP'],
        fields=["UPDATE_TIME", "BID", "OFFER", "CHANGE", "MARKET_STATE"],
    )
    #adapter="QUOTE_ADAPTER")

    # Adding the "on_price_update" function to Subscription
    subcription_prices.addlistener(on_prices_update)

    # Registering the Subscription
    sub_key_prices = ig_stream_service.ls_client.subscribe(subcription_prices)

    # Making an other Subscription in MERGE mode
    subscription_account = Subscription(
        mode="MERGE",
        items='ACCOUNT:' + accountId,
        fields=["AVAILABLE_CASH"],
    )
    #    #adapter="QUOTE_ADAPTER")

    # Adding the "on_balance_update" function to Subscription
    subscription_account.addlistener(on_account_update)

    # Registering the Subscription
    sub_key_account = ig_stream_service.ls_client.subscribe(
        subscription_account)

    compat.wait_for_input(
        "{0:-^80}\n".format("HIT CR TO UNSUBSCRIBE AND DISCONNECT FROM \
    LIGHTSTREAMER"))

    # Disconnecting
    ig_stream_service.disconnect()
def main():
    logging.basicConfig(level=logging.INFO)
    # logging.basicConfig(level=logging.DEBUG)

    ig_service = IGService(config.username, config.password, config.api_key, config.acc_type)

    ig_stream_service = IGStreamService(ig_service)
    ig_session = ig_stream_service.create_session()
    accountId = ig_session[u'accounts'][0][u'accountId']
    ig_stream_service.connect(accountId)

    # Making a new Subscription in MERGE mode
    subcription_prices = Subscription(
        mode="MERGE",
        items=['L1:CS.D.GBPUSD.CFD.IP', 'L1:CS.D.USDJPY.CFD.IP'],
        fields=["UPDATE_TIME", "BID", "OFFER", "CHANGE", "MARKET_STATE"],
        )
        #adapter="QUOTE_ADAPTER")


    # Adding the "on_price_update" function to Subscription
    subcription_prices.addlistener(on_prices_update)

    # Registering the Subscription
    sub_key_prices = ig_stream_service.ls_client.subscribe(subcription_prices)


    # Making an other Subscription in MERGE mode
    subscription_account = Subscription(
        mode="MERGE",
        items='ACCOUNT:'+accountId,
        fields=["AVAILABLE_CASH"],
        )
    #    #adapter="QUOTE_ADAPTER")

    # Adding the "on_balance_update" function to Subscription
    subscription_account.addlistener(on_account_update)

    # Registering the Subscription
    sub_key_account = ig_stream_service.ls_client.subscribe(subscription_account)

    compat.wait_for_input("{0:-^80}\n".format("HIT CR TO UNSUBSCRIBE AND DISCONNECT FROM \
    LIGHTSTREAMER"))

    # Disconnecting
    ig_stream_service.disconnect()
Пример #14
0
    def subscribe(self):
        # Making a new Subscription in MERGE mode
        subcription_prices = Subscription(
            mode="MERGE",
            items=self.tickers_subs,
            fields=["BID", "OFFER", "CHANGE", "MARKET_STATE", "UPDATE_TIME"],
            # adapter="QUOTE_ADAPTER"
        )

        # Adding the "on_price_update" function to Subscription
        subcription_prices.addlistener(self._on_prices_update)

        # Registering the Subscription
        self.logger.info("Registering the Subscription")
        try:
            self.ig_stream_service.ls_client.subscribe(subcription_prices)
        except Exception:
            self.logger.error("Error while subscribing")
            print(traceback.format_exc())
def main():
    #logging.basicConfig(level=logging.DEBUG)
    logging.basicConfig(level=logging.INFO)

    # Establishing a new connection to Lightstreamer Server
    print("Starting connection")
    #lightstreamer_client = LSClient("http://localhost:8080", "DEMO")
    lightstreamer_client = LSClient("http://push.lightstreamer.com", "DEMO")
    try:
        lightstreamer_client.connect()
    except Exception as e:
        print("Unable to connect to Lightstreamer Server")
        print(traceback.format_exc())
        sys.exit(1)


    # Making a new Subscription in MERGE mode
    subscription = Subscription(
        mode="MERGE",
        items=["item1", "item2", "item3", "item4",
               "item5", "item6", "item7", "item8",
               "item9", "item10", "item11", "item12"],
        fields=["stock_name", "last_price", "time", "bid", "ask"],
        adapter="QUOTE_ADAPTER")


    # Adding the "on_item_update" function to Subscription
    subscription.addlistener(on_item_update)

    # Registering the Subscription
    sub_key = lightstreamer_client.subscribe(subscription)

    compat.wait_for_input("{0:-^80}\n".format("HIT CR TO UNSUBSCRIBE AND DISCONNECT FROM \
    LIGHTSTREAMER"))

    # Unsubscribing from Lightstreamer by using the subscription key
    #lightstreamer_client.unsubscribe(sub_key)

    lightstreamer_client.unsubscribe()

    # Disconnecting
    lightstreamer_client.disconnect()
Пример #16
0
    def _t_account_events(self, q, tmout=None):
        '''
        Thread to create the subscription to account events.

        Here we create a merge subscription for lightstreamer.
        '''
        self.igss.set_account_q(q)
        # Making an other Subscription in MERGE mode
        subscription_account = Subscription(
            mode="MERGE",
            items=['ACCOUNT:' + self.p.account],
            fields=["AVAILABLE_CASH", "EQUITY"],
        )
        #    #adapter="QUOTE_ADAPTER")

        # Adding the "on_balance_update" function to Subscription
        subscription_account.addlistener(self.igss.on_account_update)

        # Registering the Subscription
        sub_key_account = self.igss.ls_client.subscribe(subscription_account)
Пример #17
0
    def __init__(self, events_queue, ig_stream_service, tickers):
        self.price_event = None
        self.events_queue = events_queue
        self.continue_backtest = True
        self.ig_stream_service = ig_stream_service
        self.tickers_lst = tickers
        self.tickers = {}
        for ticker in self.tickers_lst:
            self.tickers[ticker] = {}

        # Making a new Subscription in MERGE mode
        subcription_prices = Subscription(
            mode="MERGE",
            items=tickers,
            fields=["UPDATE_TIME", "BID", "OFFER", "CHANGE", "MARKET_STATE"],
            # adapter="QUOTE_ADAPTER",
        )

        # Adding the "on_price_update" function to Subscription
        subcription_prices.addlistener(self.on_prices_update)

        # Registering the Subscription
        self.ig_stream_service.ls_client.subscribe(subcription_prices)
Пример #18
0
    def __init__(self, events_queue, ig_stream_service, tickers):
        self.price_event = None
        self.events_queue = events_queue
        self.continue_backtest = True
        self.ig_stream_service = ig_stream_service
        self.tickers_lst = tickers
        self.tickers = {}
        for ticker in self.tickers_lst:
            self.tickers[ticker] = {}

        # Making a new Subscription in MERGE mode
        subcription_prices = Subscription(
            mode="MERGE",
            items=tickers,
            fields=["UPDATE_TIME", "BID", "OFFER", "CHANGE", "MARKET_STATE"],
            # adapter="QUOTE_ADAPTER",
        )

        # Adding the "on_price_update" function to Subscription
        subcription_prices.addlistener(self.on_prices_update)

        # Registering the Subscription
        self.ig_stream_service.ls_client.subscribe(subcription_prices)
Пример #19
0
def main():

    epics1 = [
        'CHART:CS.D.GBPEUR.MINI.IP:1MINUTE',
        'CHART:IR.D.10YEAR100.FWM2.IP:1MINUTE',
        'CHART:CC.D.LCO.UME.IP:1MINUTE', 'CHART:CS.D.NZDUSD.MINI.IP:1MINUTE',
        'CHART:CS.D.USDCAD.MINI.IP:1MINUTE',
        'CHART:CS.D.USDJPY.MINI.IP:1MINUTE', 'CHART:CO.D.RR.FWM1.IP:1MINUTE',
        'CHART:CO.D.O.FWM2.IP:1MINUTE', 'CHART:IX.D.SPTRD.IFM.IP:1MINUTE',
        'CHART:IX.D.NASDAQ.IFE.IP:1MINUTE'
    ]

    epics2 = ['CHART:CS.D.GBPEUR.MINI.IP:1MINUTE']

    epics3 = ['CHART:IR.D.10YEAR100.FWM2.IP:1MINUTE']

    epics4 = ['CHART:CS.D.NZDUSD.MINI.IP:1MINUTE']

    epics2 = ['CHART:KA.D.ECHOGS.CASH.IP:1MINUTE']

    logging.basicConfig(level=logging.INFO)
    # logging.basicConfig(level=logging.DEBUG)

    ig_service = IGService(config.username, config.password, config.api_key,
                           config.acc_type)

    ig_stream_service = IGStreamService(ig_service)
    ig_session = ig_stream_service.create_session()
    # Ensure configured account is selected
    accounts = ig_session[u'accounts']
    for account in accounts:
        if account[u'accountId'] == config.acc_number:
            accountId = account[u'accountId']
            break
        else:
            print('Account not found: {0}'.format(config.acc_number))
            accountId = None
    ig_stream_service.connect(accountId)

    # Making a new Subscription in MERGE mode
    subscription_prices = Subscription(
        mode="MERGE",
        items=epics1,
        fields=["UTM", "BID_OPEN", "BID_HIGH", "BID_LOW", "BID_CLOSE"],
    )

    # adapter="QUOTE_ADAPTER")

    # Adding the "on_price_update" function to Subscription
    subscription_prices.addlistener(on_prices_update)

    # Registering the Subscription
    sub_key_prices = ig_stream_service.ls_client.subscribe(subscription_prices)

    # Making an other Subscription in MERGE mode
    subscription_account = Subscription(
        mode="MERGE",
        items=['ACCOUNT:' + accountId],
        fields=["AVAILABLE_CASH"],
    )
    #    #adapter="QUOTE_ADAPTER")

    # Registering the Subscription
    sub_key_account = ig_stream_service.ls_client.subscribe(
        subscription_account)

    input("{0:-^80}\n".format("HIT CR TO UNSUBSCRIBE AND DISCONNECT FROM \
    LIGHTSTREAMER"))

    # Disconnecting
    ig_stream_service.disconnect()
Пример #20
0
def main():
    logging.basicConfig(level=logging.INFO)
    # logging.basicConfig(level=logging.DEBUG)

    ig_service = IGService(config.username, config.password, config.api_key,
                           config.acc_type)

    ig_stream_service = IGStreamService(ig_service)
    ig_session = ig_stream_service.create_session()
    # Ensure configured account is selected
    accounts = ig_session[u"accounts"]
    for account in accounts:
        if account[u"accountId"] == config.acc_number:
            accountId = account[u"accountId"]
            break
        else:
            print("Account not found: {0}".format(config.acc_number))
            accountId = None
    ig_stream_service.connect(accountId)

    # Making a new Subscription in MERGE mode
    subscription_prices = Subscription(
        mode="MERGE",
        items=["CHART:CS.D.EURUSD.MINI.IP:1MINUTE"],
        fields=[
            "LTV", "UTM", "DAY_OPEN_MID", "DAY_NET_CHG_MID",
            "DAY_PERC_CHG_MID", "DAY_HIGH", "DAY_LOW", "OFR_OPEN", "OFR_HIGH",
            "OFR_LOW", "OFR_CLOSE", "BID_OPEN", "BID_HIGH", "BID_LOW",
            "BID_CLOSE", "LTP_OPEN", "LTP_HIGH", "LTP_LOW", "LTP_CLOSE",
            "CONS_END", "CONS_TICK_COUNT"
        ],
    )
    # adapter="QUOTE_ADAPTER")

    # Adding the "on_price_update" function to Subscription
    subscription_prices.addlistener(on_prices_update)

    # Registering the Subscription
    sub_key_prices = ig_stream_service.ls_client.subscribe(subscription_prices)

    # Making an other Subscription in MERGE mode
    subscription_account = Subscription(
        mode="MERGE",
        items=["ACCOUNT:" + accountId],
        fields=["AVAILABLE_CASH"],
    )
    #    #adapter="QUOTE_ADAPTER")

    # Adding the "on_balance_update" function to Subscription
    subscription_account.addlistener(on_account_update)

    # Registering the Subscription
    sub_key_account = ig_stream_service.ls_client.subscribe(
        subscription_account)

    heartbeat_items = ["TRADE:HB.U.HEARTBEAT.IP"]
    heartbeat = Subscription(
        mode='MERGE',
        items=heartbeat_items,
        fields=["HEARTBEAT"],
    )

    heartbeat.addlistener(on_heartbeat_update)
    sub_heartbeat = ig_stream_service.ls_client.subscribe(heartbeat)

    input("{0:-^80}\n".format("HIT CR TO UNSUBSCRIBE AND DISCONNECT FROM \
    LIGHTSTREAMER"))

    # Disconnecting
    ig_stream_service.disconnect()
    producer.flush()