Skip to main content

Welcome to pyRofex’s Documentation

Overview

pyRofex is a python library that allows interactions with ROFEX’s Rest and Websocket APIs.

The library is designed to avoid developers hours of research and coding needed to connect with ROFEX APIs, so they could focused on the important part of their software.

Although, we recommend to take a look at the official API documentation to get familiarize with the API Responses and functionality.

Warning

pyRofex will only work with the websocket-client version between 0.54.0 and 0.57.0

Installing

pyRofex is available at the Python Package Index repository. Install and update using pip:

pip install -U pyRofex

API Credentials

In order to use the library you need to have the correct authentication credentials for the environment.

To get new credentials:

Dependencies

Features

This sections describe the functionality and components of the library.

Available methods

Initialization

Before you start using the library, you need to initialize the environment that you want to connect with.

Functions
  • initialize: Initialize the specified environment. Set the default user, password and account for the environment.

  • set_default_environment: Set default environment. The default environment that is going to be used when no environment is specified.

Rest

The library provides functions to make requests to the REST API and return the corresponding response.

Functions
  • get_segments: gets a list of valid segments.

  • get_instruments: gets data of instruments by passing arguments for specific info.

  • get_all_instruments: gets a list of all available instruments.

  • get_detailed_instruments: gets a detailed list of all available instruments.

  • get_instrument_details: gets the details of a single instrument.

  • get_market_data: gets market data information for an instrument.

  • get_trade_history: gets a list of historic trades for an instrument.

  • send_order: sends a new order to the Market.

  • cancel_order: cancels an order.

  • get_order_status: gets the status of the specified order.

  • get_all_orders_status: gets the status of all the orders associated with an account.

  • get_account_position: gets the status of the account positions.

  • get_detailed_position: gets the status of detailed account asset positions by asset type.

  • get_account_report: gets the summary of associated account.

All functions return a dict of the JSON response.

Websocket

The library allows users to start a connection to the websocket API. The connection will be monitored by a separated thread, so its very important to set the proper handlers to process new incoming messages.

Functions
  • init_websocket_connection: configure the Websocket Client with the handlers and then start a Websocket connection with API.

  • close_websocket_connection: close the connection with the API.

  • market_data_subscription: sends a Market Data Subscription Message through the connection.

  • order_report_subscription: sends an Order Report Subscription Message through the connection.

  • add_websocket_market_data_handler **: adds a new Market Data handler to the Websocket Client. This handler is going to be call when a new Market Data Message is received.

  • remove_websocket_market_data_handler **: removes a Market Data handler from the handlers list in the Websocket Client.

  • add_websocket_order_report_handler **: adds a new Order Report handler to the Websocket Client. This handler is going to be call when a new Order Report Message is received.

  • remove_websocket_order_report_handler **: removes an Order Report handler from the handlers list in the Websocket Client.

  • add_websocket_error_handler **: adds a new Error handler to the Websocket Client. This handler is going to be call when a new Error Message is received.

  • remove_websocket_error_handler **: removes an Error handler from the handlers list in the Websocket Client.

  • set_websocket_exception_handler: sets an exception handler to the Websocket Client. This handler is going to be called when an Exception occurred in the client.

  • send_order_via_websocket: sends a new order to the Market.

  • cancel_order_via_websocket: cancels an order.

** handlers are pythons functions that will be call whenever the specific event occurred.

Enumerations

The library also provides some enumerations to help developers avoid errors and improve readability. Next, you have the list of available enums:

  • Environment: Identifies the environment to use. (REMARKET: Demo environment; LIVE: Production environment)

  • CFICode: Identifies the type of instrument.

  • MarketDataEntry: Identifies market data entries for an instrument.

  • Market: Market ID associated to the instruments.

  • MarketSegment: Market Segment ID associated to the instruments.

  • OrderType: Identifies the different order types.

  • Side: Identifies the side of an order.

  • TimeInForce: Time modifier of the order that defines the time the order will be active.

How to use it

Once the library is install, we import and initialize it.

The initialization sets the user, password and account to the environment specified. Then, try to authenticate with the given user/password.

If the authentication fails, an ApiException is raised.

Finally, sets the environment as the default one. (you can change it with the set_default_environment function)

import pyRofex

# Set the the parameter for the REMARKET environment
pyRofex.initialize(user="sampleUser",
                   password="samplePassword",
                   account="sampleAccount",
                   environment=pyRofex.Environment.REMARKET)

# In case you have a previously generated and active token, you will be able to do the following
pyRofex.initialize(user="sampleUser",
                   password="samplePassword",
                   account="sampleAccount",
                   environment=pyRofex.Environment.REMARKET,
                   active_token="activeToken")

Rest

# Makes a request to the Rest API and get the last price
# Use the MarketDataEntry enum to specify the data
pyRofex.get_market_data(ticker="DLR/DIC23",
                        entries=[pyRofex.MarketDataEntry.LAST])

# Gets all segments
pyRofex.get_segments()

# Gets available instruments list
pyRofex.get_all_instruments()

# Alternative option to get all available instruments list
pyRofex.get_instruments('all')

# Alternative option to get instruments by given cfi code:
pyRofex.get_instruments('by_cfi',
                        cfi_code=[pyRofex.CFICode.STOCK,
                                  pyRofex.CFICode.BOND,
                                  pyRofex.CFICode.CEDEAR])

# Alternative option to get instruments by given segments
pyRofex.get_instruments('by_segments',
                        market=pyRofex.Market.ROFEX,
                        market_segment=[pyRofex.MarketSegment.DDF,
                                        pyRofex.MarketSegment.MERV])

# Gets detailed instruments list
pyRofex.get_detailed_instruments()

# Alternative option to get detailed instruments list
pyRofex.get_instruments('details')

# Get all order report for the configured account
pyRofex.get_all_orders_status()

# Gets historic trades
pyRofex.get_trade_history(ticker="DLR/JUN23",
                          start_date="2018-12-01",
                          end_date="2019-01-10")

# Sends a Limit order to the market
order = pyRofex.send_order(ticker="DLR/DIC23",
                           side=pyRofex.Side.BUY,
                           size=10,
                           price=55.8,
                           order_type=pyRofex.OrderType.LIMIT)

# Gets the last order status for the previous order
pyRofex.get_order_status(order["order"]["clientId"])

# Cancels the previous order
cancel_order = pyRofex.cancel_order(order["order"]["clientId"])

# Checks the order status of the cancellation order
pyRofex.get_order_status(cancel_order["order"]["clientId"])

Websocket

# First we define the handlers that will process the messages and exceptions.
def market_data_handler(message):
    print("Market Data Message Received: {0}".format(message))
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,
                                  order_report_handler=order_report_handler,
                                  error_handler=error_handler,
                                  exception_handler=exception_handler)

# Instruments list to subscribe
instruments = ["DLR/DIC23", "DLR/ENE24"]
# 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()

** Every time a new message is received, the correct handler will be call.

Official API Documentation

For more detailed information about ROFEX Rest and Websocket APIs go to the Primary API Documentation.

Acknowledgements

Development of this software was driven by Primary as part of an Open Source initiative of Grupo Rofex.

Author/Maintainer

Metadata

Release files for pyRofex 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyRofex 0.5.0
File Size Uploaded Provenance
pyRofex-0.5.0.tar.gz 22.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pyRofex 0.5.0
File Interpreter ABI Platform
pyRofex-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 45.0 kB

Release files / pyRofex-0.5.0.tar.gz

Download URL pyRofex-0.5.0.tar.gz
Size 22.2 kB
Tags Source
SHA-256 checksum
How to use checksums
7f23b065849c2c25753279bc3fae9d6770d6302856f2f6a65d15e8f8849857f4
BLAKE2b-256 checksum
How to use checksums
04cc3feb14c9f92b1a6771ff299a56b3c56fe5ded0e7caf47d46669ea592fad5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / pyRofex-0.5.0-py3-none-any.whl

Download URL pyRofex-0.5.0-py3-none-any.whl
Size 22.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b3fe24a1ac21045bf5d3d1623a13e62a77055faaf77d31b09d0d88330c805b87
BLAKE2b-256 checksum
How to use checksums
a20328878acceb1fe7635a8f31363798cb225fe9fb2b2bf52ee99484c7f2efe1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Security for pyRofex 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page