{"_id":"@axvietnam/spot","_rev":"2-625e1750dc1aa93c35b35921f422c40d","name":"@axvietnam/spot","dist-tags":{"latest":"32.0.1"},"versions":{"32.0.1":{"name":"@axvietnam/spot","version":"32.0.1","keywords":["Axvn","API","Spot","Connector","REST","WebSocket","Trading"],"author":{"name":"hoangxuanbien"},"license":"MIT","_id":"@axvietnam/spot@32.0.1","maintainers":[{"name":"sbvvietnam","email":"magnesi24vnd@gmail.com"}],"homepage":"https://github.com/axvietnam/connector-js#readme","bugs":{"url":"https://github.com/axvietnam/connector-js/issues"},"dist":{"shasum":"dabc9d321f626a2ee5205b451c774fe73988ba33","tarball":"https://registry.npmjs.org/@axvietnam/spot/-/spot-32.0.1.tgz","fileCount":10,"integrity":"sha512-J1MyjMlUuMjIRytkDM6mb4CzI1Df77LM/+wbGCn4AylhLauUEZ/ymdKomvsQ910btnwD7QOptAmm1XlmM19MiQ==","signatures":[{"sig":"MEUCIDmPV69dUxPeyxPYE//ASTBCRGpR1ldbttOTq0U3JQ5/AiEAr5E8SZaNN8qSn/K2x+t8s4oDI7eD1BQgZvKn5dBFUiE=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":5776191},"main":"./dist/index.js","types":"./dist/index.d.ts","module":"./dist/index.mjs","exports":{".":{"import":"./dist/index.mjs","require":"./dist/index.js"}},"gitHead":"bd100a66d81c49906ff983a27a8c1829f15d54da","scripts":{"lint":"npx eslint '**/*.ts' --fix","test":"npx jest --maxWorkers=4 --bail","build":"npm run clean && tsdown","clean":"rm -rf dist","format":"npx prettier --ignore-path .prettierignore --write .","typecheck":"tsc --noEmit","test:watch":"npx jest --watch","prepublishOnly":"npm run build"},"_npmUser":{"name":"sbvvietnam","email":"magnesi24vnd@gmail.com"},"repository":{"url":"git+https://github.com/axvietnam/connector-js.git","type":"git"},"_npmVersion":"10.8.2","description":"Official Axvn Spot Connector - A lightweight library that provides a convenient interface to Axvn's Spot REST API, WebSocket API and WebSocket Streams.","directories":{},"_nodeVersion":"20.20.2","dependencies":{"ws":"^8.17.1","axios":"^1.7.4","@types/ws":"^8.5.5","@axvietnam/common":"2.4.5"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29.6.4","eslint":"8.57.0","tsdown":"^0.16.5","ts-jest":"^29.1.1","ts-node":"^10.9.1","prettier":"^3.3.3","typescript":"^5.7.2","@types/jest":"^29.5.4","@types/node":"^20.17.24","json-with-bigint":"^3.5.8","typescript-eslint":"^8.24.0"},"_npmOperationalInternal":{"tmp":"tmp/spot_32.0.1_1786810579579_0.34429389472033334","host":"s3://npm-registry-packages-npm-production"}}},"time":{"created":"2026-08-15T16:16:19.241Z","modified":"2026-08-16T18:06:19.199Z","32.0.1":"2026-08-15T16:16:19.774Z"},"bugs":{"url":"https://github.com/axvietnam/connector-js/issues"},"author":{"name":"hoangxuanbien"},"license":"MIT","homepage":"https://github.com/axvietnam/connector-js#readme","keywords":["Axvn","API","Spot","Connector","REST","WebSocket","Trading"],"repository":{"url":"git+https://github.com/axvietnam/connector-js.git","type":"git"},"description":"Official Axvn Spot Connector - A lightweight library that provides a convenient interface to Axvn's Spot REST API, WebSocket API and WebSocket Streams.","maintainers":[{"email":"magnesi24vnd@gmail.com","name":"sbvvietnam"},{"email":"Nhamhuan@gmail.com","name":"nhamhuan"}],"readme":"# Axvn JavaScript SPOT Connector\n\n[![Open Issues](https://img.shields.io/github/issues/axvietnam/connector-js)](https://github.com/axvietnam/connector-js/issues)\n[![Code Style: Prettier](https://img.shields.io/badge/code%20style-prettier-ff69b4)](https://prettier.io/)\n[![npm version](https://badge.fury.io/js/@axvietnam%2Fspot.svg)](https://badge.fury.io/js/@axvietnam%2Fspot)\n[![npm Downloads](https://img.shields.io/npm/dm/@axvietnam/spot.svg)](https://www.npmjs.com/package/@axvietnam/spot)\n![Node.js Version](https://img.shields.io/badge/Node.js-%3E=22.12.0-brightgreen)\n[![Socket Badge](https://socket.dev/api/badge/npm/package/@axvietnam/spot)](https://socket.dev/npm/package/@axvietnam/spot)\n[![Docs](https://img.shields.io/badge/docs-online-blue?style=flat-square)](https://axvietnam.github.io/axvietnam-connector-js/modules/_axvietnam_spot.html)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nThis is a client library for the Axvn SPOT API, enabling developers to interact programmatically with Axvn's SPOT trading platform. The library provides tools for retrieving market data, executing trades, and managing orders through three distinct endpoints:\n\n- [REST API](./src/rest-api/rest-api.ts)\n- [Websocket API](./src/websocket-api/websocket-api-connection.ts)\n- [Websocket Stream](./src/websocket-streams/websocket-streams-connection.ts)\n\n## Table of Contents\n\n- [Supported Features](#supported-features)\n- [Installation](#installation)\n- [Documentation](#documentation)\n- [REST APIs](#rest-apis)\n- [Websocket APIs](#websocket-apis)\n- [Websocket Streams](#websocket-streams)\n- [Testing](#testing)\n- [Migration Guide](#migration-guide)\n- [Contributing](#contributing)\n- [Licence](#licence)\n\n## Supported Features\n\n- REST API Endpoints:\n  - `/api/*`\n- WebSocket Endpoints: Real-time data streaming and request-response communication.\n- Inclusion of test cases and examples for quick onboarding.\n\n## Installation\n\nTo use this library, ensure your environment is running Node.js version **22.12.0** or later. If you're using `nvm` (Node Version Manager), you can set the correct version as follows:\n\n```bash\nnvm install 22.12.0\nnvm use 22.12.0\n```\n\nThen install the library using `npm`:\n\n```bash\nnpm install @axvietnam/spot\n```\n\n## Documentation\n\nFor detailed information, refer to the [Axvn API Documentation](https://developers.vnkr.vn/docs/axvietnam-spot-api-docs/README).\n\n### REST APIs\n\nAll REST API endpoints are available through the [`rest-api`](./src/rest-api/rest-api.ts) module. The REST API enables you to fetch market data, manage trades, and access account information. Note that some endpoints require authentication using your Axvn API credentials.\n\n```typescript\nimport { Spot, SpotRestAPI } from '@axvietnam/spot';\n\nconst configurationRestAPI = {\n    apiKey: 'your-api-key',\n    apiSecret: 'your-api-secret',\n};\nconst client = new Spot({ configurationRestAPI });\n\nclient.restAPI\n    .exchangeInfo({ symbol: 'VNKRUSDT' })\n    .then((res) => res.data())\n    .then((data: SpotRestAPI.ExchangeInfoResponse) => console.log(data))\n    .catch((err) => console.error(err));\n```\n\nMore examples can be found in the [`examples/rest-api`](./examples/rest-api/) folder.\n\n#### Configuration Options\n\nThe REST API supports the following advanced configuration options:\n\n- `timeout`: Timeout for requests in milliseconds (default: 1000 ms).\n- `proxy`: Proxy configuration:\n  - `host`: Proxy server hostname.\n  - `port`: Proxy server port.\n  - `protocol`: Proxy protocol (http or https).\n  - `auth`: Proxy authentication credentials:\n    - `username`: Proxy username.\n    - `password`: Proxy password.\n- `keepAlive`: Enable HTTP keep-alive (default: true).\n- `compression`: Enable response compression (default: true).\n- `retries`: Number of retry attempts for failed requests (default: 3).\n- `backoff`: Delay in milliseconds between retries (default: 1000 ms).\n- `httpsAgent`: Custom HTTPS agent for advanced TLS configuration.\n- `privateKey`: RSA or ED25519 private key for authentication.\n- `privateKeyPassphrase`: Passphrase for the private key, if encrypted.\n- `timeUnit`: Specify the time unit for timestamps (e.g., milliseconds or microseconds).\n\n##### Timeout\n\nYou can configure a timeout for requests in milliseconds. If the request exceeds the specified timeout, it will be aborted. See the [Timeout example](./docs/rest-api/timeout.md) for detailed usage.\n\n##### Proxy\n\nThe REST API supports HTTP/HTTPS proxy configurations. See the [Proxy example](./docs/rest-api/proxy.md) for detailed usage.\n\n##### Keep-Alive\n\nEnable HTTP keep-alive for persistent connections. See the [Keep-Alive example](./docs/rest-api/keepAlive.md) for detailed usage.\n\n##### Compression\n\nEnable or disable response compression. See the [Compression example](./docs/rest-api/compression.md) for detailed usage.\n\n##### Retries\n\nConfigure the number of retry attempts and delay in milliseconds between retries for failed requests. See the [Retries example](./docs/rest-api/retries.md) for detailed usage.\n\n##### HTTPS Agent\n\nCustomize the HTTPS agent for advanced TLS configurations. See the [HTTPS Agent example](./docs/rest-api/httpsAgent.md) for detailed usage.\n\n##### Key Pair Based Authentication\n\nThe REST API supports key pair-based authentication for secure communication. You can use `RSA` or `ED25519` keys for signing requests. See the [Key Pair Based Authentication example](./docs/rest-api/key-pair-authentication.md) for detailed usage.\n\n##### Time Unit\n\nThe REST API supports different time units for timestamp values. See the [Time Unit example](./docs/rest-api/time-unit.md) for more details.\n\n##### Certificate Pinning\n\nTo enhance security, you can use certificate pinning with the `httpsAgent` option in the configuration. This ensures the client only communicates with servers using specific certificates. See the [Certificate Pinning example](./docs/rest-api/certificate-pinning.md) for detailed usage.\n\n#### Error Handling\n\nThe REST API provides detailed error types to help you handle issues effectively:\n\n- `ConnectorClientError`: General client error.\n- `RequiredError`: Thrown when a required parameter is missing.\n- `UnauthorizedError`: Indicates missing or invalid authentication credentials.\n- `ForbiddenError`: Access to the requested resource is forbidden.\n- `TooManyRequestsError`: Rate limit exceeded.\n- `RateLimitBanError`: IP address banned for exceeding rate limits.\n- `ServerError`: Internal server error.\n- `NetworkError`: Issues with network connectivity.\n- `NotFoundError`: Resource not found.\n- `BadRequestError`: Invalid request.\n\nSee the [Error Handling example](./docs/rest-api/error-handling.md) for detailed usage.\n\n#### Testnet\n\nFor testing purposes, `/api/*` endpoints can be used in the [Spot Testnet](https://testnet.testnet.vnkr.vn/). Update the `basePath` in your configuration:\n\n```typescript\nimport { Spot, SpotRestAPI, SPOT_REST_API_TESTNET_URL } from '@axvietnam/spot';\n\nconst configurationRestAPI = {\n    apiKey: 'your-api-key',\n    apiSecret: 'your-api-secret',\n    basePath: SPOT_REST_API_TESTNET_URL,\n};\nconst client = new Spot({ configurationRestAPI });\n```\n\nIf `basePath` is not provided, it defaults to `https://api.vnkr.vn`.\n\n### Websocket APIs\n\nThe WebSocket API provides request-response communication for market data and trading actions. Use the [`websocket-api`](./src/websocket-api/websocket-api.ts) module to interact with these endpoints.\n\n```typescript\nimport { Spot, SpotWebsocketAPI } from '@axvietnam/spot';\n\nconst configurationWebsocketAPI = {\n    apiKey: 'your-api-key',\n    apiSecret: 'your-api-secret',\n};\nconst client = new Spot({ configurationWebsocketAPI });\n\nclient.websocketAPI\n    .connect()\n    .then((connection: SpotWebsocketAPI.WebsocketAPIConnection) =>\n        connection.exchangeInfo({ symbol: 'VNKRUSDT' })\n    )\n    .then((res: SpotWebsocketAPI.ApiResponse<SpotWebsocketAPI.ExchangeInfoResponse>) =>\n        console.log(res.data)\n    )\n    .catch((err) => console.error(err));\n```\n\nMore examples are available in the [`examples/websocket-api`](./examples/websocket-api/) folder.\n\n#### Configuration Options\n\nThe WebSocket API supports the following advanced configuration options:\n\n- `timeout`: Set the timeout for WebSocket requests (default: 5000 ms).\n- `reconnectDelay`: Specify the delay between reconnection attempts (default: 5000 ms).\n- `compression`: Enable or disable compression for WebSocket messages (default: true).\n- `agent`: Customize the WebSocket agent for advanced configurations.\n- `mode`: Choose between `single` and `pool` connection modes.\n  - `single`: A single WebSocket connection.\n  - `pool`: A pool of WebSocket connections.\n- `poolSize`: Define the number of WebSocket connections in pool mode.\n- `privateKey`: RSA or ED25519 private key for authentication.\n- `privateKeyPassphrase`: Passphrase for the private key, if encrypted.\n- `timeUnit`: Specify the time unit for timestamps (e.g., milliseconds or microseconds).\n\n##### Timeout\n\nSet the timeout for WebSocket API requests in milliseconds. See the [Timeout example](./docs/websocket-api/timeout.md) for detailed usage.\n\n##### Reconnect Delay\n\nSpecify the delay in milliseconds between WebSocket reconnection attempts. See the [Reconnect Delay example](./docs/websocket-api/reconnect-delay.md) for detailed usage.\n\n##### Compression\n\nEnable or disable compression for WebSocket messages. See the [Compression example](./docs/websocket-api/compression.md) for detailed usage.\n\n##### WebSocket Agent\n\nCustomize the agent for advanced configurations. See the [WebSocket Agent example](./docs/websocket-api/agent.md) for detailed usage.\n\n##### Connection Mode\n\nChoose between `single` and `pool` connection modes for WebSocket connections. The `single` mode uses a single WebSocket connection, while the `pool` mode uses a pool of WebSocket connections. See the [Connection Mode example](./docs/websocket-api/connection-mode.md) for detailed usage.\n\n##### Key Pair Based Authentication\n\nUse RSA or ED25519 private keys for WebSocket API authentication. See the [Key Pair Authentication example](./docs/websocket-api/key-pair-authentication.md) for detailed usage.\n\n##### Certificate Pinning\n\nTo enhance security, you can use certificate pinning with the `agent` option in the configuration. This ensures the client only communicates with servers using specific certificates. See the [Certificate Pinning example](./docs/websocket-api/certificate-pinning.md) for detailed usage.\n\n##### Time Unit\n\nSpecify the time unit for WebSocket API timestamps (e.g., milliseconds or microseconds). See the [Time Unit example](./docs/websocket-api/time-unit.md) for detailed usage.\n\n#### Subscribe to User Data Streams\n\nYou can consume the user data stream, which sends account-level events such as account and order updates. First do a `logon` to the websocket connection via WebSocket API; then:\n\n```typescript\nimport { Spot, SpotWebsocketAPI } from '@axvietnam/spot';\n\nconst configurationWebsocketAPI = {\n    apiKey: 'your-api-key',\n    apiSecret: 'your-api-secret',\n};\nconst client = new Spot({ configurationWebsocketAPI });\n\nclient.websocketAPI\n    .connect()\n    .then((connection) => connection.sessionLogon().then(() => connection))\n    .then((connection) => connection.userDataStreamSubscribe())\n    .then(({ stream }) => {\n        stream.on('message', (data) => {\n            switch (data.e) {\n                case 'balanceUpdate':\n                    console.log('balance update stream', data);\n                    break;\n                case 'outboundAccountPosition':\n                    console.log('outbound account position stream', data);\n                    break;\n                // …handle other variants…\n                default:\n                    console.log('unknown stream', data);\n                    break;\n            }\n        });\n    })\n    .catch((err) => console.error(err));\n```\n\n#### Testnet\n\nFor testing purposes, the Websocket API also supports a testnet environment. Update the `wsURL` in your configuration:\n\n```typescript\nimport { Spot, SpotWebsocketAPI, SPOT_WS_API_TESTNET_URL } from '@axvietnam/spot';\n\nconst configurationWebsocketAPI = {\n    apiKey: 'your-api-key',\n    apiSecret: 'your-api-secret',\n    wsURL: SPOT_WS_API_TESTNET_URL,\n};\nconst client = new Spot({ configurationWebsocketAPI });\n```\n\nIf `wsURL` is not provided, it defaults to `wss://ws-api.vnkr.vn:443/ws-api/v3`.\n\n### Websocket Streams\n\nWebSocket Streams provide real-time data feeds for market trades, candlesticks, and more. Use the [websocket-streams](./src/websocket-streams/websocket-streams.ts) module to subscribe to these streams.\n\n```typescript\nimport { Spot, SpotWebsocketStreams, SPOT_WS_STREAMS_PROD_URL } from '@axvietnam/spot';\n\nconst configurationWebsocketStreams = {\n    wsURL: SPOT_WS_STREAMS_PROD_URL,\n};\nconst client = new Spot({ configurationWebsocketStreams });\n\nclient.websocketStreams\n    .connect()\n    .then((connection: SpotWebsocketStreams.WebsocketStreamsConnection) => {\n        const stream = connection.aggTrade({ symbol: 'VNKRUSDT' });\n        stream.on('message', (data: SpotWebsocketStreams.AggTradeResponse) => console.info(data));\n    })\n    .catch((err) => console.error(err));\n```\n\nMore examples are available in the [`examples/websocket-streams`](./examples/websocket-streams/) folder.\n\n#### Configuration Options\n\nThe WebSocket Streams API supports the following advanced configuration options:\n\n- `reconnectDelay`: Specify the delay between reconnection attempts (default: 5000 ms).\n- `compression`: Enable or disable compression for WebSocket messages (default: true).\n- `agent`: Customize the WebSocket agent for advanced configurations.\n- `mode`: Choose between `single` and `pool` connection modes.\n  - `single`: A single WebSocket connection.\n  - `pool`: A pool of WebSocket connections.\n- `poolSize`: Define the number of WebSocket connections in pool mode.\n- `timeUnit`: Specify the time unit for timestamps (e.g., milliseconds or microseconds).\n\n##### Reconnect Delay\n\nSpecify the delay in milliseconds between WebSocket reconnection attempts for streams. See the [Reconnect Delay example](./docs/websocket-streams/reconnect-delay.md) for detailed usage.\n\n##### Compression\n\nEnable or disable compression for WebSocket Streams messages. See the [Compression example](./docs/websocket-streams/compression.md) for detailed usage.\n\n##### WebSocket Agent\n\nCustomize the agent for advanced configurations. See the [WebSocket Agent example](./docs/websocket-streams/agent.md) for detailed usage.\n\n##### Connection Mode\n\nChoose between `single` and `pool` connection modes for WebSocket Streams. The `single` mode uses a single WebSocket connection, while the `pool` mode uses a pool of WebSocket connections. See the [Connection Mode example](./docs/websocket-streams/connection-mode.md) for detailed usage.\n\n##### Certificate Pinning\n\nTo enhance security, you can use certificate pinning with the `agent` option in the configuration. This ensures the client only communicates with servers using specific certificates. See the [Certificate Pinning example](./docs/websocket-streams/certificate-pinning.md) for detailed usage.\n\n##### Time Unit\n\nSpecify the time unit for WebSocket Streams timestamps (e.g., milliseconds or microseconds). See the [Time Unit example](./docs/websocket-streams/time-unit.md) for detailed usage.\n\n#### Unsubscribing from Streams\n\nYou can unsubscribe from specific WebSocket streams using the `unsubscribe` method. This is useful for managing active subscriptions without closing the connection.\n\n```typescript\nimport { Spot, SpotWebsocketStreams, SPOT_WS_STREAMS_PROD_URL } from '@axvietnam/spot';\n\nconst configurationWebsocketStreams = {\n    wsURL: SPOT_WS_STREAMS_PROD_URL,\n};\nconst client = new Spot({ configurationWebsocketStreams });\n\nclient.websocketStreams\n    .connect()\n    .then((connection: SpotWebsocketStreams.WebsocketStreamsConnection) => {\n        const stream = connection.aggTrade({ symbol: 'VNKRUSDT' });\n        stream.on('message', (data: SpotWebsocketStreams.AggTradeResponse) => console.info(data));\n\n        setTimeout(() => {\n            stream.unsubscribe();\n            console.log('Unsubscribed from VNKRUSDT trade stream');\n        }, 10000);\n    })\n    .catch((err) => console.error(err));\n```\n\n#### Testnet\n\nWebsocket Streams also support a testnet environment for development and testing. Update the `wsURL` in your configuration:\n\n```typescript\nimport { Spot, SpotWebsocketStreams, SPOT_WS_STREAMS_TESTNET_URL } from '@axvietnam/spot';\n\nconst configurationWebsocketStreams = {\n    wsURL: SPOT_WS_STREAMS_TESTNET_URL,\n};\nconst client = new Spot({ configurationWebsocketStreams });\n```\n\nIf `wsURL` is not provided, it defaults to `wss://stream.vnkr.vn:9443`.\n\n### Automatic Connection Renewal\n\nThe WebSocket connection is automatically renewed for both WebSocket API and WebSocket Streams connections, before the 24 hours expiration of the API key. This ensures continuous connectivity.\n\n## Testing\n\nTo run the tests:\n\n```bash\nnpm install\n\nnpm run test\n```\n\nThe tests cover: - REST API endpoints - WebSocket API and Streams - Error handling and edge cases\n\n## Migration Guide\n\nIf you are upgrading to the new modularized structure, refer to the [Migration Guide](./docs/migration_guide_spot_connector.md) for detailed steps.\n\n## Contributing\n\nContributions are welcome!\n\nSince this repository contains auto-generated code, we encourage you to start by opening a GitHub issue to discuss your ideas or suggest improvements. This helps ensure that changes align with the project's goals and auto-generation processes.\n\nTo contribute:\n\n1. Open a GitHub issue describing your suggestion or the bug you've identified.\n2. If it's determined that changes are necessary, the maintainers will merge the changes into the main branch.\n\nPlease ensure that all tests pass if you're making a direct contribution. Submit a pull request only after discussing and confirming the change.\n\nThank you for your contributions!\n\n## Disclaimer\n\nThis SDK is provided by Axvn on an \"as is\" and \"as available\" basis for use at your own risk. Axvn makes no representations or warranties of any kind, whether express or implied, as to the operation of the SDK, its accuracy, reliability, completeness, or fitness for any particular purpose.\n\nTo the fullest extent permitted by law, Axvn shall not be liable for any losses, damages, or expenses of any kind arising from or in connection with your use of, or inability to use, this SDK, including but not limited to any financial losses resulting from errors, bugs, interruptions, or inaccuracies in the SDK.\n\nYour use of this SDK to access the Axvn Platform is subject to the Axvn API Key Terms and the Axvn Terms of Use, which shall prevail in the event of any conflict with this disclaimer. You are solely responsible for any orders or transactions executed through the Axvn Platform using this SDK.\n\nThis SDK is not intended to constitute investment advice or a recommendation to buy, sell, or hold any digital asset. You should independently evaluate and verify all information before acting.\n\n- [Axvn Terms of Use](https://www.vnkr.vn/en/terms)\n- [Axvn API Key Terms](https://www.vnkr.vn/en/about-legal/terms-axvietnam-api)\n\n## Licence\n\nThis project is licensed under the MIT License. See the [LICENCE](./LICENCE) file for details.\n","readmeFilename":"README.md"}