def logout(): print("Cerrando sesion de Remarkets") try: pyRofex.close_websocket_connection() except: print("Error al cerrar sesion") sys.exit()
def disconnect(self): """ Terminates Connection to ROFEX DMA Server. """ if logging.getLevelName('DEBUG') > 1: logging.debug(f'ROFEXClient: Disconnecting.') print(dash_line) message = f'Terminating connection' print(message.center(width)) print(dash_line) pyRofex.close_websocket_connection() sys.exit(0)
def error_handler(message): print("Error Message Received: {0}".format(message)) def exception_handler(e): print("Exception Occurred: {0}".format(e.message)) # 3-Initialize Websocket Connection with the handlers pyRofex.init_websocket_connection(order_report_handler=order_report_handler, error_handler=error_handler, exception_handler=exception_handler) # 4-Subscribes to receive order report for the default account pyRofex.order_report_subscription() # 5-Subscribes to an invalid account pyRofex.order_report_subscription(account="InvalidAccount") # 6-Send an order to check that order_report_handler is called pyRofex.send_order(ticker="DODic19", side=pyRofex.Side.BUY, size=10, order_type=pyRofex.OrderType.MARKET) # 7-Wait 5 sec then close the connection time.sleep(1) pyRofex.close_websocket_connection()
def error_handler(message): # print("Error Message Received: {0}".format(message)) if message['status'] == 'ERROR' and "don't exist" in message['description']: print("Símbolo Inválido") print("Cerrando sesión en Remarkets") pyRofex.close_websocket_connection()
def market_data_handler(message): # print("Market Data Message Received: {0}".format(message)) print("Consultando símbolo") performOperation(message) print("Cerrando sesión en Remarkets") pyRofex.close_websocket_connection()
def close_connection(): print("Cerrando sesión en Remarkets") pyRofex.close_websocket_connection()
def iniciar(ticker2, REMARKETS_USER, REMARKET_PASS, REMARKET_ACCOUNT): def error_handler(message): print("Simbolo invalido") def market_data_handler(message): print("se ha reportado una solicutud al market data") def exception_handler(e): print("Exception Ocurred") def order_report_handler(message): print("se ha reportado una orden") print("~$ python challenge.py ", ticker2, " -u ", REMARKETS_USER, " -p ", REMARKET_PASS) print("Iniciando sesion en Remarket") # bloque try/except para autencticacion de password try: pyRofex.initialize(user=REMARKETS_USER, password=REMARKET_PASS, account=REMARKET_ACCOUNT, environment=pyRofex.Environment.REMARKET) except: print("Error de autenticacion") print("~$") print("por favor vuelva a ingresar sus credenciales") exit() else: pyRofex.init_websocket_connection( market_data_handler=market_data_handler, error_handler=error_handler, order_report_handler=order_report_handler, exception_handler=exception_handler) print("Consultando simbolo") md = pyRofex.get_market_data( ticker=ticker2, entries=[pyRofex.MarketDataEntry.BIDS, pyRofex.MarketDataEntry.LAST]) # capturar el key error de market data try: lp = md["marketData"]["LA"]["price"] except KeyError: print("Símbolo inválido") else: lp = md["marketData"]["LA"]["price"] print("Último precio operado: $", lp) print("consultando BID") try: md["marketData"]["BI"][0]["price"] except KeyError: # In this case, replace the constant value of 75.25 by a value that when talking about the September dollar the value is 75.25 in the bid offered. # But if we talk about another asset (another instrument) this remains at a competitive value for supply / demand. pyRofex.send_order(ticker=ticker2, side=pyRofex.Side.BUY, size=1, price=lp - 0.91, order_type=pyRofex.OrderType.LIMIT) print("No hay Bids Activos") bido = lp - 0.91 print("ingresando orden :$", bido) else: pyRofex.send_order(ticker=ticker2, side=pyRofex.Side.BUY, size=1, price=md["marketData"]["BI"][0]["price"] - 0.01, order_type=pyRofex.OrderType.LIMIT) bid = md["marketData"]["BI"][0]["price"] bido = bid - 0.01 print("Precio de BID: $", bid) print("ingresando orden :$", bido) print("cerrando sesion en Remarket") time.sleep(5) pyRofex.close_websocket_connection() print("~$")