def start_ws( stopping=Event(), user='', account='', password='', entorno=''): if user == '': user, password, account, entorno = ask_login_credentials() pmy.init(user, password, account, entorno) pmy.login() ws = createWS() t_ws = Thread(target=initWS, kwargs={ 'ws': ws, 'user': user, 'password': password, 'entorno': entorno, 'account': account, 'stopping': stopping }, name='WebSocket-Thread') t_ws.start() try: #Wait until the Websocket is open in its thread conn_timeout = 5 sleep(0.5) while not ws.sock.connected and conn_timeout: self.logger.debug( 'Waiting to establish the websocket connection') sleep(1) conn_timeout -= 1 return ws except: ws = None self.logger.error("Websocket could not be oppened.") stopping.set() return ws
def run(): try: logger = logging.getLogger(__name__) logger.debug("Hello!, please don't kill me") stopping = Event() user, password, account, entorno,db = ask_login_credentials() ws = start_ws(stopping,user=user,account=account,entorno=entorno,password=password) # Subscribe to the OrderReport messages subscribeOR(ws,account) #Subscribe to MD entries = ["LA","BI","OF","SE","OI","TV","IV"] tickers = ["RFX20Jun19","RFX20Sep19","I.RFX20","RFXP 06/09 19","DOMay19","DOJun19","DOP 05/06 19"] subscribeMD(ws,entries=entries,tickers=tickers) t = Thread(target=process,kwargs={'stopping':stopping,'db':db},name='ProcessData-Thread') t.daemon = True t.start() while True: pass except KeyboardInterrupt: stopping.set() ws.close() t.join() logger.debug("You've killed me. I'll revenge. Hasta la vista, baby")
def run(self): try: self.logger.debug("Hello!, please don't kill me") if self.user is None: self.user, self.password, self.account, self.entorno, self.db = ask_login_credentials( ) self.ws = WS(user=self.user, account=self.account, entorno=self.entorno, password=self.password, db=self.db, stopping=self.stopping, export_to_db=True) pmy.init(userParam=self.user, passwordParam=self.password, accountParam=self.account, entornoParam=self.entorno, verifyHTTPsParam=True) pmy.login() valid_instruments = pmy.instrumentos() tickers = [] instruments = [ 'RFX20', 'RFXP', 'GGAL', 'AY24', 'AO20', 'YPF', 'WTI', 'ORO', 'DO' ] for inst in valid_instruments['instruments']: ticker = inst['instrumentId']['symbol'] for s in instruments: if s in ticker: tickers.append(ticker) if not self.stopping.is_set(): # Subscribe to the OrderReport messages self.ws.subscribeOR() #Subscribe to MD entries = ["LA", "BI", "OF", "SE", "OI", "TV", "IV"] #tickers = ["RFX20Dic19","RFX20Mar20","I.RFX20","RFXP 12/03 19","DOOct19","DONov19","DOP 10/11 19","AY24Dic19","ORONov19","WTINov19","GGALOct19",'MERV - XMEV - GGAL'] self.ws.subscribeMD(entries=entries, tickers=tickers) try: while not self.stopping.is_set(): pass except KeyboardInterrupt: self.logger.debug("Clossing the botMiron") self.stopping.set() try: if self.ws is not None: self.ws.delete() except: self.logger.exception("Error killing the bot...") self.logger.info( "You've killed me. I will revenge. Hasta la vista, baby.") except: self.logger.exception("Exception in the botMiron")
def run(user=None, password=None, account=None, entorno=None, db=None): try: logger = logging.getLogger(__name__) logger.debug("Hello!, please don't kill me") stopping = Event() if user is None: user, password, account, entorno, db = ask_login_credentials() ticker, max_loss = select_ticker() ws = WS(user=user, account=account, entorno=entorno, password=password, db=db, stopping=stopping) if not stopping.is_set(): #Subscribe to the OrderReport messages ws.subscribeOR() est = FollowTheLeader(ws, account=account, ticker=ticker, stopping=stopping, max_loss=max_loss, db=db) t_est = Thread(target=est.run, name='Estrategia') t_est.daemon = True t_est.start() try: while not stopping.is_set(): pass except KeyboardInterrupt: logger.debug("Clossing the main bot app") stopping.set() try: try: t_est.join() except: pass if 'ws' in locals(): ws.delete() except: logger.exception("Error killing the bot...") logger.debug("You've killed me. I will revenge. Hasta la vista, baby.") except: logger.exception("Exception in the botFTL")
def run(): try: logger = logging.getLogger(__name__) logger.debug("Hello!, please don't kill me") stopping = Event() user, password, account, entorno, db = ask_login_credentials() ws = start_ws(stopping, user=user, account=account, entorno=entorno, password=password) #Subscribe to the OrderReport messages subscribeOR(ws, account) ticker_spot = "I.RFX20" ticker_futuro = "RFX20Jun19" fecha_vto = '28-06-2019' t_est = Thread(target=estrategia, kwargs={ 'ws': ws, 'ticker_spot': ticker_spot, 'ticker_futuro': ticker_futuro, 'fecha_vto': fecha_vto, 'account': account, 'stopping': stopping, 'db': db }, name='BandasTasaStrategy') t_est.daemon = True t_est.start() while True: pass except KeyboardInterrupt: stopping.set() t_est.join() ws.close() logger.debug("You've killed me. I will revenge. Hasta la vista, baby.")
def run(): try: logger = logging.getLogger(__name__) logger.debug("Hello!, please don't kill me") stopping = Event() user, password, account, entorno, db = ask_login_credentials() ticker, max_loss = select_ticker() ws = start_ws(stopping, user=user, account=account, entorno=entorno, password=password) #Subscribe to the OrderReport messages subscribeOR(ws, account) t_est = Thread(target=estrategia, kwargs={ 'ws': ws, 'ticker': ticker, 'stopping': stopping, 'max_loss': max_loss, 'account': account, 'db': db }, name='Estrategia-Thread') t_est.daemon = True t_est.start() while True: pass except KeyboardInterrupt: stopping.set() t_est.join() ws.close() logger.debug("You've killed me. I will revenge. Hasta la vista, baby.")