{"id":30178776,"url":"https://github.com/huancapital/metaapi-node.js-client","last_synced_at":"2025-08-12T05:41:58.438Z","repository":{"id":295217221,"uuid":"887651126","full_name":"huancapital/metaapi-node.js-client","owner":"huancapital","description":"Metaapi Cloud","archived":false,"fork":false,"pushed_at":"2024-11-13T03:32:49.000Z","size":62,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-24T09:30:36.338Z","etag":null,"topics":["cloud","loud","metaapi"],"latest_commit_sha":null,"homepage":"https://app.metaapi.cloud/accounts","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/huancapital.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-11-13T03:31:45.000Z","updated_at":"2024-11-13T03:56:06.000Z","dependencies_parsed_at":"2025-05-29T11:31:11.785Z","dependency_job_id":null,"html_url":"https://github.com/huancapital/metaapi-node.js-client","commit_stats":null,"previous_names":["huancapital/metaapi-node.js-client"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/huancapital/metaapi-node.js-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huancapital%2Fmetaapi-node.js-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huancapital%2Fmetaapi-node.js-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huancapital%2Fmetaapi-node.js-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huancapital%2Fmetaapi-node.js-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/huancapital","download_url":"https://codeload.github.com/huancapital/metaapi-node.js-client/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huancapital%2Fmetaapi-node.js-client/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270009976,"owners_count":24511880,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-12T02:00:09.011Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloud","loud","metaapi"],"created_at":"2025-08-12T05:41:49.867Z","updated_at":"2025-08-12T05:41:58.416Z","avatar_url":"https://github.com/huancapital.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"🚨 **NOTICE** 🚨\nThis is an earlier fork of the original repository and it receives no updates. You can find the latest official version at [metaapi/metaapi-javascript-sdk](https://github.com/metaapi/metaapi-javascript-sdk).\n\n---\n\n# metaapi.cloud SDK for node.js\n\nMetaApi is a powerful API for MetaTrader 4 and MetaTrader 5 terminals.\nMetaApi is available in cloud and self-hosted options.\n\nOfficial REST and websocket API documentation: [https://metaapi.cloud/docs/client/](https://metaapi.cloud/docs/client/)\n\nPlease note that this SDK provides an abstraction over REST and websocket API to simplify your application logic.\nFor more information about SDK APIs please check esdoc documentation in source codes located inside lib folder of this npm package.\n\n## Installation\n```bash\nnpm install --save metaapi.cloud-sdk\n```\n\n## Obtaining MetaApi token\nYou can obtain MetaApi token via [https://app.metaapi.cloud/token](https://app.metaapi.cloud/token) UI.\n\n## Add MetaTrader account to MetaApi\nYou can use [https://app.metaapi.cloud/accounts](https://app.metaapi.cloud/accounts) UI to add a MetaTrader\naccount to MetaApi application. Alternatively you can use API as\ndemonstrated below.\n\n### Add MetaTrader account to MetaApi via API\n```javascript\nimport MetaApi from 'metaapi.cloud-sdk';\n\nconst token = '...';\nconst api = new MetaApi(token);\n\n// if you do not have created a provisioning profile for your broker,\n// you should do it before creating an account\nconst provisioningProfile = await api.provisioningProfileApi.createProvisioningProfile({\n  name: 'My profile',\n  type: 'standard',\n  version: 5\n});\n// servers.dat file is required for MT5 profile and can be found inside\n// config directory of your MetaTrader terminal data folder. It contains\n// information about available broker servers\nawait provisioningProfile.uploadFile('servers.dat', '/path/to/servers.dat');\n// for MT4, you should upload an .srv file instead\n// await provisioningProfile.uploadFile('broker.srv', '/path/to/broker.srv');\n\n// Alternatively you can retrieve an existing profile from API\n// const provisioningProfile = await api.provisioningProfileApi.getProvisioningProfile('profileId');\n\n// if you have not yet added your MetaTrader account, then add it\nconst account = await api.metatraderAccountApi.createAccount({\n  name: 'Trading account #1',\n  type: 'cloud',\n  login: '1234567',\n  // password can be investor password for read-only access\n  password: 'qwerty',\n  server: 'ICMarketsSC-Demo',\n  // synchronizationMode can be 'automatic' for RPC access or 'user' if you\n  // want to keep track of terminal state in real-time (e.g. if you are\n  // developing a EA or trading strategy)\n  synchronizationMode: 'automatic',\n  provisioningProfileId: provisioningProfile.id,\n  //algorithm used to parse your broker timezone. Supported values are\n  // icmarkets for America/New_York DST switch and roboforex for EET\n  // DST switch (the values will be changed soon)\n  timeConverter: 'roboforex',\n  application: 'MetaApi',\n  magic: '123456'\n});\n\n// Alternatively you can retrieve an existing account from API\n// const account = await api.metatraderAccountApi.getAccount('accountId');\n```\n\n## Access MetaTrader account via RPC API\nRPC API let you query the trading terminal state. You should use\nautomatic synchronization mode if all you need is the RPC API.\n\n```javascript\nimport MetaApi from 'metaapi.cloud-sdk';\n\nconst token = '...';\nconst api = new MetaApi(token);\n\nconst account = await api.metatraderAccountApi.getAccount('accountId');\n\nconst connection = await account.connect();\n\n// retrieve balance and equity\nconsole.log(await connection.getAccountInformation());\n// retrieve open positions\nconsole.log(await connection.getPositions());\n// retrieve a position by id\nconsole.log(await connection.getPosition('1234567'));\n// retrieve pending orders\nconsole.log(await connection.getOrders());\n// retrieve a pending order by id\nconsole.log(await connection.getOrder('1234567'));\n// retrieve history orders by ticket\nconsole.log(await connection.getHistoryOrdersByTicket('1234567'));\n// retrieve history orders by position id\nconsole.log(await connection.getHistoryOrdersByPosition('1234567'));\n// retrieve history orders by time range\nconsole.log(await connection.getHistoryOrdersByTimeRange(startTime, endTime));\n// retrieve history deals by ticket\nconsole.log(await connection.getDealsByTicket('1234567'));\n// retrieve history deals by position id\nconsole.log(await connection.getDealsByPosition('1234567'));\n// retrieve history deals by time range\nconsole.log(await connection.getDealsByTimeRange(startTime, endTime));\n\n// trade\nconsole.log(await connection.createMarketBuyOrder('GBPUSD', 0.07, 0.9, 2.0, 'comment', 'TE_GBPUSD_7hyINWqAlE'));\nconsole.log(await connection.createMarketSellOrder('GBPUSD', 0.07, 2.0, 0.9, 'comment', 'TE_GBPUSD_7hyINWqAlE'));\nconsole.log(await connection.createLimitBuyOrder('GBPUSD', 0.07, 1.0, 0.9, 2.0, 'comment', 'TE_GBPUSD_7hyINWqAlE'));\nconsole.log(await connection.createLimitSellOrder('GBPUSD', 0.07, 1.5, 2.0, 0.9, 'comment', 'TE_GBPUSD_7hyINWqAlE'));\nconsole.log(await connection.createStopBuyOrder('GBPUSD', 0.07, 1.5, 0.9, 2.0, 'comment', 'TE_GBPUSD_7hyINWqAlE'));\nconsole.log(await connection.createStopSellOrder('GBPUSD', 0.07, 1.0, 2.0, 0.9, 'comment', 'TE_GBPUSD_7hyINWqAlE'));\nconsole.log(await connection.modifyPosition('46870472', 2.0, 0.9));\nconsole.log(await connection.closePositionPartially('46870472', 0.9));\nconsole.log(await connection.closePosition('46870472'));\n// this trade type is available for MT5 netting accounts only\nconsole.log(await connection.closePositionBySymbol('EURUSD'));\nconsole.log(await connection.modifyOrder('46870472', 0.07, 1.0, 2.0, 0.9));\nconsole.log(await connection.cancelOrder('46870472'));\n\n// Note: trade methods do not throw an exception if terminal have refused\n// the trade, thus you must check the returned value\nconst result = await connection.createMarketBuyOrder('GBPUSD', 0.07, 0.9, 2.0, 'comment', 'TE_GBPUSD_7hyINWqAlE');\nif (result.description !== 'TRADE_RETCODE_DONE') {\n  console.error('Trade was rejected by MetaTrader terminal with ' + result.description + ' error');\n}\n\n// you can release all MetaApi resource when you done using it\napi.close();\n```\n\n## Synchronize with MetaTrader terminal state in real-time\nIf you are developing applications like trading strategy or an EA then\nyou'll likely need a real-time view of the terminal state. If this is\nthe case, then you should set your account synchronization mode to\n'user' and use API below to access terminal state.\n\n```javascript\nimport MetaApi, {HistoryStorage, SynchronizationListener} from 'metaapi.cloud-sdk';\n\nconst token = '...';\nconst api = new MetaApi(token);\n\nconst account = await api.metatraderAccountApi.getAccount('accountId');\n\n// account.synchronizationMode must be equal to 'user' at this point\n\nclass MongodbHistoryStorage extends HistoryStorage {\n  // implement the abstract methods, see MemoryHistoryStorage for sample\n  // implementation\n}\n\nconst historyStorage = new MongodbHistoryStorage();\n\n// Note: if you will not specify history storage, then in-memory storage\n// will be used (instalce of MemoryHistoryStorage)\nconst connection = await account.connect(historyStorage);\n\n// access local copy of terminal state\nconst terminalState = connection.terminalState;\n\n// wait until synchronization completed\nawait connection.waitSynchronized();\n\nconsole.log(terminalState.connected);\nconsole.log(terminalState.connectedToBroker);\nconsole.log(terminalState.accountInformation);\nconsole.log(terminalState.positions);\nconsole.log(terminalState.orders);\n// symbol specifications\nconsole.log(terminalState.specifications);\nconsole.log(terminalState.specification('EURUSD'));\nconsole.log(terminalState.price('EURUSD'));\n\n// access history storage\nconst historyStorage = account.historyStorage;\n\n// both orderSynchronizationFinished and dealSynchronizationFinished\n// should be true once history synchronization have finished\nconsole.log(historyStorage.orderSynchronizationFinished);\nconsole.log(historyStorage.dealSynchronizationFinished);\n// invoke other methods provided by your history storage\nconsole.log(await historyStorage.yourMethod());\n\n// receive synchronization event notifications\n// first, implement your listener\nclass MySynchronizationListener extends SynchronizationListener {\n  // override abstract methods you want to receive notifications for\n}\n// now add the listener\nconst listener = new MySynchronizationListener();\nconnection.addSynchronizationListener(listener);\n// remove the listener when no longer needed\nconnection.removeSynchronizationListener(listener);\n\n// close the connection to clean up resources\nconnection.close();\n\n// you can release all MetaApi resource when you done using it\napi.close();\n```\n\nKeywords: MetaTrader API, MetaTrader REST API, MetaTrader websocket API,\nMetaTrader 5 API, MetaTrader 5 REST API, MetaTrader 5 websocket API,\nMetaTrader 4 API, MetaTrader 4 REST API, MetaTrader 4 websocket API,\nMT5 API, MT5 REST API, MT5 websocket API, MT4 API, MT4 REST API,\nMT4 websocket API, MetaTrader SDK, MetaTrader SDK, MT4 SDK, MT5 SDK,\nMetaTrader 5 SDK, MetaTrader 4 SDK, MetaTrader node.js SDK, MetaTrader 5\nnode.js SDK, MetaTrader 4 node.js SDK, MT5 node.js SDK, MT4 node.js SDK,\nFX REST API, Forex REST API, Forex websocket API, FX websocket API, FX\nSDK, Forex SDK, FX node.js SDK, Forex node.js SDK, Trading API, Forex\nAPI, FX API, Trading SDK, Trading REST API, Trading websocket API,\nTrading SDK, Trading node.js SDK\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuancapital%2Fmetaapi-node.js-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhuancapital%2Fmetaapi-node.js-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuancapital%2Fmetaapi-node.js-client/lists"}