Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Javascript SDK for CopyFactory trade copying API. Can copy trades both between MetaTrader 5 (MT5) and MetaTrader 4 (MT4)

License

NotificationsYou must be signed in to change notification settings

agiliumtrade-ai/copyfactory-javascript-sdk

Repository files navigation

CopyFactory is a powerful copy trading 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), 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.

TheMetaApi pricing was developed with the intent to make your charges less or equal to what you would have to payfor hosting your own infrastructure. This is possible because over time we managed to heavily optimizeour MetaTrader infrastructure. And with MetaApi you can save significantly on application development andmaintenance costs and time thanks to high-quality API, open-source SDKs and convenience of a cloud service.

Why do we offer CopyFactory trade copying API

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

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

Frequently asked questions (FAQ)

FAQ is located here:https://metaapi.cloud/docs/copyfactory/faq/

CopyFactory copytradging 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 thehttps://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 athttps://metaapi.cloud/docs/copyfactory/

FAQ

Please check this page for FAQ:https://metaapi.cloud/docs/copyfactory/faq/.

Code examples

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

  • #"https://github.com/agiliumtrade-ai/copyfactory-javascript-sdk/tree/master/examples">https://github.com/agiliumtrade-ai/copyfactory-javascript-sdk/tree/master/examples

Installation

npm install --save metaapi.cloud-sdk

Installing SDK in browser SPA applications

npm install --save metaapi.cloud-sdk

Installing SDK in browser HTML applications

<scriptsrc="unpkg.com/metaapi.cloud-sdk/index.js"></script><script>consttoken='...';constapi=newCopyFactory(token);</script>

Retrieving API token

Please visithttps://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
importMetaApi,{CopyFactory}from'metaapi.cloud-sdk';consttoken='...';constmetaapi=newMetaApi(token);constcopyFactory=newCopyFactory(token);// retrieve MetaApi MetaTrader accounts with CopyFactory as application field value// master account must have PROVIDER value in copyFactoryRolesconstmasterMetaapiAccount=awaitapi.metatraderAccountApi.getAccount('masterMetaapiAccountId');if(!masterMetaapiAccount.copyFactoryRoles||!masterMetaapiAccount.copyFactoryRoles.includes('PROVIDER')){thrownewError('Please specify PROVIDER copyFactoryRoles value in your MetaApi account in '+'order to use it in CopyFactory API');}// slave account must have SUBSCRIBER value in copyFactoryRolesconstslaveMetaapiAccount=awaitapi.metatraderAccountApi.getAccount('slaveMetaapiAccountId');if(!slaveMetaapiAccount.copyFactoryRoles||!slaveMetaapiAccount.copyFactoryRoles.includes('SUBSCRIBER')){thrownewError('Please specify SUBSCRIBER copyFactoryRoles value in your MetaApi account in '+'order to use it in CopyFactory API');}letconfigurationApi=copyFactory.configurationApi;// create a strategy being copiedletstrategyId=awaitconfigurationApi.generateStrategyId();awaitconfigurationApi.updateStrategy(strategyId.id,{name:'Test strategy',description:'Some useful description about your strategy',accountId:masterMetaapiAccount.id,maxTradeRisk:0.1,timeSettings:{lifetimeInHours:192,openingIntervalInMinutes:5}});// subscribe slave CopyFactory accounts to the strategyawaitconfigurationApi.updateSubscriber(slaveMetaapiAccount.id,{name:'Demo account',subscriptions:[{strategyId:strategyId.id,multiplier:1}]});// retrieve list of strategiesconsole.log(awaitconfigurationApi.getStrategies())// retrieve list of provider portfoliosconsole.log(awaitconfigurationApi.getPortfolioStrategies())// retrieve list of subscribersconsole.log(awaitconfigurationApi.getSubscribers())

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

Retrieving trade copying history

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

Retrieving trading history on provider side

lethistoryApi=copyFactory.historyApi;// retrieve trading history, please note that this method support pagination and limits number of recordsconsole.log(awaithistoryApi.getProvidedTransactions(newDate('2020-08-01'),newDate('2020-09-01')));

Retrieving trading history on subscriber side

lethistoryApi=copyFactory.historyApi;// retrieve trading history, please note that this method support pagination and limits number of recordsconsole.log(awaithistoryApi.getSubscriptionTransactions(newDate('2020-08-01'),newDate('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 wereclosed manually on a slave account will also be reopened during resynchronization.

letaccountId='...';// CopyFactory account id// resynchronize all strategiesawaitcopyFactory.tradingApi.resynchronize(accountId);// resynchronize specific strategyawaitcopyFactory.tradingApi.resynchronize(accountId,['ABCD']);

Sending external trading signals to a strategy

You can submit external trading signals to your trading strategy.

constaccountId='...';consttradingApi=copyFactory.tradingApi;constsignalId='...';// get signal clientconstsignalClient=awaittradingApi.getSignalClient(accountId);// add trading signalawaitsignalClient.updateExternalSignal(strategyId,signalId,{symbol:'EURUSD',type:'POSITION_TYPE_BUY',time:newDate(),volume:0.01});// get external signalsconsole.log(awaitsignalClient.getStrategyExternalSignals(strategyId));// remove signalawaitsignalClient.removeExternalSignal(strategyId,signalId,{time:newDate()});

Retrieving trading signals

constaccountId='...';constsignalClient=awaittradingApi.getSignalClient(accountId);// retrieve trading signalsconsole.log(awaitsignalClient.getTradingSignals());

Managing stopouts

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

lettradingApi=copyFactory.tradingApi;letaccountId='...';// CopyFactory account idletstrategyId='...';// CopyFactory strategy id// retrieve list of strategy stopoutsconsole.log(awaittradingApi.getStopouts(accountId));// reset a stopout so that subscription can continueawaittradingApi.resetSubscriptionStopouts(accountId,strategyId,'daily-equity');

Managing stopout listeners

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

import{StopoutListener}from'metaapi.cloud-sdk';lettradingApi=copyFactory.tradingApi;// create a custom class based on the StopoutListenerclassListenerextendsStopoutListener{// specify the function called on event arrivalasynconStopout(strategyStopoutEvent){console.log('Strategy stopout event',strategyStopoutEvent);}// specify the function called on error eventasynconError(error){console.log('Error event',error);}}// add listenerconstlistener=newListener();constlistenerId=tradingApi.addStopoutListener(listener);// remove listenertradingApi.removeStopoutListener(listenerId);

Retrieving slave trading logs

lettradingApi=copyFactory.tradingApi;letaccountId='...';// CopyFactory account id// retrieve slave trading logconsole.log(awaittradingApi.getUserLog(accountId));// retrieve paginated slave trading log by time rangeconsole.log(awaittradingApi.getUserLog(accountId,newDate(Date.now()-24*60*60*1000),undefined,20,10));

Log streaming

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

Strategy logs

import{UserLogListener}from'metaapi.cloud-sdk';lettradingApi=copyFactory.tradingApi;// create a custom class based on the UserLogListenerclassListenerextendsUserLogListener{// specify the function called on event arrivalasynconUserLog(logEvent){console.log('Strategy user log event',logEvent);}// specify the function called on error eventasynconError(error){console.log('Error event',error);}}// add listenerconstlistener=newListener();constlistenerId=tradingApi.addStrategyLogListener(listener,'ABCD');// remove listenertradingApi.removeStrategyLogListener(listenerId);

Subscriber logs

import{UserLogListener}from'metaapi.cloud-sdk';lettradingApi=copyFactory.tradingApi;// create a custom class based on the UserLogListenerclassListenerextendsUserLogListener{// specify the function called on event arrivalasynconUserLog(logEvent){console.log('Subscriber user log event',logEvent);}// specify the function called on error eventasynconError(error){console.log('Error event',error);}}// add listenerconstlistener=newListener();constlistenerId=tradingApi.addSubscriberLogListener(listener,'accountId');// remove listenertradingApi.removeSubscriberLogListener(listenerId);

Transaction streaming

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

Strategy transactions

import{TransactionListener}from'metaapi.cloud-sdk';lethistoryApi=copyFactory.historyApi;// create a custom class based on the TransactionListenerclassListenerextendsTransactionListener{// specify the function called on event arrivalasynconTransaction(transactionEvent){console.log('Strategy transaction event',transactionEvent);}// specify the function called on error eventasynconError(error){console.log('Error event',error);}}// add listenerconstlistener=newListener();constlistenerId=historyApi.addStrategyTransactionListener(listener,'ABCD');// remove listenerhistoryApi.removeStrategyTransactionListener(listenerId);

Subscriber transactions

import{TransactionListener}from'metaapi.cloud-sdk';lethistoryApi=copyFactory.historyApi;// create a custom class based on the TransactionListenerclassListenerextendsTransactionListener{// specify the function called on event arrivalasynconTransaction(transactionEvent){console.log('Subscriber transaction event',transactionEvent);}// specify the function called on error eventasynconError(error){console.log('Error event',error);}}// add listenerconstlistener=newListener();constlistenerId=historyApi.addSubscriberTransactionListener(listener,'accountId');// remove listenerhistoryApi.removeSubscriberTransactionListener(listenerId);

Related projects:

Take a look at our website for the full list of APIs and features supportedhttps://metaapi.cloud/#features

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

  1. MetaApi cloud forex APIhttps://metaapi.cloud/docs/client/
  2. MetaTrader account management APIhttps://metaapi.cloud/docs/provisioning/
  3. MetaStats forex trading metrics APIhttps://metaapi.cloud/docs/metastats/
  4. MetaApi MT manager APIhttps://metaapi.cloud/docs/manager/
  5. MetaApi risk management APIhttps://metaapi.cloud/docs/risk-management/

About

Javascript SDK for CopyFactory trade copying API. Can copy trades both between MetaTrader 5 (MT5) and MetaTrader 4 (MT4)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp