New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

okx-api

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

okx-api - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

lib/rest-client.d.ts

3

lib/index.d.ts

@@ -1,1 +0,2 @@

export declare const HELLO = "HELLO";
export * from './rest-client';
export * from './util/typeGuards';
"use strict";
// export * from './inverse-client';
// export * from './inverse-futures-client';
// export * from './linear-client';
// export * from './spot-client';
// export * from './websocket-client';
// export * from './logger';
// export * from './types/shared';
// export * from './types/spot';
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./rest-client"), exports);
__exportStar(require("./util/typeGuards"), exports);
// export * from './util/WsStore';
// export * from './constants/enum';
Object.defineProperty(exports, "__esModule", { value: true });
exports.HELLO = void 0;
// Package under development
exports.HELLO = 'HELLO';
//# sourceMappingURL=index.js.map
{
"name": "okx-api",
"version": "0.0.1",
"version": "0.0.2",
"description": "EARLY BETA. Node.js connector for OKX REST APIs and WebSockets, with TypeScript & integration tests.",

@@ -30,10 +30,10 @@ "main": "lib/index.js",

"devDependencies": {
"@types/jest": "^26.0.23",
"@types/jest": "^28.1.4",
"@types/node": "^14.14.7",
"eslint": "^7.10.0",
"jest": "^27.0.4",
"source-map-loader": "^2.0.0",
"ts-jest": "^27.0.3",
"ts-loader": "^8.0.11",
"typescript": "^4.0.5",
"eslint": "^8.19.0",
"jest": "^28.1.2",
"source-map-loader": "^4.0.0",
"ts-jest": "^28.0.5",
"ts-loader": "^9.3.1",
"typescript": "^4.7.4",
"webpack": "^5.4.0",

@@ -40,0 +40,0 @@ "webpack-bundle-analyzer": "^4.1.0",

@@ -9,4 +9,6 @@ # okx-api

WARNING: This package is still early beta, following the designs of my other connectors. If you want to stay informed when this may be ready for testing, please get in touch via telegram.
**WARNING: This package is still early beta! Expect breaking changes until this sees a major release.**
If you want to stay informed when this may be ready for testing, please get in touch via telegram.
Node.js connector for the okx APIs and WebSockets, with TypeScript & browser support.

@@ -21,2 +23,13 @@

## Related projects
- Try my connectors:
- [ftx-api](https://www.npmjs.com/package/ftx-api)
- [bybit-api](https://www.npmjs.com/package/bybit-api)
- [okx-api](https://www.npmjs.com/package/okx-api)
- [binance](https://www.npmjs.com/package/binance)
- Try my misc utilities:
- [orderbooks](https://www.npmjs.com/package/orderbooks)
- Check out my examples:
- [awesome-crypto-examples](https://github.com/tiagosiebler/awesome-crypto-examples)
## Documentation

@@ -29,4 +42,4 @@ Most methods accept JS objects. These can be populated using parameters specified by okx's API documentation.

- [src](./src) - the whole connector written in typescript
- [lib](./lib) - the javascript version of the project (compiled from typescript). This should not be edited directly, as it will be overwritten with each release.
- [dist](./dist) - the packed bundle of the project for use in browser environments.
- [lib](./lib) - the javascript version of the project (compiled from typescript). This should not be edited directly, as it will be overwritten with each release. This is also the version published to npm.
- [dist](./dist) - the packed bundle of the project for use in browser environments (manual, using webpack).
- [examples](./examples) - some implementation examples & demonstrations. Contributions are welcome!

@@ -40,168 +53,11 @@

<!--
### REST Inverse
To use the inverse REST APIs, import the `InverseClient`:
## REST Client
```javascript
const { InverseClient } = require('okx-api');
### Requests & Responses
- If your IDE doesn't have IntelliSense, check the [rest-client.ts](./src/rest-client.ts) for a list of methods, params & return types.
- Requests follow the same ordering and format as the categories in the [API docs](https://www.okx.com/docs-v5/en/#rest-api).
- Responses are parsed automatically for less nesting. Error responses are thrown in full:
- If the response looks successful (HTTP 200 and "code" in the response body === "0"), only the `data` property is directly (without the `code`, `data` & `msg` properties).
- If the response looks like an error (HTTP error OR the "code" property in the response does not equal "0"), the full response is thrown (including `code` and `msg` properties). See the interface for [APIResponse<T>](./src/types/rest/shared.ts).
const restClientOptions = {
// override the max size of the request window (in ms)
recv_window?: number;
// how often to sync time drift with okx servers
sync_interval_ms?: number | string;
// Default: false. Disable above sync mechanism if true.
disable_time_sync?: boolean;
// Default: false. If true, we'll throw errors if any params are undefined
strict_param_validation?: boolean;
// Optionally override API protocol + domain
// e.g 'https://api.bytick.com'
baseUrl?: string;
// Default: true. whether to try and post-process request exceptions.
parse_exceptions?: boolean;
};
const API_KEY = 'xxx';
const PRIVATE_KEY = 'yyy';
const useLivenet = false;
const client = new InverseClient(
API_KEY,
PRIVATE_KEY,
// optional, uses testnet by default. Set to 'true' to use livenet.
useLivenet,
// restClientOptions,
// requestLibraryOptions
);
client.getApiKeyInfo()
.then(result => {
console.log("apiKey result: ", result);
})
.catch(err => {
console.error("apiKey error: ", err);
});
client.getOrderBook({ symbol: 'BTCUSD' })
.then(result => {
console.log("getOrderBook inverse result: ", result);
})
.catch(err => {
console.error("getOrderBook inverse error: ", err);
});
```
See [inverse-client.ts](./src/inverse-client.ts) for further information. -->
## WebSockets
Inverse, linear & spot WebSockets can be used via a shared `WebsocketClient`. However, make sure to make one instance of WebsocketClient per market type (spot vs inverse vs linear vs linearfutures):
```javascript
const { WebsocketClient } = require('okx-api');
const API_KEY = 'xxx';
const PRIVATE_KEY = 'yyy';
const wsConfig = {
key: API_KEY,
secret: PRIVATE_KEY,
/*
The following parameters are optional:
*/
// defaults to false == testnet. Set to true for livenet.
// livenet: true
// NOTE: to listen to multiple markets (spot vs inverse vs linear vs linearfutures) at once, make one WebsocketClient instance per market
// defaults to inverse:
// market: 'inverse'
// market: 'linear'
// market: 'spot'
// how long to wait (in ms) before deciding the connection should be terminated & reconnected
// pongTimeout: 1000,
// how often to check (in ms) that WS connection is still alive
// pingInterval: 10000,
// how long to wait before attempting to reconnect (in ms) after connection is closed
// reconnectTimeout: 500,
// config options sent to RestClient (used for time sync). See RestClient docs.
// restOptions: { },
// config for axios used for HTTP requests. E.g for proxy support
// requestOptions: { }
// override which URL to use for websocket connections
// wsUrl: 'wss://stream.bytick.com/realtime'
};
const ws = new WebsocketClient(wsConfig);
// subscribe to multiple topics at once
ws.subscribe(['position', 'execution', 'trade']);
// and/or subscribe to individual topics on demand
ws.subscribe('kline.BTCUSD.1m');
// Listen to events coming from websockets. This is the primary data source
ws.on('update', data => {
console.log('update', data);
});
// Optional: Listen to websocket connection open event (automatic after subscribing to one or more topics)
ws.on('open', ({ wsKey, event }) => {
console.log('connection open for websocket with ID: ' + wsKey);
});
// Optional: Listen to responses to websocket queries (e.g. the response after subscribing to a topic)
ws.on('response', response => {
console.log('response', response);
});
// Optional: Listen to connection close event. Unexpected connection closes are automatically reconnected.
ws.on('close', () => {
console.log('connection closed');
});
// Optional: Listen to raw error events.
// Note: responses to invalid topics are currently only sent in the "response" event.
ws.on('error', err => {
console.error('ERR', err);
});
```
See [websocket-client.ts](./src/websocket-client.ts) for further information.
Note: for linear websockets, pass `linear: true` in the constructor options when instancing the `WebsocketClient`. To connect to both linear and inverse websockets, make two instances of the WebsocketClient.
---
## Customise Logging
Pass a custom logger which supports the log methods `silly`, `debug`, `notice`, `info`, `warning` and `error`, or override methods from the default logger as desired.
```javascript
const { WebsocketClient, DefaultLogger } = require('okx-api');
// Disable all logging on the silly level
DefaultLogger.silly = () => {};
const ws = new WebsocketClient(
{ key: 'xxx', secret: 'yyy' },
DefaultLogger
);
```
## Browser Usage

@@ -221,4 +77,6 @@ Build a bundle using webpack:

Support my efforts to make algo trading accessible to all - register with my referral links:
- [okx](https://www.bybit.com/en-US/register?affiliate_id=9410&language=en-US&group_id=0&group_type=1)
- [Bybit](https://www.bybit.com/en-US/register?affiliate_id=9410&language=en-US&group_id=0&group_type=1)
- [Binance](https://www.binance.com/en/register?ref=20983262)
- [OKX](https://www.okx.com/join/18504944)
- [FTX](https://ftx.com/referrals#a=ftxapigithub)

@@ -225,0 +83,0 @@ Or buy me a coffee using any of these:

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc