Package: metaapi-cloud-risk-management-sdk
MetaApi risk management API is a member of MetaApi project (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.TheMetaApi pricingwas 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 featuresFeatures supported:tracking equity drawdown APImanage arbitrary number of trackers with different periodsretrieving drawdown events with REST API or streamingretrieving drawdown statisticsretrieving equity chartsPlease check Features section of thehttps://metaapi.cloud/docs/risk-management/documentation for detailed description of all settings you can make.FAQPlease check this page for FAQ:https://metaapi.cloud/docs/risk-management/faq/.Code examplesPlease check examples folder for code examples.Installationpipinstallmetaapi-cloud-sdkRetrieving API tokenPlease visithttps://app.metaapi.cloud/tokenweb UI to obtain your API token.Configuring equity trackingIn order to configure equity tracking you need to:add MetaApi MetaTrader accounts withriskManagementApiEnabledfield set to true (see below)create equity trackers for the accounts with needed parametersfrommetaapi_cloud_sdkimportMetaApi,RiskManagementtoken='...'metaapi=MetaApi(token=token)risk_management=RiskManagement(token=token)# retrieve MetaApi MetaTrader accounts with riskManagementApiEnabled field set to trueaccount=awaitapi.metatrader_account_api.get_account(account_id='accountId')ifnotaccount.risk_management_api_enabled:raiseException('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 trackertracker_id=awaitrisk_management_api.create_drawdown_tracker('accountId',{'name':'Test tracker','period':'day','absoluteDrawdownThreshold':100})# retrieve list of trackersprint(awaitrisk_management_api.get_drawdown_trackers('accountId'))# retrieve a tracker by nameprint(awaitrisk_management_api.get_drawdown_tracker_by_name('accountId','Test tracker'))# update a trackerprint(awaitrisk_management_api.update_drawdown_tracker('accountId',tracker_id['id'],{'name':'Updated name'}))# remove a trackerprint(awaitrisk_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 statisticsRiskManagement allows you to monitor equity drawdowns on trading accounts.Retrieving drawdown events# retrieve drawdown events, please note that this method supports filtering by broker time range, account_id, tracker_id# and limits number of recordsprint(awaitrisk_management_api.get_drawdown_events('2022-04-13 09:30:00.000','2022-05-14 09:30:00.000'))Streaming drawdown eventsYou can subscribe to a stream of drawdown events using the drawdown listener.frommetaapi_cloud_sdkimportDrawdownListener# create a custom class based on the DrawdownListenerclassListener(DrawdownListener):# specify the function called on events arrivalasyncdefon_drawdown(drawdown_event):print('Drawdown event',drawdown_event)# add listenerlistener=Listener()listener_id=risk_management_api.add_drawdown_listener(listener)# remove listenerrisk_management_api.remove_drawdown_listener(listener_id)Retrieving drawdown statistics# retrieve drawdown statistics, please note that this method can filter returned data and supports paginationprint(awaitrisk_management_api.get_drawdown_statistics('accountId',tracker_id['id']))Retrieving equity chart# retrieve equity chart, please note that this method supports loading within specified broker timeprint(awaitrisk_management_api.get_equity_chart('accountId'))Related projects:See our website for the full list of APIs and features supportedhttps://metaapi.cloud/#featuresSome of the APIs you might decide to use together with risk management API are:MetaApi cloud forex trading APIhttps://metaapi.cloud/docs/client/MetaStats cloud forex trading statistics APIhttps://metaapi.cloud/docs/metastats/CopyFactory copy trading  APIhttps://metaapi.cloud/docs/copyfactory/MetaStats forex trading metrics APIhttps://metaapi.cloud/docs/metastats/MetaApi MT manager APIhttps://metaapi.cloud/docs/manager/