{"_id":"@cex-io/cexio-spot-trading","_rev":"1-927514ba28207825cef28da44a25d2df","name":"@cex-io/cexio-spot-trading","dist-tags":{"latest":"2.0.1"},"versions":{"2.0.0":{"name":"@cex-io/cexio-spot-trading","version":"2.0.0","description":"The official Node.js client for CEX.IO Spot Trading API","main":"index.js","directories":{"lib":"lib"},"repository":{"type":"git","url":"git+https://github.com/cex-io-exchange/cexio-spot-trading.git"},"bugs":{"url":"https://github.com/cex-io-exchange/cexio-spot-trading/issues"},"homepage":"https://github.com/cex-io-exchange/cexio-spot-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"},"_id":"@cex-io/cexio-spot-trading@2.0.0","_nodeVersion":"14.16.0","_npmVersion":"6.14.11","dist":{"integrity":"sha512-g8h3P+QRZ6ELNhnDmTj++qvvSCqYwSfz1X72+z1bGEzAIHwpQ2yxnwBo51/rSnUhVGasFyStlXE2zEFSGRGW5g==","shasum":"adc36f13aee528546311c17a7ae272b44503d710","tarball":"https://registry.npmjs.org/@cex-io/cexio-spot-trading/-/cexio-spot-trading-2.0.0.tgz","fileCount":7,"unpackedSize":22443,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEL/MCyh5QxYsf/SiWQNkd1W2ve/OMTpsJJYAlqg68knAiEAxFYJQwEYuHTJEEXp7uiadRfX5zqnQxvue/G8wK0Giqg="}]},"_npmUser":{"name":"oucexio","email":"ou@cex.io"},"maintainers":[{"name":"dverescexio","email":"d.veres@cex.io"},{"name":"oucexio","email":"ou@cex.io"},{"name":"dmytro.svynarenko","email":"d.svynarenko@cex.io"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cexio-spot-trading_2.0.0_1707233969060_0.32825981316981157"},"_hasShrinkwrap":false},"2.0.1":{"name":"@cex-io/cexio-spot-trading","version":"2.0.1","description":"The official Node.js client for CEX.IO Spot Trading API","main":"index.js","directories":{"lib":"lib"},"repository":{"type":"git","url":"git+https://github.com/cex-io-exchange/cexio-spot-trading.git"},"bugs":{"url":"https://github.com/cex-io-exchange/cexio-spot-trading/issues"},"homepage":"https://github.com/cex-io-exchange/cexio-spot-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":"46e249fe585875284e0b6ddd9b1cacd8e6734414","_id":"@cex-io/cexio-spot-trading@2.0.1","_nodeVersion":"14.16.0","_npmVersion":"6.14.11","dist":{"integrity":"sha512-yI8csVV33f+nWfbR9wlUpvvYxKWOQ1NmIcR8fjqLTrtRHey8G6BG0FNVflQUNqn7aTBBgoOt050ygzfSg6EuaQ==","shasum":"22cd402cb49ea5de812e47c17595b074d2d6a6a1","tarball":"https://registry.npmjs.org/@cex-io/cexio-spot-trading/-/cexio-spot-trading-2.0.1.tgz","fileCount":7,"unpackedSize":22508,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBlProbs4fp8SqVSfpqL6PV9KG12U6Pmb0FDc/egp8p6AiBB1dmogRE34+t5lFnw9lcNvFPFIOKzZrd9rzdJUl8+Uw=="}]},"_npmUser":{"name":"oucexio","email":"ou@cex.io"},"maintainers":[{"name":"dverescexio","email":"d.veres@cex.io"},{"name":"oucexio","email":"ou@cex.io"},{"name":"dmytro.svynarenko","email":"d.svynarenko@cex.io"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cexio-spot-trading_2.0.1_1707296172583_0.0894215824290332"},"_hasShrinkwrap":false}},"time":{"created":"2024-02-06T15:39:28.956Z","2.0.0":"2024-02-06T15:39:29.245Z","modified":"2024-02-07T08:56:13.037Z","2.0.1":"2024-02-07T08:56:12.838Z"},"maintainers":[{"name":"dverescexio","email":"d.veres@cex.io"},{"name":"oucexio","email":"ou@cex.io"},{"name":"dmytro.svynarenko","email":"d.svynarenko@cex.io"}],"description":"The official Node.js client for CEX.IO Spot Trading API","homepage":"https://github.com/cex-io-exchange/cexio-spot-trading","keywords":["API","exchange","real-time","trading","cryptoexchange","crypto","bitcoin","ethereum","trade"],"repository":{"type":"git","url":"git+https://github.com/cex-io-exchange/cexio-spot-trading.git"},"author":{"name":"cex.io"},"bugs":{"url":"https://github.com/cex-io-exchange/cexio-spot-trading/issues"},"license":"MIT","readme":"# CEX.IO Spot Trading\n\nThe official Node.js client for CEX.IO Spot 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-spot-trading\n```\n\n## Rest client\n\n```js\nconst { RestClient } = require('@cex-io/cexio-spot-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/spot/'\n- `apiUrlPublic` _string_ - Use a concrete url for public API calls. This option overrides `host` value. Default is 'https://trade.cex.io/api/spot/rest-public/'\n- `apiUrl` _string_ - Use a concrete url for private API calls. This option overrides `host` value. Default is 'https://trade.cex.io/api/spot/rest/'\n\n\n### Public actions\n\nTo make a public request use `async callPublic(action, params)` method.\nThis method return `Promise` which resolves with server response.\nIf some error was occurred then method rejects with status code and error description.\n\nFor more details check [api reference](https://trade.cex.io/docs).\n\n```js\nconst { RestClient } = require('@cex-io/cexio-spot-trading')\n\nconst client = new RestClient()\n\ntry {\n  const res = await client.callPublic('get_ticker')\n  console.log(res)\n} catch (err) {\n  console.log(err)\n}\n```\n\n```js\n{ error: 'Bad Request', statusCode: 400 }\n{ error: 'Unexpected error', statusCode: 500 }\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-spot-trading')\n\nconst key = '_account_api_key_'\nconst secret = '_account_api_secret_'\nconst action = 'get_my_orders'\nconst params = {\n  pair: 'BTC-USD'\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{ ok: 'ok', data: { ... } }\n```\n\n## WebSocket client\n\n```js\nconst { WebsocketClient } = require('@cex-io/cexio-spot-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/spot/'\n- `apiUrlPublic` _string_ - Use a concrete url for public WS calls. This option overrides `host` value. Default is 'wss://trade.cex.io/api/spot/ws-public/'\n- `apiUrl` _string_ - Use a concrete url for private WS calls. This option overrides `host` value. Default is 'wss://trade.cex.io/api/spot/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-spot-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-spot-trading')\nconst ws = new WebsocketClient(apiKey, apiSecret)\n\ntry {\n  await ws.connect()\n\n  ws.subscribe('executionReport', msg => {\n    console.log('executionReport:', msg)\n  })\n\n  ws.subscribe('account_update', msg => {\n    console.log('account_update:', msg)\n  })\n} catch (err) {\n  console.error(err)\n}\n```","readmeFilename":"README.md"}