{"_id":"@cex-io/cexio-margin-trading","_rev":"1-205b88b414439990982b4de221008d20","name":"@cex-io/cexio-margin-trading","dist-tags":{"latest":"2.0.2"},"versions":{"2.0.1":{"name":"@cex-io/cexio-margin-trading","version":"2.0.1","keywords":["API","exchange","real-time","trading","cryptoexchange","crypto","bitcoin","ethereum","trade"],"author":{"name":"cex.io"},"license":"MIT","_id":"@cex-io/cexio-margin-trading@2.0.1","maintainers":[{"name":"dmytro.svynarenko","email":"d.svynarenko@cex.io"},{"name":"oucexio","email":"ou@cex.io"},{"name":"dverescexio","email":"d.veres@cex.io"}],"homepage":"https://github.com/cex-io-exchange/cexio-margin-trading","bugs":{"url":"https://github.com/cex-io-exchange/cexio-margin-trading/issues"},"dist":{"shasum":"dcafc64eb9677987b3687f025830181b1427356b","tarball":"https://registry.npmjs.org/@cex-io/cexio-margin-trading/-/cexio-margin-trading-2.0.1.tgz","fileCount":7,"integrity":"sha512-dnMc+ybXRhAWFO9BHnBM2SfjttRjA2zy4VyZs6xHwbpZEtOd3a+W2e08XNgGceG/fQ2F7vF3VuWUuS16B6KPAA==","signatures":[{"sig":"MEUCIQCWj2iA88d/7L5qd7jdhlHf5nWgwymQuHepPcK/B9pGbgIgK0rq4aQk9P5FGWA5DVR5j835KbfKu/fEXOokSh8HG4A=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":21541},"main":"index.js","engines":{"node":">=14"},"gitHead":"ca4473b881900d18d2b7a3f9f5bf8a34577686a3","_npmUser":{"name":"oucexio","email":"ou@cex.io"},"repository":{"url":"git+https://github.com/cex-io-exchange/cexio-margin-trading.git","type":"git"},"_npmVersion":"6.14.11","description":"The official Node.js client for CEX.IO Margin Trading API","directories":{"lib":"lib"},"_nodeVersion":"14.16.0","dependencies":{"ws":"^8.13.0","node-fetch":"^2.6.9"},"_hasShrinkwrap":false,"devDependencies":{"log4js":"^6.9.1","standard":"^14.3.4"},"_npmOperationalInternal":{"tmp":"tmp/cexio-margin-trading_2.0.1_1732892689575_0.8847537844161635","host":"s3://npm-registry-packages"}},"2.0.2":{"name":"@cex-io/cexio-margin-trading","version":"2.0.2","description":"The official Node.js client for CEX.IO Margin Trading API","main":"index.js","directories":{"lib":"lib"},"repository":{"type":"git","url":"git+https://github.com/cex-io-exchange/cexio-margin-trading.git"},"bugs":{"url":"https://github.com/cex-io-exchange/cexio-margin-trading/issues"},"homepage":"https://github.com/cex-io-exchange/cexio-margin-trading","engines":{"node":">=14"},"keywords":["API","exchange","real-time","trading","cryptoexchange","crypto","bitcoin","ethereum","trade"],"author":{"name":"cex.io"},"license":"MIT","dependencies":{"node-fetch":"^2.6.9","ws":"^8.13.0"},"devDependencies":{"log4js":"^6.9.1","standard":"^14.3.4"},"gitHead":"4aeded8cca415f48f242ce8d8ecef6ab8c11fd05","_id":"@cex-io/cexio-margin-trading@2.0.2","_nodeVersion":"14.16.0","_npmVersion":"6.14.11","dist":{"integrity":"sha512-zBbCIleh03Q9D+s554XuehUx77eGA/EMcD8uExk2lAHvallNSZBkwXBWRKaqUVC21dN9KLaPYTicWtWN1D5ZHw==","shasum":"747fda69d22e3e8795a9520c9406333a7c730933","tarball":"https://registry.npmjs.org/@cex-io/cexio-margin-trading/-/cexio-margin-trading-2.0.2.tgz","fileCount":7,"unpackedSize":21535,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD3ham8ToItj22XZLrQSMOoY5ZmKs59YN1b+MT0LIvR6gIgOVCsm0Q0Bj+oDp9gGlAj5lGvxy2VuuOAl8hVmN1EVho="}]},"_npmUser":{"name":"oucexio","email":"ou@cex.io"},"maintainers":[{"name":"dmytro.svynarenko","email":"d.svynarenko@cex.io"},{"name":"oucexio","email":"ou@cex.io"},{"name":"dverescexio","email":"d.veres@cex.io"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cexio-margin-trading_2.0.2_1733225122589_0.6641525303756972"},"_hasShrinkwrap":false}},"time":{"created":"2024-11-29T15:04:49.500Z","modified":"2024-12-03T11:25:23.033Z","2.0.1":"2024-11-29T15:04:49.739Z","2.0.2":"2024-12-03T11:25:22.751Z"},"bugs":{"url":"https://github.com/cex-io-exchange/cexio-margin-trading/issues"},"author":{"name":"cex.io"},"license":"MIT","homepage":"https://github.com/cex-io-exchange/cexio-margin-trading","keywords":["API","exchange","real-time","trading","cryptoexchange","crypto","bitcoin","ethereum","trade"],"repository":{"type":"git","url":"git+https://github.com/cex-io-exchange/cexio-margin-trading.git"},"description":"The official Node.js client for CEX.IO Margin Trading API","maintainers":[{"name":"dmytro.svynarenko","email":"d.svynarenko@cex.io"},{"name":"oucexio","email":"ou@cex.io"},{"name":"dverescexio","email":"d.veres@cex.io"}],"readme":"# CEX.IO Margin Trading\n\nThe official Node.js client for CEX.IO Margin Trading API (https://trade.cex.io/docs)\n\n## Features\n\n- Easy to use, requires only key-secret pair to setup\n- Handle all transport work, just call required action\n- Popular protocols supported, REST and WebSocket onboard\n\n## Installation\n\n```bash\nnpm install @cex-io/cexio-margin-trading\n```\n\n## Rest client\n\n```js\nconst { RestClient } = require('@cex-io/cexio-margin-trading')\nconst defaultClient = new RestClient()\nconst authenticatedClient = new RestClient(apiKey, apiSecret, options)\n```\n\nArguments for RestClient are optional. For private actions you need to generate apiKey and apiSecret pair from UI terminal.\n\n- `apiKey` _string_ - Api key for specific account.\n- `apiSecret` _string_ - Api secret for specific account.\n- `options` _object_ - Additional settings for client.\n\nAvailable client options described below, they all are optional:\n\n- `apiLimit` _integer_ - Rate limit value for apiKey. Default is 300.\n  Client will check requests count and prevent from spam the server. You can ask to increase this limit.\n- `timeout` _integer_ - Request timeout in milliseconds. Default is 30000.\n- `rejectUnauthorized` _boolean_ - This option useful when you test demo env. Default is true.\n- `host` _string_ - Can be changed to test your bot on demo environment. Default is 'https://trade.cex.io/api/margin/'\n- `apiUrl` _string_ - Use a concrete url for private API calls. This option overrides `host` value. Default is 'https://trade.cex.io/api/margin/rest/'\n\n\n### Private actions\n\nTo make private api calls use `async callPrivate(action, params)`. It's similar to public method but requires `apiKey` and `apiSecret` arguments to client initialization. Each private request is signed with `HMAC sha256` so if key is incorrect or signature is wrong client will return rejected promise with error like this `{ error: 'Authorization Failed', statusCode: 401 }`\n\n```js\nconst { RestClient } = require('@cex-io/cexio-margin-trading')\n\nconst key = '_account_api_key_'\nconst secret = '_account_api_secret_'\nconst action = 'getPositions'\nconst params = {\n  pair: 'BTC-USDT'\n}\n\nconst client = new RestClient(key, secret)\n\ntry {\n  const res = await client.callPrivate(action, params)\n  console.log(res)\n} catch (err) {\n  console.error(err)\n}\n```\n\nSuccess response example:\n\n```js\n{ status: 'success', data: { ... } }\n```\n\n## WebSocket client\n\n```js\nconst { WebsocketClient } = require('@cex-io/cexio-margin-trading')\nconst ws = new WebsocketClient(apiKey, apiSecret, options)\n```\n\nTo init the WebsocketClient you must pass `apiKey` and `apiSecret` arguments. You can generate them in UI terminal.\n\n- `apiKey` _string_ - Api key for specific account.\n- `apiSecret` _string_ - Api secret for specific account.\n- `options` _object_ - Additional settings for client.\n\nAvailable client options described below, they all are optional:\n\n- `wsReplyTimeout` _integer_ - Request timeout in milliseconds. Default is 30000.\n- `rejectUnauthorized` _boolean_ - This option useful when you test demo env. Default is true.\n- `host` _string_ - Can be changed to test your bot on demo environment. Default is 'wss://trade.cex.io/api/margin/'\n- `apiUrl` _string_ - Use a concrete url for private WS calls. This option overrides `host` value. Default is 'wss://trade.cex.io/api/margin/ws/'\n\n\n### Call Private actions\nTo send request to the server you need to connect and auth first. Everything is under the hood and all you need is call `async ws.connect()` method. After that you can invoke `async ws.callPrivate(action, params)` method which returns `Promise` with server response.\nIf some error was occurred then method rejects with status code and error description.\n\n```js\n  const { WebsocketClient } = require('@cex-io/cexio-margin-trading')\n  const ws = new WebsocketClient(apiKey, apiSecret, options)\n\n  await ws.connect() // connect and auth on the server\n\n  const res = await ws.callPrivate(action, params)\n  console.log('result:', res)\n\n  ws.disconnect() // close connection\n```\n\n### Subscribe to updates\nThe WebsocketClient allows you to receive updates. The following types of updates are available: `account_update`, `executionReport`, `order_book_increment`, `tradeUpdate`, etc. You can get more details about them in [documentation](https://trade.cex.io/docs#websocket-private-api-calls-account-events).\n\n```js\nconst { WebsocketClient } = require('@cex-io/cexio-margin-trading')\nconst ws = new WebsocketClient(apiKey, apiSecret)\n\ntry {\n  await ws.connect()\n  \n  ws.subscribe('accountUpdate', msg => {\n    console.log('accountUpdate:', msg)\n  })\n} catch (err) {\n  console.error(err)\n}\n```","readmeFilename":"README.md"}