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