Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
first version
  • Loading branch information
ggallohernandez committed Oct 14, 2020
0 parents commit 72c8aa6
Show file tree
Hide file tree
Showing 21 changed files with 1,364 additions and 0 deletions.
141 changes: 141 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
# IDEs
.idea

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/
53 changes: 53 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
Primary DMA (Matriz) python connector
=====================================

Overview
--------
**pymatriz** is a python library that allows interactions with Primary DMA (Matriz) Rest and Websocket APIs.

Installing
----------
*pymatriz* is available at the `Python Package Index <https://pypi.org/project/pymatriz>`_ repository. Install and update using `pip <https://pip.pypa.io/en/stable/quickstart/>`_\ :

.. code-block::
pip install -U pyRofex
API Credentials
---------------

Credentials provided by your broker which use Primary DMA (Matriz) platform.

Usage
~~~~~~~~~~~~~~~~~
.. code::
import datetime
from pymatriz.enums import MarketDataEntry, Market
from pymatriz.matriz_api_client import MatrizAPIClient
client = MatrizAPIClient(username="", password="")
# Real-time message handling
client.add_market_data_handler(lambda msg: print(msg))
# Error handling
client.set_exception_handler(lambda e: print(e))
# Negotiate Auth Token and connects to websocket
client.connect()
# Rest API call + websocket subscription
print(client.get_daily_history(["GGAL"], terms=[MarketDataEntry.TERM_48HS], market=Market.MERVAL, start_date=datetime.date(2020, 10, 5)))
# Ends websocket connection
client.close()
Disclaimer
----------

The library is built as a result of a reverse engineering process, so use it on your own behalf.

This library is provided 'as is' without warranty of any kind, either express or implied, including, but not limited to, the implied warranties of fitness for a purpose, or the warranty of non-infringement.
43 changes: 43 additions & 0 deletions examples/advanced_logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import logging
from http.client import HTTPConnection
import websocket
import datetime
import pandas as pd
from pymatriz.enums import MarketDataEntry, Market
from pymatriz.client import MatrizAPIClient

# Rest client HTTP messages logging, adjust to logging.ERROR if you want to see full HTTP messages
log = logging.getLogger('urllib3')
log.setLevel(logging.DEBUG)

# logging from urllib3 to console
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
log.addHandler(ch)

# print statements from `http.client.HTTPConnection` to console/stdout
HTTPConnection.debuglevel = 1

# Websocket message logging
websocket.enableTrace(True)

# Set Matriz platform credentials provided by your broker
# required
username = '[email protected]'
password = 'CHANGE_ME'

pd.set_option('display.max_rows', 10)
pd.set_option('display.max_columns', None)
pd.set_option('display.width', 1000)

client = MatrizAPIClient(username=username, password=password)

client.add_market_data_handler(lambda msg: print(msg[(msg["sid"] == "MERV - XMEV - GGAL - 48hs")]) if len(msg[(msg["sid"] == "MERV - XMEV - GGAL - 48hs")]) > 0 else None)
client.set_exception_handler(lambda e: print(e))

client.connect()
df = client.get_daily_history(["GGAL", "SUPV"], terms=[MarketDataEntry.TERM_24HS, MarketDataEntry.TERM_48HS], market=Market.MERVAL, start_date=datetime.date(2020, 9, 14))

print(df)

client.close()
23 changes: 23 additions & 0 deletions examples/get_daily_history.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import datetime
import pandas as pd
from pymatriz.enums import MarketDataEntry, Market
from pymatriz.client import MatrizAPIClient

# Set Matriz platform credentials provided by your broker
# required
username = '[email protected]'
password = 'CHANGE_ME'

pd.set_option('display.max_rows', 10)
pd.set_option('display.max_columns', None)
pd.set_option('display.width', 1000)

client = MatrizAPIClient(username=username, password=password)

client.connect()

df = client.get_daily_history(["GGAL", "SUPV"], terms=[MarketDataEntry.TERM_24HS, MarketDataEntry.TERM_48HS], start_date=datetime.date(2020, 9, 14))

print(df)

client.close()
23 changes: 23 additions & 0 deletions examples/get_instruments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import datetime
import pandas as pd
from pymatriz.enums import MarketDataEntry, Market
from pymatriz.client import MatrizAPIClient

# Set Matriz platform credentials provided by your broker
# required
username = '[email protected]'
password = 'CHANGE_ME'

pd.set_option('display.max_rows', 10)
pd.set_option('display.max_columns', None)
pd.set_option('display.width', 1000)

client = MatrizAPIClient(username=username, password=password)

client.connect()

df = client.get_all_instruments()

print(df)

client.close()
25 changes: 25 additions & 0 deletions examples/real_time_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import datetime
import pandas as pd
from pymatriz.enums import MarketDataEntry, Market
from pymatriz.client import MatrizAPIClient

# Set Matriz platform credentials provided by your broker
# required
username = '[email protected]'
password = 'CHANGE_ME'

pd.set_option('display.max_rows', 10)
pd.set_option('display.max_columns', None)
pd.set_option('display.width', 1000)

client = MatrizAPIClient(username=username, password=password)

client.add_market_data_handler(lambda msg: print(msg[(msg["sid"] == "MERV - XMEV - GGAL - 48hs")]) if len(msg[(msg["sid"] == "MERV - XMEV - GGAL - 48hs")]) > 0 else None)
client.set_exception_handler(lambda e: print(e))

client.connect()

client.market_data_subscription(["GGAL"], terms=[MarketDataEntry.TERM_48HS], market=Market.MERVAL)

# Call to disconnect from websocket
# client.close()
Empty file added pymatriz/__init__.py
Empty file.
Loading

0 comments on commit 72c8aa6

Please sign in to comment.