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