metaapi-cloud-risk-management-sdk


Namemetaapi-cloud-risk-management-sdk JSON
Version 2.0.2 PyPI version JSON
download
home_pagehttps://github.com/metaapi/metaapi-risk-management-python-sdk
SummaryPython SDK for MetaApi risk management API. Can execute trading risk restrictions, forex challenges and competitions in a cloud on both MetaTrader 5 (MT5) and MetaTrader 4 (MT4) (https://metaapi.cloud)
upload_time2024-01-04 13:53:20
maintainer
docs_urlNone
authorMetaApi DMCC
requires_python>=3.6
licenseSEE LICENSE IN LICENSE
keywords metaapi.cloud metatrader metatrader 5 metatrader 4 metatrader5 metatrader4 mt mt4 mt5 forex equity tracking risk management api rest client sdk cloud ftmo prop trading proprietary trading
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            MetaApi risk management API for Python (a member of `metaapi.cloud <https://metaapi.cloud>`_ project)
#####################################################################################################

MetaApi risk management API is a member of MetaApi project (`https://metaapi.cloud <https://metaapi.cloud>`_),
a powerful cloud forex trading API which supports both MetaTrader 4 and MetaTrader 5 platforms.

MetaApi is a paid service, however API access to one MetaTrader account is free of charge.

The `MetaApi pricing <https://metaapi.cloud/#pricing>`_ was developed with the intent to make your charges less or equal
to what you would have to pay for hosting your own infrastructure. This is possible because over time we managed to heavily
optimize our MetaTrader infrastructure. And with MetaApi you can save significantly on application development and
maintenance costs and time thanks to high-quality API, open-source SDKs and convenience of a cloud service.

This SDK requires a 3.8+ version of Python to run.

MetaApi risk management API features
=====================================

Features supported:

- tracking equity drawdown API
- manage arbitrary number of trackers with different periods
- retrieving drawdown events with REST API or streaming
- retrieving drawdown statistics
- retrieving equity charts

Please check Features section of the `https://metaapi.cloud/docs/risk-management/ <https://metaapi.cloud/docs/risk-management/>`_
documentation for detailed description of all settings you can make.

FAQ
===

Please check this page for FAQ: `https://metaapi.cloud/docs/risk-management/faq/ <https://metaapi.cloud/docs/risk-management/faq/>`_.

Code examples
=============

Please check examples folder for code examples.

Installation
============

.. code-block:: bash

    pip install metaapi-cloud-sdk

Retrieving API token
====================

Please visit `https://app.metaapi.cloud/token <https://app.metaapi.cloud/token>`_ web UI to obtain your API token.

Configuring equity tracking
===========================

In order to configure equity tracking you need to:

- add MetaApi MetaTrader accounts with `riskManagementApiEnabled` field set to true (see below)
- create equity trackers for the accounts with needed parameters

.. code-block:: python

    from metaapi_cloud_sdk import MetaApi, RiskManagement

    token = '...'
    metaapi = MetaApi(token=token)
    risk_management = RiskManagement(token=token)

    # retrieve MetaApi MetaTrader accounts with riskManagementApiEnabled field set to true
    account = await api.metatrader_account_api.get_account(account_id='accountId')
    if not account.risk_management_api_enabled:
        raise Exception('Please set riskManagementApiEnabled field to true in your MetaApi account in ' +
            'order to use it in RiskManagement API')

    risk_management_api = risk_management.risk_management_api

    # create a tracker
    tracker_id = await risk_management_api.create_drawdown_tracker('accountId', {
        'name': 'Test tracker',
        'period': 'day',
        'absoluteDrawdownThreshold': 100
    })

    # retrieve list of trackers
    print(await risk_management_api.get_drawdown_trackers('accountId'))

    # retrieve a tracker by name
    print(await risk_management_api.get_drawdown_tracker_by_name('accountId', 'Test tracker'))

    # update a tracker
    print(await risk_management_api.update_drawdown_tracker('accountId', tracker_id['id'], {'name': 'Updated name'}))

    # remove a tracker
    print(await risk_management_api.delete_drawdown_tracker('accountId', tracker_id['id']))

See in-code documentation for full definition of possible configuration options.

Retrieving equity tracking events and statistics
================================================

RiskManagement allows you to monitor equity drawdowns on trading accounts.

Retrieving drawdown events
--------------------------
.. code-block:: python

    # retrieve drawdown events, please note that this method supports filtering by broker time range, account_id, tracker_id
    # and limits number of records
    print(await risk_management_api.get_drawdown_events('2022-04-13 09:30:00.000', '2022-05-14 09:30:00.000'))

Streaming drawdown events
-------------------------

You can subscribe to a stream of drawdown events using the drawdown listener.

.. code-block:: python

    from metaapi_cloud_sdk import DrawdownListener

    # create a custom class based on the DrawdownListener
    class Listener(DrawdownListener):

        # specify the function called on events arrival
        async def on_drawdown(drawdown_event):
            print('Drawdown event', drawdown_event)

    # add listener
    listener = Listener()
    listener_id = risk_management_api.add_drawdown_listener(listener)

    # remove listener
    risk_management_api.remove_drawdown_listener(listener_id)

Retrieving drawdown statistics
------------------------------
.. code-block:: python

    # retrieve drawdown statistics, please note that this method can filter returned data and supports pagination
    print(await risk_management_api.get_drawdown_statistics('accountId', tracker_id['id']))

Retrieving equity chart
------------------------------
.. code-block:: python

    # retrieve equity chart, please note that this method supports loading within specified broker time
    print(await risk_management_api.get_equity_chart('accountId'))

Related projects:
=================

See our website for the full list of APIs and features supported `https://metaapi.cloud/#features <https://metaapi.cloud/#features>`_

Some of the APIs you might decide to use together with risk management API are:

1. MetaApi cloud forex trading API `https://metaapi.cloud/docs/client/ <https://metaapi.cloud/docs/client/>`_
2. MetaStats cloud forex trading statistics API `https://metaapi.cloud/docs/metastats/ <https://metaapi.cloud/docs/metastats/>`_
3. CopyFactory copy trading  API `https://metaapi.cloud/docs/copyfactory/ <https://metaapi.cloud/docs/copyfactory/>`_
4. MetaStats forex trading metrics API `https://metaapi.cloud/docs/metastats/ <https://metaapi.cloud/docs/metastats/>`_
5. MetaApi MT manager API `https://metaapi.cloud/docs/manager/ <https://metaapi.cloud/docs/manager/>`_

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/metaapi/metaapi-risk-management-python-sdk",
    "name": "metaapi-cloud-risk-management-sdk",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "metaapi.cloud,MetaTrader,MetaTrader 5,MetaTrader 4,MetaTrader5,MetaTrader4,MT,MT4,MT5,forex,equity tracking,risk management,API,REST,client,sdk,cloud,ftmo,prop trading,proprietary trading",
    "author": "MetaApi DMCC",
    "author_email": "support@metaapi.cloud",
    "download_url": "https://files.pythonhosted.org/packages/d1/e7/dc1a10988a71b48b0fcd8924d7a7e8ffdbae511938233596c12174738877/metaapi_cloud_risk_management_sdk-2.0.2.tar.gz",
    "platform": null,
    "description": "MetaApi risk management API for Python (a member of `metaapi.cloud <https://metaapi.cloud>`_ project)\n#####################################################################################################\n\nMetaApi risk management API is a member of MetaApi project (`https://metaapi.cloud <https://metaapi.cloud>`_),\na powerful cloud forex trading API which supports both MetaTrader 4 and MetaTrader 5 platforms.\n\nMetaApi is a paid service, however API access to one MetaTrader account is free of charge.\n\nThe `MetaApi pricing <https://metaapi.cloud/#pricing>`_ was developed with the intent to make your charges less or equal\nto what you would have to pay for hosting your own infrastructure. This is possible because over time we managed to heavily\noptimize our MetaTrader infrastructure. And with MetaApi you can save significantly on application development and\nmaintenance costs and time thanks to high-quality API, open-source SDKs and convenience of a cloud service.\n\nThis SDK requires a 3.8+ version of Python to run.\n\nMetaApi risk management API features\n=====================================\n\nFeatures supported:\n\n- tracking equity drawdown API\n- manage arbitrary number of trackers with different periods\n- retrieving drawdown events with REST API or streaming\n- retrieving drawdown statistics\n- retrieving equity charts\n\nPlease check Features section of the `https://metaapi.cloud/docs/risk-management/ <https://metaapi.cloud/docs/risk-management/>`_\ndocumentation for detailed description of all settings you can make.\n\nFAQ\n===\n\nPlease check this page for FAQ: `https://metaapi.cloud/docs/risk-management/faq/ <https://metaapi.cloud/docs/risk-management/faq/>`_.\n\nCode examples\n=============\n\nPlease check examples folder for code examples.\n\nInstallation\n============\n\n.. code-block:: bash\n\n    pip install metaapi-cloud-sdk\n\nRetrieving API token\n====================\n\nPlease visit `https://app.metaapi.cloud/token <https://app.metaapi.cloud/token>`_ web UI to obtain your API token.\n\nConfiguring equity tracking\n===========================\n\nIn order to configure equity tracking you need to:\n\n- add MetaApi MetaTrader accounts with `riskManagementApiEnabled` field set to true (see below)\n- create equity trackers for the accounts with needed parameters\n\n.. code-block:: python\n\n    from metaapi_cloud_sdk import MetaApi, RiskManagement\n\n    token = '...'\n    metaapi = MetaApi(token=token)\n    risk_management = RiskManagement(token=token)\n\n    # retrieve MetaApi MetaTrader accounts with riskManagementApiEnabled field set to true\n    account = await api.metatrader_account_api.get_account(account_id='accountId')\n    if not account.risk_management_api_enabled:\n        raise Exception('Please set riskManagementApiEnabled field to true in your MetaApi account in ' +\n            'order to use it in RiskManagement API')\n\n    risk_management_api = risk_management.risk_management_api\n\n    # create a tracker\n    tracker_id = await risk_management_api.create_drawdown_tracker('accountId', {\n        'name': 'Test tracker',\n        'period': 'day',\n        'absoluteDrawdownThreshold': 100\n    })\n\n    # retrieve list of trackers\n    print(await risk_management_api.get_drawdown_trackers('accountId'))\n\n    # retrieve a tracker by name\n    print(await risk_management_api.get_drawdown_tracker_by_name('accountId', 'Test tracker'))\n\n    # update a tracker\n    print(await risk_management_api.update_drawdown_tracker('accountId', tracker_id['id'], {'name': 'Updated name'}))\n\n    # remove a tracker\n    print(await risk_management_api.delete_drawdown_tracker('accountId', tracker_id['id']))\n\nSee in-code documentation for full definition of possible configuration options.\n\nRetrieving equity tracking events and statistics\n================================================\n\nRiskManagement allows you to monitor equity drawdowns on trading accounts.\n\nRetrieving drawdown events\n--------------------------\n.. code-block:: python\n\n    # retrieve drawdown events, please note that this method supports filtering by broker time range, account_id, tracker_id\n    # and limits number of records\n    print(await risk_management_api.get_drawdown_events('2022-04-13 09:30:00.000', '2022-05-14 09:30:00.000'))\n\nStreaming drawdown events\n-------------------------\n\nYou can subscribe to a stream of drawdown events using the drawdown listener.\n\n.. code-block:: python\n\n    from metaapi_cloud_sdk import DrawdownListener\n\n    # create a custom class based on the DrawdownListener\n    class Listener(DrawdownListener):\n\n        # specify the function called on events arrival\n        async def on_drawdown(drawdown_event):\n            print('Drawdown event', drawdown_event)\n\n    # add listener\n    listener = Listener()\n    listener_id = risk_management_api.add_drawdown_listener(listener)\n\n    # remove listener\n    risk_management_api.remove_drawdown_listener(listener_id)\n\nRetrieving drawdown statistics\n------------------------------\n.. code-block:: python\n\n    # retrieve drawdown statistics, please note that this method can filter returned data and supports pagination\n    print(await risk_management_api.get_drawdown_statistics('accountId', tracker_id['id']))\n\nRetrieving equity chart\n------------------------------\n.. code-block:: python\n\n    # retrieve equity chart, please note that this method supports loading within specified broker time\n    print(await risk_management_api.get_equity_chart('accountId'))\n\nRelated projects:\n=================\n\nSee our website for the full list of APIs and features supported `https://metaapi.cloud/#features <https://metaapi.cloud/#features>`_\n\nSome of the APIs you might decide to use together with risk management API are:\n\n1. MetaApi cloud forex trading API `https://metaapi.cloud/docs/client/ <https://metaapi.cloud/docs/client/>`_\n2. MetaStats cloud forex trading statistics API `https://metaapi.cloud/docs/metastats/ <https://metaapi.cloud/docs/metastats/>`_\n3. CopyFactory copy trading  API `https://metaapi.cloud/docs/copyfactory/ <https://metaapi.cloud/docs/copyfactory/>`_\n4. MetaStats forex trading metrics API `https://metaapi.cloud/docs/metastats/ <https://metaapi.cloud/docs/metastats/>`_\n5. MetaApi MT manager API `https://metaapi.cloud/docs/manager/ <https://metaapi.cloud/docs/manager/>`_\n",
    "bugtrack_url": null,
    "license": "SEE LICENSE IN LICENSE",
    "summary": "Python SDK for MetaApi risk management API. Can execute trading risk restrictions, forex challenges and competitions in a cloud on both MetaTrader 5 (MT5) and MetaTrader 4 (MT4) (https://metaapi.cloud)",
    "version": "2.0.2",
    "project_urls": {
        "Homepage": "https://github.com/metaapi/metaapi-risk-management-python-sdk"
    },
    "split_keywords": [
        "metaapi.cloud",
        "metatrader",
        "metatrader 5",
        "metatrader 4",
        "metatrader5",
        "metatrader4",
        "mt",
        "mt4",
        "mt5",
        "forex",
        "equity tracking",
        "risk management",
        "api",
        "rest",
        "client",
        "sdk",
        "cloud",
        "ftmo",
        "prop trading",
        "proprietary trading"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d1e7dc1a10988a71b48b0fcd8924d7a7e8ffdbae511938233596c12174738877",
                "md5": "dc407ff182a19b7f0eb3e9d4ba34ba58",
                "sha256": "205338271b2b38b27d8c80a35f3d3993a58a8d1e258077e73c4e26412c748f42"
            },
            "downloads": -1,
            "filename": "metaapi_cloud_risk_management_sdk-2.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "dc407ff182a19b7f0eb3e9d4ba34ba58",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 19133,
            "upload_time": "2024-01-04T13:53:20",
            "upload_time_iso_8601": "2024-01-04T13:53:20.328528Z",
            "url": "https://files.pythonhosted.org/packages/d1/e7/dc1a10988a71b48b0fcd8924d7a7e8ffdbae511938233596c12174738877/metaapi_cloud_risk_management_sdk-2.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-04 13:53:20",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "metaapi",
    "github_project": "metaapi-risk-management-python-sdk",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "metaapi-cloud-risk-management-sdk"
}
        
Elapsed time: 0.18848s