コード例 #1
0
ファイル: 6_MM_Strategy.py プロジェクト: pjseoane/pyRofex
    def __init__(self, instrument, size, spread):
        # Define variables
        self.instrument = instrument
        self.comision = 0
        self.initial_size = size
        self.buy_size = size
        self.sell_size = size
        self.spread = spread
        self.tick = 0.001
        self.my_order = dict()
        self.last_md = None
        self.state = States.WAITING_MARKET_DATA

        # Initialize the environment
        pyRofex.initialize(user="******",
                           password="******",
                           account="XXXXXXX",
                           environment=pyRofex.Environment.REMARKET)

        # Initialize Websocket Connection with the handler
        pyRofex.init_websocket_connection(
            market_data_handler=self.market_data_handler,
            order_report_handler=self.order_report_handler)

        # Subscribes for Market Data
        pyRofex.market_data_subscription(tickers=[self.instrument],
                                         entries=[
                                             pyRofex.MarketDataEntry.BIDS,
                                             pyRofex.MarketDataEntry.OFFERS
                                         ])

        # Subscribes to receive order report for the default account
        pyRofex.order_report_subscription()
コード例 #2
0
def open_connection():
    pyRofex.init_websocket_connection(market_data_handler=market_data_handler,
                                      error_handler=error_handler,
                                      exception_handler=exception_handler)

    instruments = [args.ticker]
    entries = [pyRofex.MarketDataEntry.BIDS, pyRofex.MarketDataEntry.LAST]
    print("Consultando símbolo")
    pyRofex.market_data_subscription(tickers=instruments, entries=entries)
    pyRofex.market_data_subscription(tickers=["InvalidInstrument"],
                                     entries=entries)
コード例 #3
0
ファイル: rofexclient.py プロジェクト: fedeturi/finance
    def connect(self, user, password, account, environment):
        """
        Implements Connection to ROFEX DMA Server.
        (demo = reMarkets; live = ROFEX)
        Initializes environment and WebSocket Connection
            :param user: User.
            :type user: Str.
            :param password: User Password.
            :type password: Str.
            :param account: Account provided by Market Authority.
            :type account: Str.
            :param environment: Market environment.
            :type environment: Str.
        """

        clear_screen()
        print(dash_line)
        message = f'Connecting to {environment} DMA server'
        print(message.center(width))
        print(dash_line)

        if logging.getLevelName('DEBUG') > 1:
            logging.debug(
                f'ROFEXClient: Starting connection to {environment} DMA Server '
            )
        try:
            # Initialize Environment
            pyRofex.initialize(user=user,
                               password=password,
                               account=account,
                               environment=environment)

            # Initialize WebSocket Cnnection with Handlers

            pyRofex.init_websocket_connection(
                market_data_handler=self.market_data_handler,
                error_handler=self.error_handler,
                exception_handler=self.exception_handler)
        except Exception as e:
            if logging.getLevelName('DEBUG') > 1:
                logging.debug(f'ROFEXClient ERROR: En exception occurred {e}')

            error_msg = "\033[0;30;47mERROR: CONNECTION ERROR. Check log file " \
                        "for detailed error message.\033[1;37;40m"
            print(error_msg)
            print(dash_line)
コード例 #4
0
# 2-Defines the handlers that will process the messages and exceptions.
def order_report_handler(message):
    print("Order Report Message Received: {0}".format(message))


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
コード例 #5
0
def order_report_handler(message):
    print("Order Report Message Received: {0}".format(message))


def error_handler(message):
    print("Error Message Received: {0}".format(message))


def exception_handler(e):
    print("Exception Occurred: {0}".format(e.message))


# Initiate Websocket Connection
pyRofex.init_websocket_connection(market_data_handler=market_data_handler,
                                  error_handler=error_handler,
                                  exception_handler=exception_handler)

# Instruments list to subscribe
instruments = ["RFX20Sep20", "I.RFX20"]
# Uses the MarketDataEntry enum to define the entries we want to subscribe to
entries = [
    pyRofex.MarketDataEntry.BIDS, pyRofex.MarketDataEntry.OFFERS,
    pyRofex.MarketDataEntry.LAST
]

# Subscribes to receive market data messages **
pyRofex.market_data_subscription(tickers=instruments, entries=entries)

# Subscribes to receive order report messages (default account will be used) **
pyRofex.order_report_subscription()
コード例 #6
0
        plt.pause(0.2)


# Defines the handlers that will process the messages
def market_data_handler(message):
    global prices
    print("Market Data Message Received: {0}".format(message))
    last = None if not message["marketData"]["LA"] else message["marketData"]["LA"]["price"]
    prices.loc[datetime.fromtimestamp(message["timestamp"]/1000)] = [
        message["marketData"]["BI"][0]["price"],
        message["marketData"]["OF"][0]["price"],
        last
    ]


# Initialize Websocket Connection with the handlers
pyRofex.init_websocket_connection(market_data_handler=market_data_handler)


# Subscribes to receive market data messages
pyRofex.market_data_subscription(
    tickers=[instrument],
    entries=[
        pyRofex.MarketDataEntry.BIDS,
        pyRofex.MarketDataEntry.OFFERS,
        pyRofex.MarketDataEntry.LAST]
)

while True:
    update_plot()
    time.sleep(0.5)
コード例 #7
0
def order_report_handler(message):
    pass


def order_error_handler(message):
    print("Error Message Received: {0}".format(message))


def order_exception_handler(e):
    print("Exception Occurred: {0}".format(e.message))


pyRofex.init_websocket_connection(
    market_data_handler=market_data_handler,
    error_handler=error_handler,
    exception_handler=exception_handler,
    order_report_handler=order_report_handler,
)

entries = [
    pyRofex.MarketDataEntry.BIDS, pyRofex.MarketDataEntry.OFFERS,
    pyRofex.MarketDataEntry.LAST, pyRofex.MarketDataEntry.OPENING_PRICE,
    pyRofex.MarketDataEntry.CLOSING_PRICE, pyRofex.MarketDataEntry.HIGH_PRICE,
    pyRofex.MarketDataEntry.LOW_PRICE, pyRofex.MarketDataEntry.TRADE_VOLUME,
    pyRofex.MarketDataEntry.NOMINAL_VOLUME,
    pyRofex.MarketDataEntry.TRADE_EFFECTIVE_VOLUME
]

pyRofex.market_data_subscription(tickers=instruments, entries=entries, depth=5)
# pyRofex.order_report_subscription()
コード例 #8
0
print("Iniciando sesion en Remarkets")
try:
    pyRofex.initialize(
        user=sys.argv[3],
        password=sys.argv[5],
        account=sys.argv[7],
        environment = pyRofex.Environment.REMARKET)
except:
    print("Usuario y/o contraseña incorrectos")
    sys.exit()



# Inicializo la conexion Websocket
try:
    pyRofex.init_websocket_connection()
except:
    print("Error al establecer una conexion websocket")
    sys.exit()



#Obtengo la MARKET_DATA
print("Consultando simbolo")
md = pyRofex.get_market_data(instrumento, [pyRofex.MarketDataEntry.BIDS,
                                           pyRofex.MarketDataEntry.LAST])


#Check del simbolo
if md["status"] == "ERROR" and md["description"] == "Security {0}:ROFX doesn't exist".format(instrumento):
    print("Simbilo invalido")
コード例 #9
0
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("~$")