Ejemplo n.º 1
0
    def cancel_order(self, ClOrdId):
        # TODO implement

        if logging.getLevelName('DEBUG') > 1:
            logging.debug(
                f'ROFEXClient: Sending cancel message for order {ClOrdId}')

        try:
            cancel_order = pyRofex.cancel_order(ClOrdId)

            lk.acquire()
            print(dash_line)
            print(f"----------- Cancel Order Response: ".ljust(width, '-'))
            pprint(cancel_order)
            lk.release()

            order_status = pyRofex.get_order_status(ClOrdId)
            lk.acquire()
            print(dash_line)
            print(f"----------- Cancel Order Status Response: ".ljust(
                width, '-'))
            pprint(order_status)
            lk.release()

        except Exception as e:
            if logging.getLevelName('DEBUG') > 1:
                logging.debug(f'ROFEXClient ERROR: En exception occurred {e}')

            error_msg = "\033[0;30;47mERROR: Check log file for detailed error message.\033[1;37;40m"
            print(error_msg)
            print(dash_line)
def send_buy_order(ticker, price, qty):
    order = pyRofex.send_order(ticker=ticker,
                               side=pyRofex.Side.BUY,
                               size=qty,
                               price=price,
                               order_type=pyRofex.OrderType.LIMIT)

    print("Send Order Response:")
    pprint.pprint(order)
    order_status = pyRofex.get_order_status(order["order"]["clientId"])
    print("Order Status Response:")
    pprint.pprint(order_status)
Ejemplo n.º 3
0
def performBid(md):
    simbolo = md['instrumentId']['symbol']
    if hasBids(md):
        bidAmount = hasBids(md) - 0.01
    else:
        bidAmount = ORDER_FIXED_AMOUNT
    order = pyRofex.send_order(ticker=simbolo,
                               side=pyRofex.Side.BUY,
                               size=1,
                               price=bidAmount,
                               order_type=pyRofex.OrderType.LIMIT)
    orderStatus = pyRofex.get_order_status(order["order"]["clientId"])
    if orderStatus['status'] == 'OK':
        return orderStatus
    else:
        return False
Ejemplo n.º 4
0
    def get_ingresar_orden(self, buy):
        cont = 0
        self.print('Consultando BID')
        try:
            md = pyRofex.get_market_data(
                ticker=self.date_symbol,
                entries=[pyRofex.MarketDataEntry.BIDS])
        except Exception as e:
            self.print('Error al buscar BIDs : {}'.format(e))
            logging.error('Error al buscar BIDs : {}'.format(e))

        if md["marketData"]["BI"][0]["price"]:
            self.print('Precio de BID: ${}'.format(
                str(round(md["marketData"]["BI"][0]["price"],
                          2)).replace('.', ',')))
            entrada = round(
                float(md["marketData"]["BI"][0]["price"]) - 0.01, 2)
        else:
            self.print('No hay BIDs activos')
            entrada = float(buy)

        order = pyRofex.send_order(ticker=self.date_symbol,
                                   side=pyRofex.Side.BUY,
                                   size=1,
                                   price=entrada,
                                   order_type=pyRofex.OrderType.LIMIT)

        if order['status'] == 'ERROR':
            self.print('Error al realizar una órden: {}'.format(
                order['description']))
            return False

        order_status = pyRofex.get_order_status(order["order"]["clientId"])

        while True:
            if order_status["order"]['status'] == 'NEW':
                self.print('Ingresando orden a ${}'.format(entrada))
                return True
            else:
                # TODO: control de errores para otros posibles estados
                time.sleep(1)
                cont += 1

            if cont == self.timeout:
                self.print('Orden cancelada por TIMEOUT')
                return False
Ejemplo n.º 5
0
    def placer_order(self, ticker, order_side, order_price, order_qty):
        # TODO implement
        # TODO Atento al parametro cancel_previous

        if order_side.lower() == 'buy':
            order_side = pyRofex.Side.BUY
        elif order_side.lower() == 'sell':
            order_side = pyRofex.side.BUY
        else:
            raise IncorrectOrderSide

        if logging.getLevelName('DEBUG') > 1:
            logging.debug(
                f'ROFEXClient: Sending {str(order_side).split(".")[-1]} order.'
            )

        try:
            order = pyRofex.send_order(ticker=ticker,
                                       side=order_side,
                                       size=order_qty,
                                       price=order_price,
                                       order_type=pyRofex.OrderType.LIMIT)
            lk.acquire()
            print(dash_line)
            print(f"----------- Send Order Response: ".ljust(width, '-'))
            pprint(order)
            active_orders.append(order)
            lk.release()

            order_status = pyRofex.get_order_status(order["order"]["clientId"])
            lk.acquire()
            print(dash_line)
            print(f"----------- Order Status Response: ".ljust(width, '-'))
            pprint(order_status)
            lk.release()

        except Exception as e:
            if logging.getLevelName('DEBUG') > 1:
                logging.debug(f'ROFEXClient ERROR: En exception occurred {e}')

            error_msg = "\033[0;30;47mERROR: Check log file for detailed error message.\033[1;37;40m"
            print(error_msg)
            print(dash_line)
Ejemplo n.º 6
0
# Print the response
print("Market Data Response: {0}".format(md))

# 3-Send a Buy Limit Order for DODic19 with the same price as the best bid
order = pyRofex.send_order(ticker="DODic19",
                           side=pyRofex.Side.BUY,
                           size=10,
                           price=md["marketData"]["BI"][0]["price"],
                           order_type=pyRofex.OrderType.LIMIT)

# Print the response
print("Send Order Response: {0}".format(order))

# 4-Check the order status
order_status = pyRofex.get_order_status(order["order"]["clientId"])

# Print the response
print("Order Status Response: {0}".format(order_status))

# 5-If order status is PENDING_NEW then we keep checking the status until
# the market accept or reject the order or timeout is reach
timeout = 5  # Time out 5 seconds

while order_status["order"]["status"] == "PENDING_NEW" and timeout > 0:
    time.sleep(1)
    order_status = pyRofex.get_order_status(order["order"]["clientId"])

    # Print Order Status
    print("Recheck Order Status Response: {0}".format(order_status))
Ejemplo n.º 7
0
 def get_order_status(self, order):
     """ returns order status"""
     return pyRofex.get_order_status(order["order"]["clientId"])
Ejemplo n.º 8
0
        if OF == []:
            print("No hay BIDs activos")

            #genero una orden por 81.5 centavos
            order = pyRofex.send_order(ticker=ticker,
                                       side=pyRofex.Side.BUY,
                                       size=10,
                                       price=81.5,
                                       order_type=pyRofex.OrderType.LIMIT)

            # Imprimo la respuesta de la orden
            print("Resultado de la orden: {0}".format(order["status"]))

            # Reviso el estado de la orden
            order_status = pyRofex.get_order_status(order["order"]["clientId"])

            # Imprimo el estado de la orden
            print("Estado de la orden: {0}".format(order_status["status"]))

            # si el estado de la orden es PENDING_NEW entonces sigo verificanto el estado
            # hasta que el mercado acepte o rechace la orden o se alcance el tiempo maximo

            timeout = 5  # Time out 5 segundos

            while order_status["order"][
                    "status"] == "PENDING_NEW" and timeout > 0:
                time.sleep(1)
                order_status = pyRofex.get_order_status(
                    order["order"]["clientId"])