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()
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()