Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,16 @@ Optionally `NODE_NO_WARNINGS` can be exported from `.env` file to silence proces
$ export $(cat .env | xargs)
```

## Settings

Open settings file of an API and set appropriate fields in `account`, `address` and `authentication` sections.

## Usage

General syntax of commands:

```bash
$ node <request|response|socket>[ --<option>]
$ node <request|response|socket>[ --<option|optionKey=optionValue>]
$ node <api>[ <handler>][ <parameter>][ <paramKey=paramValue>][ --<option>]
```

Expand All @@ -92,22 +96,23 @@ See detailed syntax and command examples in **sub directory readme** files.

### Request

Run scenario for **all requests** of **all APIs**:
Run flow for **all requests** of **all APIs**:

```bash
$ node request
```

To run a scenario related to an API request, change directory:
To run a flow related to an API request, change directory:

```bash
$ cd request
```

Run scenario for **all requests** of a **specific API**:
Run flow for **all requests** of a **specific API**:

```bash
$ node bybit
$ node bybit --flow=orders
```

Run **single request** with snapshot (option `--snap[shot]` is required if not enabled in settings):
Expand All @@ -120,7 +125,7 @@ $ node bybit currencyAll --snapshot

### Response

Run scenario for **all responses** of **all APIs** (option `--aggr[egate]` is required if not enabled in settings):
Run flow for **all responses** of **all APIs** (option `--aggr[egate]` is required if not enabled in settings):

```bash
$ node response --aggr
Expand All @@ -131,13 +136,13 @@ $ node response --aggregate
Aggregated "2024-01-01T00:00:00.000Z.json" to "../collection/coinbase/currency_network_all".
```

To run a scenario related to an API response, change directory:
To run a flow related to an API response, change directory:

```bash
$ cd response
```

Run scenario for **all responses** of a **specific API**:
Run flow for **all responses** of a **specific API**:

```bash
$ node bybit
Expand Down
21 changes: 0 additions & 21 deletions coinbase/products.js

This file was deleted.

6 changes: 6 additions & 0 deletions configuration/bybit.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@
"WITHDRAW_ONE": "asset/withdraw/query-record?txID"
},
"PREFIX": "/v5/",
"RESPONSE": {
"CODE": "retCode",
"DESCRIPTION": "retMsg",
"OK": 0,
"SUCCESS": "OK"
},
"TRADE": {
"EXEC": [
"UNKNOWN",
Expand Down
65 changes: 38 additions & 27 deletions configuration/coinbase.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,46 @@
"ENCODING": "hex",
"HOSTNAME": "api.coinbase.com",
"ORDER": {
"LIMIT": "limit_limit_gtc"
"LIMIT": "limit_limit_gtc",
"MARKET": "market_market_ioc",
"STATUS": [
"CANCEL_QUEUED",
"CANCELLED",
"EXPIRED",
"FAILED",
"FILLED",
"OPEN",
"PENDING",
"QUEUED",
"UNKNOWN_ORDER_STATUS"
]
},
"PATH": {
"ADDRESS_ALL": "/v2/accounts/${account_uuid}/addresses",
"ADDRESS": "/v2/accounts/${account_uuid}/addresses",
"ADDRESS_ONE": "/v2/accounts/${account_uuid}/addresses/${address_uuid}",
"ADDRESS_TRANSACTIONS": "/v2/accounts/${account_uuid}/addresses/${address_uuid}/transactions",
"CURRENCY_ALL": "/api/v2/currencies/crypto",
"CURRENCY_ONE": "/api/v2/currencies/crypto?coin",
"DEPOSIT_ALL": "/v2/accounts/${account_uuid}/deposits",
"DEPOSIT_NEW": "/v2/accounts/${account_uuid}/addresses",
"DEPOSIT_ONE": "",
"KEY_INFORMATION": "",
"MARKET_HISTORY": "/api/v3/brokerage/market/products/${product_id}/ticker",
"MARKET_INFORMATION": "/api/v3/brokerage/market/products",
"MARKET_TICKERS": "/api/v3/brokerage/market/products/${product_id}",
"CURRENCY_ONE": "/api/v2/currencies/crypto?asset_uuid",
"MARKET_ALL": "/api/v3/brokerage/market/products",
"MARKET_ONE": "/api/v3/brokerage/market/products/${product_id}",
"MARKET_TICKERS": "/api/v3/brokerage/market/products/${product_id}/ticker",
"NETWORK_ALL": "/api/v2/currencies/crypto?network",
"ORDER_ALL": "/api/v3/brokerage/orders/historical/batch",
"ORDER_BOOK": "",
"ORDER_CANCEL_ALL": "/api/v3/brokerage/orders/batch_cancel",
"ORDER_CANCEL_ONE": "",
"ORDER_HISTORY_ALL": "",
"ORDER_HISTORY_ONE": "",
"ORDER_ONE": "/api/v3/brokerage/orders/historical/${order_id}",
"ORDER_CANCEL": "/api/v3/brokerage/orders/batch_cancel",
"ORDER_ONE": "/api/v3/brokerage/orders/historical/${order_uuid}",
"ORDER_PLACE": "/api/v3/brokerage/orders",
"TRADE_RATES": "",
"TRADE_HISTORY_ALL": "",
"TRADE_HISTORY_ONE": "",
"TRANSFER_ALL": "",
"TRANSFER_INTERNAL": "",
"TRANSACTION_ALL": "/v2/accounts/${account_uuid}/transactions",
"TRANSACTION_ONE": "/v2/accounts/${account_uuid}/transactions/${transaction_uuid}",
"USER_ACCOUNT_ALL": "/api/v3/brokerage/accounts",
"USER_ACCOUNT_ONE": "/api/v3/brokerage/accounts/${account_uuid}",
"USER_PORTFOLIO_ALL": "/api/v3/brokerage/portfolios",
"USER_PORTFOLIO_ONE": "/api/v3/brokerage/portfolios/${portfolio_uuid}",
"WITHDRAW_ALL": "",
"WITHDRAW_NEW": "",
"WITHDRAW_ONE": ""
"USER_PORTFOLIO_ONE": "/api/v3/brokerage/portfolios/${portfolio_uuid}"
},
"PREFIX": "",
"PRODUCT": {
"FUTURE": "FUTURE",
"SPOT": "SPOT"
},
"SOCKET": {
"CHANNEL": {
"CANDLES": "candles",
Expand All @@ -55,9 +58,17 @@
"UNSUBSCRIBE": "unsubscribe",
"URL": "wss://advanced-trade-ws.coinbase.com"
},
"RESPONSE": {
"CODE": "error",
"DESCRIPTION": "message",
"OK": "OK",
"SUCCESS": "OK"
},
"TRADE": {
"BUY": "BUY",
"SELL": "SELL"
"SIDE": {
"BUY": "BUY",
"SELL": "SELL"
}
},
"USER": {
"PORTFOLIO": ["CONSUMER", "DEFAULT", "INTX", "UNDEFINED"]
Expand Down
27 changes: 22 additions & 5 deletions lib/authentication.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,33 @@ import nodeCrypto from 'node:crypto';
import jsonwebtoken from 'jsonwebtoken';
import { AUTH } from './constants.mjs';

export const blind = (secret, hidden = 'full', visibility = 2) => {
/**
* Replace characters in a confidential data (key, secret, etc.).
* @param {string} confidential
* @param {string} hidden
* @param {number} visibility
* @returns {string}
*/
export const blind = (confidential, hidden = 'full', visibility = 2) => {
const output = {
full: '****************',
mask:
secret.slice(0, visibility) +
secret.slice(visibility, -visibility).replace(/.|\n/g, '*') +
secret.slice(-visibility),
none: secret,
confidential.slice(0, visibility) +
confidential.slice(visibility, -visibility).replace(/.|\n/g, '*') +
confidential.slice(-visibility),
none: confidential,
}[hidden];

return output;
};

/**
* Sign a request by Hash-based Message Authentication Code.
* @param {"hex"} encoding
* @param {string} payload
* @param {string} secret
* @param {string} key
* @returns {string}
*/
export const signHmac = (encoding, payload, secret, key) => {
const nonce = nodeCrypto.createHmac('sha256', secret).update(payload),
Expand All @@ -45,6 +57,11 @@ export const signHmac = (encoding, payload, secret, key) => {

/**
* Sign a request by JSON Web Token.
* @param {"hex"} encoding
* @param {object} payload
* @param {string} secret
* @param {string} key
* @returns {string}
*/
export const signJwt = (encoding, payload, secret, key) => {
const nonce = nodeCrypto.randomBytes(16).toString(encoding),
Expand Down
2 changes: 2 additions & 0 deletions lib/constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const AUTH = {
* INTERNAL_SERVER_ERROR: 500,
* NO_CONTENT: 204,
* NOT_FOUND: 404,
* NOT_IMPLEMENTED: 501,
* OK: 200,
* PAYMENT_REQUIRED: 402,
* SERVICE_UNAVAILABLE: 503,
Expand All @@ -63,6 +64,7 @@ export const HTTP = {
FORBIDDEN: 403,
NO_CONTENT: 204,
NOT_FOUND: 404,
NOT_IMPLEMENTED: 501,
OK: 200,
PAYMENT_REQUIRED: 402,
SERVICE_UNAVAILABLE: 503,
Expand Down
Loading