metaapi-cloud-copyfactory-sdk


Namemetaapi-cloud-copyfactory-sdk JSON
Version 9.0.1 PyPI version JSON
download
home_pagehttps://github.com/metaapi/metaapi-copyfactory-python-sdk
SummaryPython SDK for SDK for CopyFactory trade copying API. Can copy trades both between MetaTrader 5 (MT5) and MetaTrader 4 (MT4). (https://metaapi.cloud)
upload_time2024-01-06 06:33:17
maintainer
docs_urlNone
authorMetaApi DMCC
requires_python>=3.8
licenseSEE LICENSE IN LICENSE
keywords metaapi.cloud metatrader metatrader 5 metatrader 4 metatrader5 metatrader4 mt mt4 mt5 forex copy trading api rest client sdk cloud
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            CopyFactory trade copying API for Python (a member of `metaapi.cloud <https://metaapi.cloud>`_ project)
#######################################################################################################

CopyFactory is a powerful trade copying API which makes developing forex
trade copying applications as easy as writing few lines of code.

CopyFactory 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 we offer a free tier for testing and personal use.

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.

Why do we offer CopyFactory API trade copying API
=================================================

We found that developing reliable and flexible trade copier is a task
which requires lots of effort, because developers have to solve a series
of complex technical tasks to create a product.

We decided to share our product as it allows developers to start with a
powerful solution in almost no time, saving on development and
infrastructure maintenance costs.

Frequently asked questions (FAQ)
================================

FAQ is located here: `https://metaapi.cloud/docs/copyfactory/faq/ <http://metaapi.cloud/docs/copyfactory/faq/>`_

CopyFactory copytrading API features
====================================

Features supported:

- low latency trade copying API
- reliable trade copying API
- suitable for large-scale deployments
- suitable for large number of subscribers
- connect arbitrary number of strategy providers and subscribers
- subscribe accounts to multiple strategies at once
- select arbitrary copy ratio for each subscription
- configure symbol mapping between strategy providers and subscribers
- apply advanced risk filters on strategy provider side
- override risk filters on subscriber side
- provide multiple strategies from a single account based on magic or symbol filters
- supports manual trading on subscriber accounts while copying trades
- synchronize subscriber account with strategy providers
- monitor trading history
- calculate trade copying commissions for account managers
- support portfolio strategies as trading signal source, i.e. the strategies which include signals of several other strategies (also known as combos on some platforms)

Please note that trade copying to MT5 netting accounts is not supported in the current API version

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

REST API documentation
======================

CopyFactory SDK is built on top of CopyFactory REST API.

CopyFactory REST API docs are available at `https://metaapi.cloud/docs/copyfactory/ <https://metaapi.cloud/docs/copyfactory/>`_

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

We published some code examples in our github repository, namely:

- Python: `https://github.com/metaapi/metaapi-copyfactory-python-sdk/tree/master/examples <https://github.com/metaapi/metaapi-copyfactory-python-sdk/tree/master/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 trade copying
=========================

In order to configure trade copying you need to:

- add MetaApi MetaTrader accounts with CopyFactory as application field value (see above)
- create CopyFactory master and slave accounts and connect them to MetaApi accounts via connectionId field
- create a strategy being copied
- subscribe slave CopyFactory accounts to the strategy

.. code-block:: python

    from metaapi_cloud_sdk import MetaApi, CopyFactory

    token = '...'
    metaapi = MetaApi(token=token)
    copy_factory = CopyFactory(token=token)

    # retrieve MetaApi MetaTrader accounts with CopyFactory as application field value
    # master account must have PROVIDER value in copyFactoryRoles
    master_metaapi_account = await metaapi.metatrader_account_api.get_account(account_id='masterMetaapiAccountId')
    if (master_metaapi_account is None) or master_metaapi_account.copy_factory_roles is None or 'PROVIDER' not \
            in master_metaapi_account.copy_factory_roles:
        raise Exception('Please specify PROVIDER copyFactoryRoles value in your MetaApi '
                        'account in order to use it in CopyFactory API')
    # slave account must have SUBSCRIBER value in copyFactoryRoles
    slave_metaapi_account = await metaapi.metatrader_account_api.get_account(account_id='slaveMetaapiAccountId')
    if (slave_metaapi_account is None) or slave_metaapi_account.copy_factory_roles is None or 'SUBSCRIBER' not \
            in slave_metaapi_account.copy_factory_roles:
        raise Exception('Please specify SUBSCRIBER copyFactoryRoles value in your MetaApi '
                        'account in order to use it in CopyFactory API')

    configuration_api = copy_factory.configuration_api

    # create a strategy being copied
    strategy_id = await configuration_api.generate_strategy_id()
    await configuration_api.update_strategy(id=strategy_id['id'], strategy={
        'name': 'Test strategy',
        'description': 'Some useful description about your strategy',
        'accountId': master_metaapi_account.id,
        'maxTradeRisk': 0.1,
        'stopOutRisk': {
            'value': 0.4,
            'startTime': '2020-08-24T00:00:00.000Z'
        },
        'timeSettings': {
            'lifetimeInHours': 192,
            'openingIntervalInMinutes': 5
        }
    })

    # subscribe slave CopyFactory accounts to the strategy
    await configuration_api.update_subscriber(slave_metaapi_account.id, {
        'name': 'Demo account',
        'subscriptions': [
            {
                'strategyId': strategy_id['id'],
                'multiplier': 1
            }
        ]
    })


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

Retrieving paginated lists
==========================

There are two groups of methods to retrieve paginated lists:

- with pagination in infinite scroll style
- with pagination in a classic style which allows you to calculate page count

They are applied to following entities:

- strategies: ``get_strategies_with_infinite_scroll_pagination`` and ``get_strategies_with_classic_pagination``
- provider portfolios: ``get_portfolio_strategies_with_infinite_scroll_pagination`` and ``get_portfolio_strategies_with_classic_pagination``
- subscribers: ``get_subscribers_with_infinite_scroll_pagination`` and ``get_subscribers_with_classic_pagination``

Example of retrieving strategies with pagination in infinite scroll style:

.. code-block:: python

    # paginate strategies, see in-code documentation for full list of filter options available.
    strategies = await api.metatrader_account_api.get_strategies_with_infinite_scroll_pagination(
        {'limit': 10, 'offset': 0}
    )

    # get strategies without filter (returns 1000 strategies max)
    strategies = await api.metatrader_account_api.get_strategies_with_infinite_scroll_pagination()
    strategy = None

    for s in strategies:
        if s['_id'] == 'strategyId':
            strategy = s
            break

Example of retrieving strategies with pagination in classic style:

.. code-block:: python

    # paginate strategies, see in-code documentation for full list of filter options available.
    strategies = await api.metatrader_account_api.get_strategies_with_classic_pagination({'limit': 10, 'offset': 0})
    strategy = None

    for s in strategies:
        if s['_id'] == 'strategyId':
            strategy = s
            break
    # number of all strategies matching filter without pagination options
    print(strategies['count'])

    # get strategies without filter (returns 1000 strategies max)
    strategies = await api.metatrader_account_api.get_strategies_with_classic_pagination()

Retrieving trade copying history
================================

CopyFactory allows you to monitor transactions conducted on trading accounts in real time.

Retrieving trading history on provider side
-------------------------------------------

.. code-block:: python

    history_api = copy_factory.history_api

    # retrieve trading history, please note that this method support pagination and limits number of records
    print(await history_api.get_provided_transactions(time_from=datetime.fromisoformat('2020-08-01'),
        time_till=datetime.fromisoformat('2020-09-01')))


Retrieving trading history on subscriber side
---------------------------------------------

.. code-block:: python

    history_api = copy_factory.history_api

    # retrieve trading history, please note that this method support pagination and limits number of records
    print(await history_api.get_subscription_transactions(time_from=datetime.fromisoformat('2020-08-01'),
        time_till=datetime.fromisoformat('2020-09-01')))

Resynchronizing slave accounts to masters
=========================================
There is a configurable time limit during which the trades can be opened. Sometimes trades can not open in time due to broker errors or trading session time discrepancy.
You can resynchronize a slave account to place such late trades. Please note that positions which were
closed manually on a slave account will also be reopened during resynchronization.

.. code-block:: python

    account_id = '...' # CopyFactory account id

    # resynchronize all strategies
    await copy_factory.trading_api.resynchronize(account_id=account_id)

    # resynchronize specific strategy
    await copy_factory.trading_api.resynchronize(account_id=account_id, strategy_ids=['ABCD'])

Sending external trading signals to a strategy
==============================================
You can submit external trading signals to your trading strategy.

.. code-block:: python

    trading_api = copy_factory.trading_api
    signal_id = trading_api.generate_signal_id()

    # get signal client
    signal_client = await trading_api.get_signal_client(account_id=account_id)

    # add trading signal
    await signal_client.update_external_signal(strategy_id=strategy_id, signal_id=signal_id, signal={
        'symbol': 'EURUSD',
        'type': 'POSITION_TYPE_BUY',
        'time': datetime.now(),
        'volume': 0.01
    })

    # get external signals
    print(await signal_client.get_strategy_external_signals(strategy_id))

    # remove signal
    await signal_client.remove_external_signal(strategy_id=strategy_id, signal_id=signal_id, signal={
        'time': datetime.now()
    })

Retrieving trading signals
==========================

.. code-block:: python

    subscriber_id = '...' # CopyFactory subscriber id
    signal_client = await trading_api.get_signal_client(account_id=account_id)

    # retrieve trading signals
    print(await signal_client.get_trading_signals(subscriber_id))

Managing stopouts
=================
A subscription to a strategy can be stopped if the strategy have exceeded allowed risk limit.

.. code-block:: python

    trading_api = copy_factory.trading_api
    account_id = '...' # CopyFactory account id
    strategy_id = '...' # CopyFactory strategy id

    # retrieve list of strategy stopouts
    print(await trading_api.get_stopouts(account_id=account_id))

    # reset a stopout so that subscription can continue
    await trading_api.reset_subscription_stopouts(account_id=account_id, strategy_id=strategy_id, reason='daily-equity')

Managing stopout listeners
==========================
You can subscribe to a stream of stopout events using the stopout listener.

.. code-block:: python

    from metaapi_cloud_sdk import StopoutListener

    trading_api = copy_factory.trading_api

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

        # specify the function called on event arrival
        async def on_stopout(self, strategy_stopout_event):
            print('Strategy stopout event', strategy_stopout_event)

        # specify the function called on error event
        async def on_error(self, error):
            print('Error event', error)

    # add listener
    listener = Listener()
    listener_id = trading_api.add_stopout_listener(listener)

    # remove listener
    trading_api.remove_stopout_listener(listener_id)

Retrieving slave trading logs
=============================

.. code-block:: python

    trading_api = copy_factory.trading_api
    account_id = '...' # CopyFactory account id

    # retrieve slave trading log
    print(await trading_api.get_user_log(account_id))

    # retrieve paginated slave trading log by time range
    print(await trading_api.get_user_log(account_id, datetime.fromtimestamp(datetime.now().timestamp() - 24 * 60 * 60), None, 20, 10))

Log streaming
=============
You can subscribe to a stream of strategy or subscriber log events using the user log listener.

Strategy logs
-------------

.. code-block:: python

    from metaapi_cloud_sdk import UserLogListener

    trading_api = copy_factory.trading_api

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

        # specify the function called on event arrival
        async def on_user_log(self, log_event):
            print('Strategy user log event', log_event)

        # specify the function called on error event
        async def on_error(self, error):
            print('Error event', error)

    # add listener
    listener = Listener()
    listener_id = trading_api.add_strategy_log_listener(listener, 'ABCD')

    # remove listener
    trading_api.remove_strategy_log_listener(listener_id)

Subscriber logs
---------------

.. code-block:: python

    from metaapi_cloud_sdk import UserLogListener

    trading_api = copy_factory.trading_api

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

        # specify the function called on event arrival
        async def on_user_log(self, log_event):
            print('Subscriber user log event', log_event)

        # specify the function called on error event
        async def on_error(self, error):
            print('Error event', error)

    # add listener
    listener = Listener()
    listener_id = trading_api.add_subscriber_log_listener(listener, 'accountId')

    # remove listener
    trading_api.remove_subscriber_log_listener(listener_id)

Transaction streaming
=====================
You can subscribe to a stream of strategy or subscriber transaction events using the transaction listener.

Strategy transactions
---------------------

.. code-block:: python

    from metaapi_cloud_sdk import TransactionListener

    history_api = copy_factory.history_api

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

        # specify the function called on event arrival
        async def on_transaction(self, transaction_event):
            print('Strategy transaction event', transaction_event)

        # specify the function called on error event
        async def on_error(self, error):
            print('Error event', error)

    # add listener
    listener = Listener()
    listener_id = history_api.add_strategy_transaction_listener(listener, 'ABCD')

    # remove listener
    history_api.remove_strategy_transaction_listener(listener_id)

Subscriber transactions
-----------------------

.. code-block:: python

    from metaapi_cloud_sdk import TransactionListener

    history_api = copy_factory.history_api

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

        # specify the function called on event arrival
        async def on_transaction(transaction_event):
            print('Subscriber transaction event', transaction_event)

        # specify the function called on error event
        async def on_error(self, error):
            print('Error event', error)

    # add listener
    listener = Listener()
    listener_id = history_api.add_strategy_transaction_listener(listener, 'ABCD')

    # remove listener
    history_api.remove_subscriber_transaction_listener(listener_id)

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 this module:

1. MetaApi cloud forex trading API `https://metaapi.cloud/docs/client/ <https://metaapi.cloud/docs/client/>`_
2. MetaTrader account management API `https://metaapi.cloud/docs/provisioning/ <https://metaapi.cloud/docs/provisioning/>`_
3. MetaStats cloud forex trading statistics API `https://metaapi.cloud/docs/metastats/ <https://metaapi.cloud/docs/metastats/>`_
4. MetaApi MT manager API `https://metaapi.cloud/docs/manager/ <https://metaapi.cloud/docs/manager/>`_
5. MetaApi risk management API `https://metaapi.cloud/docs/risk-management/ <https://metaapi.cloud/docs/risk-management/>`_

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/metaapi/metaapi-copyfactory-python-sdk",
    "name": "metaapi-cloud-copyfactory-sdk",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "metaapi.cloud,MetaTrader,MetaTrader 5,MetaTrader 4,MetaTrader5,MetaTrader4,MT,MT4,MT5,forex,copy trading,API,REST,client,sdk,cloud",
    "author": "MetaApi DMCC",
    "author_email": "support@metaapi.cloud",
    "download_url": "https://files.pythonhosted.org/packages/31/11/774cce585929b69baccfe35a2cce84545a533acf17dc643548d1c57dd7a2/metaapi_cloud_copyfactory_sdk-9.0.1.tar.gz",
    "platform": null,
    "description": "CopyFactory trade copying API for Python (a member of `metaapi.cloud <https://metaapi.cloud>`_ project)\n#######################################################################################################\n\nCopyFactory is a powerful trade copying API which makes developing forex\ntrade copying applications as easy as writing few lines of code.\n\nCopyFactory 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 we offer a free tier for testing and personal use.\n\nThe `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\nfor hosting your own infrastructure. This is possible because over time we managed to heavily optimize\nour 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\nWhy do we offer CopyFactory API trade copying API\n=================================================\n\nWe found that developing reliable and flexible trade copier is a task\nwhich requires lots of effort, because developers have to solve a series\nof complex technical tasks to create a product.\n\nWe decided to share our product as it allows developers to start with a\npowerful solution in almost no time, saving on development and\ninfrastructure maintenance costs.\n\nFrequently asked questions (FAQ)\n================================\n\nFAQ is located here: `https://metaapi.cloud/docs/copyfactory/faq/ <http://metaapi.cloud/docs/copyfactory/faq/>`_\n\nCopyFactory copytrading API features\n====================================\n\nFeatures supported:\n\n- low latency trade copying API\n- reliable trade copying API\n- suitable for large-scale deployments\n- suitable for large number of subscribers\n- connect arbitrary number of strategy providers and subscribers\n- subscribe accounts to multiple strategies at once\n- select arbitrary copy ratio for each subscription\n- configure symbol mapping between strategy providers and subscribers\n- apply advanced risk filters on strategy provider side\n- override risk filters on subscriber side\n- provide multiple strategies from a single account based on magic or symbol filters\n- supports manual trading on subscriber accounts while copying trades\n- synchronize subscriber account with strategy providers\n- monitor trading history\n- calculate trade copying commissions for account managers\n- support portfolio strategies as trading signal source, i.e. the strategies which include signals of several other strategies (also known as combos on some platforms)\n\nPlease note that trade copying to MT5 netting accounts is not supported in the current API version\n\nPlease check Features section of the `https://metaapi.cloud/docs/copyfactory/ <https://metaapi.cloud/docs/copyfactory/>`_\ndocumentation for detailed description of all settings you can make.\n\nREST API documentation\n======================\n\nCopyFactory SDK is built on top of CopyFactory REST API.\n\nCopyFactory REST API docs are available at `https://metaapi.cloud/docs/copyfactory/ <https://metaapi.cloud/docs/copyfactory/>`_\n\nCode examples\n=============\n\nWe published some code examples in our github repository, namely:\n\n- Python: `https://github.com/metaapi/metaapi-copyfactory-python-sdk/tree/master/examples <https://github.com/metaapi/metaapi-copyfactory-python-sdk/tree/master/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 trade copying\n=========================\n\nIn order to configure trade copying you need to:\n\n- add MetaApi MetaTrader accounts with CopyFactory as application field value (see above)\n- create CopyFactory master and slave accounts and connect them to MetaApi accounts via connectionId field\n- create a strategy being copied\n- subscribe slave CopyFactory accounts to the strategy\n\n.. code-block:: python\n\n    from metaapi_cloud_sdk import MetaApi, CopyFactory\n\n    token = '...'\n    metaapi = MetaApi(token=token)\n    copy_factory = CopyFactory(token=token)\n\n    # retrieve MetaApi MetaTrader accounts with CopyFactory as application field value\n    # master account must have PROVIDER value in copyFactoryRoles\n    master_metaapi_account = await metaapi.metatrader_account_api.get_account(account_id='masterMetaapiAccountId')\n    if (master_metaapi_account is None) or master_metaapi_account.copy_factory_roles is None or 'PROVIDER' not \\\n            in master_metaapi_account.copy_factory_roles:\n        raise Exception('Please specify PROVIDER copyFactoryRoles value in your MetaApi '\n                        'account in order to use it in CopyFactory API')\n    # slave account must have SUBSCRIBER value in copyFactoryRoles\n    slave_metaapi_account = await metaapi.metatrader_account_api.get_account(account_id='slaveMetaapiAccountId')\n    if (slave_metaapi_account is None) or slave_metaapi_account.copy_factory_roles is None or 'SUBSCRIBER' not \\\n            in slave_metaapi_account.copy_factory_roles:\n        raise Exception('Please specify SUBSCRIBER copyFactoryRoles value in your MetaApi '\n                        'account in order to use it in CopyFactory API')\n\n    configuration_api = copy_factory.configuration_api\n\n    # create a strategy being copied\n    strategy_id = await configuration_api.generate_strategy_id()\n    await configuration_api.update_strategy(id=strategy_id['id'], strategy={\n        'name': 'Test strategy',\n        'description': 'Some useful description about your strategy',\n        'accountId': master_metaapi_account.id,\n        'maxTradeRisk': 0.1,\n        'stopOutRisk': {\n            'value': 0.4,\n            'startTime': '2020-08-24T00:00:00.000Z'\n        },\n        'timeSettings': {\n            'lifetimeInHours': 192,\n            'openingIntervalInMinutes': 5\n        }\n    })\n\n    # subscribe slave CopyFactory accounts to the strategy\n    await configuration_api.update_subscriber(slave_metaapi_account.id, {\n        'name': 'Demo account',\n        'subscriptions': [\n            {\n                'strategyId': strategy_id['id'],\n                'multiplier': 1\n            }\n        ]\n    })\n\n\nSee in-code documentation for full definition of possible configuration options.\n\nRetrieving paginated lists\n==========================\n\nThere are two groups of methods to retrieve paginated lists:\n\n- with pagination in infinite scroll style\n- with pagination in a classic style which allows you to calculate page count\n\nThey are applied to following entities:\n\n- strategies: ``get_strategies_with_infinite_scroll_pagination`` and ``get_strategies_with_classic_pagination``\n- provider portfolios: ``get_portfolio_strategies_with_infinite_scroll_pagination`` and ``get_portfolio_strategies_with_classic_pagination``\n- subscribers: ``get_subscribers_with_infinite_scroll_pagination`` and ``get_subscribers_with_classic_pagination``\n\nExample of retrieving strategies with pagination in infinite scroll style:\n\n.. code-block:: python\n\n    # paginate strategies, see in-code documentation for full list of filter options available.\n    strategies = await api.metatrader_account_api.get_strategies_with_infinite_scroll_pagination(\n        {'limit': 10, 'offset': 0}\n    )\n\n    # get strategies without filter (returns 1000 strategies max)\n    strategies = await api.metatrader_account_api.get_strategies_with_infinite_scroll_pagination()\n    strategy = None\n\n    for s in strategies:\n        if s['_id'] == 'strategyId':\n            strategy = s\n            break\n\nExample of retrieving strategies with pagination in classic style:\n\n.. code-block:: python\n\n    # paginate strategies, see in-code documentation for full list of filter options available.\n    strategies = await api.metatrader_account_api.get_strategies_with_classic_pagination({'limit': 10, 'offset': 0})\n    strategy = None\n\n    for s in strategies:\n        if s['_id'] == 'strategyId':\n            strategy = s\n            break\n    # number of all strategies matching filter without pagination options\n    print(strategies['count'])\n\n    # get strategies without filter (returns 1000 strategies max)\n    strategies = await api.metatrader_account_api.get_strategies_with_classic_pagination()\n\nRetrieving trade copying history\n================================\n\nCopyFactory allows you to monitor transactions conducted on trading accounts in real time.\n\nRetrieving trading history on provider side\n-------------------------------------------\n\n.. code-block:: python\n\n    history_api = copy_factory.history_api\n\n    # retrieve trading history, please note that this method support pagination and limits number of records\n    print(await history_api.get_provided_transactions(time_from=datetime.fromisoformat('2020-08-01'),\n        time_till=datetime.fromisoformat('2020-09-01')))\n\n\nRetrieving trading history on subscriber side\n---------------------------------------------\n\n.. code-block:: python\n\n    history_api = copy_factory.history_api\n\n    # retrieve trading history, please note that this method support pagination and limits number of records\n    print(await history_api.get_subscription_transactions(time_from=datetime.fromisoformat('2020-08-01'),\n        time_till=datetime.fromisoformat('2020-09-01')))\n\nResynchronizing slave accounts to masters\n=========================================\nThere is a configurable time limit during which the trades can be opened. Sometimes trades can not open in time due to broker errors or trading session time discrepancy.\nYou can resynchronize a slave account to place such late trades. Please note that positions which were\nclosed manually on a slave account will also be reopened during resynchronization.\n\n.. code-block:: python\n\n    account_id = '...' # CopyFactory account id\n\n    # resynchronize all strategies\n    await copy_factory.trading_api.resynchronize(account_id=account_id)\n\n    # resynchronize specific strategy\n    await copy_factory.trading_api.resynchronize(account_id=account_id, strategy_ids=['ABCD'])\n\nSending external trading signals to a strategy\n==============================================\nYou can submit external trading signals to your trading strategy.\n\n.. code-block:: python\n\n    trading_api = copy_factory.trading_api\n    signal_id = trading_api.generate_signal_id()\n\n    # get signal client\n    signal_client = await trading_api.get_signal_client(account_id=account_id)\n\n    # add trading signal\n    await signal_client.update_external_signal(strategy_id=strategy_id, signal_id=signal_id, signal={\n        'symbol': 'EURUSD',\n        'type': 'POSITION_TYPE_BUY',\n        'time': datetime.now(),\n        'volume': 0.01\n    })\n\n    # get external signals\n    print(await signal_client.get_strategy_external_signals(strategy_id))\n\n    # remove signal\n    await signal_client.remove_external_signal(strategy_id=strategy_id, signal_id=signal_id, signal={\n        'time': datetime.now()\n    })\n\nRetrieving trading signals\n==========================\n\n.. code-block:: python\n\n    subscriber_id = '...' # CopyFactory subscriber id\n    signal_client = await trading_api.get_signal_client(account_id=account_id)\n\n    # retrieve trading signals\n    print(await signal_client.get_trading_signals(subscriber_id))\n\nManaging stopouts\n=================\nA subscription to a strategy can be stopped if the strategy have exceeded allowed risk limit.\n\n.. code-block:: python\n\n    trading_api = copy_factory.trading_api\n    account_id = '...' # CopyFactory account id\n    strategy_id = '...' # CopyFactory strategy id\n\n    # retrieve list of strategy stopouts\n    print(await trading_api.get_stopouts(account_id=account_id))\n\n    # reset a stopout so that subscription can continue\n    await trading_api.reset_subscription_stopouts(account_id=account_id, strategy_id=strategy_id, reason='daily-equity')\n\nManaging stopout listeners\n==========================\nYou can subscribe to a stream of stopout events using the stopout listener.\n\n.. code-block:: python\n\n    from metaapi_cloud_sdk import StopoutListener\n\n    trading_api = copy_factory.trading_api\n\n    # create a custom class based on the StopoutListener\n    class Listener(StopoutListener):\n\n        # specify the function called on event arrival\n        async def on_stopout(self, strategy_stopout_event):\n            print('Strategy stopout event', strategy_stopout_event)\n\n        # specify the function called on error event\n        async def on_error(self, error):\n            print('Error event', error)\n\n    # add listener\n    listener = Listener()\n    listener_id = trading_api.add_stopout_listener(listener)\n\n    # remove listener\n    trading_api.remove_stopout_listener(listener_id)\n\nRetrieving slave trading logs\n=============================\n\n.. code-block:: python\n\n    trading_api = copy_factory.trading_api\n    account_id = '...' # CopyFactory account id\n\n    # retrieve slave trading log\n    print(await trading_api.get_user_log(account_id))\n\n    # retrieve paginated slave trading log by time range\n    print(await trading_api.get_user_log(account_id, datetime.fromtimestamp(datetime.now().timestamp() - 24 * 60 * 60), None, 20, 10))\n\nLog streaming\n=============\nYou can subscribe to a stream of strategy or subscriber log events using the user log listener.\n\nStrategy logs\n-------------\n\n.. code-block:: python\n\n    from metaapi_cloud_sdk import UserLogListener\n\n    trading_api = copy_factory.trading_api\n\n    # create a custom class based on the UserLogListener\n    class Listener(UserLogListener):\n\n        # specify the function called on event arrival\n        async def on_user_log(self, log_event):\n            print('Strategy user log event', log_event)\n\n        # specify the function called on error event\n        async def on_error(self, error):\n            print('Error event', error)\n\n    # add listener\n    listener = Listener()\n    listener_id = trading_api.add_strategy_log_listener(listener, 'ABCD')\n\n    # remove listener\n    trading_api.remove_strategy_log_listener(listener_id)\n\nSubscriber logs\n---------------\n\n.. code-block:: python\n\n    from metaapi_cloud_sdk import UserLogListener\n\n    trading_api = copy_factory.trading_api\n\n    # create a custom class based on the UserLogListener\n    class Listener(UserLogListener):\n\n        # specify the function called on event arrival\n        async def on_user_log(self, log_event):\n            print('Subscriber user log event', log_event)\n\n        # specify the function called on error event\n        async def on_error(self, error):\n            print('Error event', error)\n\n    # add listener\n    listener = Listener()\n    listener_id = trading_api.add_subscriber_log_listener(listener, 'accountId')\n\n    # remove listener\n    trading_api.remove_subscriber_log_listener(listener_id)\n\nTransaction streaming\n=====================\nYou can subscribe to a stream of strategy or subscriber transaction events using the transaction listener.\n\nStrategy transactions\n---------------------\n\n.. code-block:: python\n\n    from metaapi_cloud_sdk import TransactionListener\n\n    history_api = copy_factory.history_api\n\n    # create a custom class based on the TransactionListener\n    class Listener(TransactionListener):\n\n        # specify the function called on event arrival\n        async def on_transaction(self, transaction_event):\n            print('Strategy transaction event', transaction_event)\n\n        # specify the function called on error event\n        async def on_error(self, error):\n            print('Error event', error)\n\n    # add listener\n    listener = Listener()\n    listener_id = history_api.add_strategy_transaction_listener(listener, 'ABCD')\n\n    # remove listener\n    history_api.remove_strategy_transaction_listener(listener_id)\n\nSubscriber transactions\n-----------------------\n\n.. code-block:: python\n\n    from metaapi_cloud_sdk import TransactionListener\n\n    history_api = copy_factory.history_api\n\n    # create a custom class based on the TransactionListener\n    class Listener(TransactionListener):\n\n        # specify the function called on event arrival\n        async def on_transaction(transaction_event):\n            print('Subscriber transaction event', transaction_event)\n\n        # specify the function called on error event\n        async def on_error(self, error):\n            print('Error event', error)\n\n    # add listener\n    listener = Listener()\n    listener_id = history_api.add_strategy_transaction_listener(listener, 'ABCD')\n\n    # remove listener\n    history_api.remove_subscriber_transaction_listener(listener_id)\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 this module:\n\n1. MetaApi cloud forex trading API `https://metaapi.cloud/docs/client/ <https://metaapi.cloud/docs/client/>`_\n2. MetaTrader account management API `https://metaapi.cloud/docs/provisioning/ <https://metaapi.cloud/docs/provisioning/>`_\n3. MetaStats cloud forex trading statistics API `https://metaapi.cloud/docs/metastats/ <https://metaapi.cloud/docs/metastats/>`_\n4. MetaApi MT manager API `https://metaapi.cloud/docs/manager/ <https://metaapi.cloud/docs/manager/>`_\n5. MetaApi risk management API `https://metaapi.cloud/docs/risk-management/ <https://metaapi.cloud/docs/risk-management/>`_\n",
    "bugtrack_url": null,
    "license": "SEE LICENSE IN LICENSE",
    "summary": "Python SDK for SDK for CopyFactory trade copying API. Can copy trades both between MetaTrader 5 (MT5) and MetaTrader 4 (MT4). (https://metaapi.cloud)",
    "version": "9.0.1",
    "project_urls": {
        "Homepage": "https://github.com/metaapi/metaapi-copyfactory-python-sdk"
    },
    "split_keywords": [
        "metaapi.cloud",
        "metatrader",
        "metatrader 5",
        "metatrader 4",
        "metatrader5",
        "metatrader4",
        "mt",
        "mt4",
        "mt5",
        "forex",
        "copy trading",
        "api",
        "rest",
        "client",
        "sdk",
        "cloud"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3111774cce585929b69baccfe35a2cce84545a533acf17dc643548d1c57dd7a2",
                "md5": "54a7a2232397f3123b228dc1f22c8cd1",
                "sha256": "3121cabfcf9e1aa24b317a31a73cf1f9fcb881537f04a91fabb50ce8a0264029"
            },
            "downloads": -1,
            "filename": "metaapi_cloud_copyfactory_sdk-9.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "54a7a2232397f3123b228dc1f22c8cd1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 48042,
            "upload_time": "2024-01-06T06:33:17",
            "upload_time_iso_8601": "2024-01-06T06:33:17.143195Z",
            "url": "https://files.pythonhosted.org/packages/31/11/774cce585929b69baccfe35a2cce84545a533acf17dc643548d1c57dd7a2/metaapi_cloud_copyfactory_sdk-9.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-06 06:33:17",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "metaapi",
    "github_project": "metaapi-copyfactory-python-sdk",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "metaapi-cloud-copyfactory-sdk"
}
        
Elapsed time: 0.17194s