open-index/open-npm huggingface dataset:
npm package: @pxtrn/async-backoff
Description: Backoff failing async calls
Author: Stefan Aebischer
Latest version: 2.0.2

# @pxtrn/async-backoff

Backoff failing async calls until they successfully complete.
Usefull for recoverable errors that most likely go away on retry.
For example errors like  `ENOTFOUND`, `EHOSTUNREACH` etc. on network calls or
`EBUSY` on file system calls.   

## Installation

`npm install --save @pxtrn/async-backoff`


## Usage

### Javascript
```js
const { backoff } = require('@pxtrn/async-backoff');

let counter = 1;

async function request() {
  console.log(`request number: ${counter}`);

  if(counter < 5) {
    counter ++;
    throw new Error('Some Network error');
  }

  console.log(`successfully requestd resource`);
  return true;
}


(async function() {
  try {
    const result = await backoff(request, {maxAttempts: 5, retryTimeout: 100});
  } catch(err) {
    console.error(`Could not request resource`);
  }
})();
```

### Typescript
```js
import { backoff } from '@pxtrn/async-backoff';

let counter = 1;

interface IUser {name: string; email: string};

async function request(): Promise<IUser> {
  console.log(`request number: ${counter}`);

  if(counter < 5) {
    counter ++;
    throw new Error('Some Network error');
  }

  console.log(`successfully requestd resource`);
  return {name: 'Bob', email: 'bob@example.com'};
}


(async function() {
  try {
    const result = await backoff<IUser>(request, {maxAttempts: 5, retryTimeout: 100});
    console.log('Got result', result);
  } catch(err) {
    console.error(`Could not request resource`);
  }
})();


```


#### Parameters

- `fn` {async Function} Async function to await
- `options` {Object}
  - `maxAttempts`: {Integer} Max number of function calls
  - `retryTimeout`: {Integer} ms to wait.
      Only for default delayStrategy (return attempts * retryTimeout)
  - `retryStrategy`: {Function(err)} return boolean true if another call to fn
      should be tryed, even maxAttempts has not been reached yet
  - `delayStrategy`: {Function(attempts)} return an integer in ms for which the
      next attempt should be delayed
  - `signal`: {AbortSignal}


#### Custom retry strategy

```js
await backoff(request, {
  maxAttempts: 5,
  retryStrategy: (err) => {
    const retryErrors = ['ECONNRESET', 'ENOTFOUND', 'ESOCKETTIMEDOUT'];
    return retryErrors.includes(err.code);
  }
});
```

#### Custom delay strategy

```js
await backoff(request, {
  maxAttempts: 5,
  delayStrategy: (attempts) => {
    return Math.min((Math.pow(2, attempts) * 100), 5e3);
  }
});
```

#### Aborting a running backoff

Note this does only abort the backoff itself, not the async function passed.

```js

const ac = new AbortController();
setTimeout(() => ac.abort(), 2e3);


await backoff(request, {
  signal: ac.signal
});
```
npm package: @pxtrn/binance-rate-limit
Description: node.js rate limit tracker for binance. Let's you verify that you won't hit a rate limit before you send your api request.
Author: Stefan Aebischer
Latest version: 1.0.0

# @pxtrn/binance-rate-limit

node.js rate limit tracker for binance. Let's you verify that you won't hit
a rate limit before you send your api request.

## Installation

`npm install --save @pxtrn/binance-rate-limit`

## Usage

Also see the full [axios example](examples/axios.ts)

```ts
import { createSpotLimiter, IRequest, IResponse } from '@pxtrn/binance-rate-limit';

const request = async (req: IRequest): Promise<IResponse> => {
  // dispatch request with your preferred request library
}

const req: IRequest = {
  method: 'GET',
  endpoint: '/api/v3/exchangeInfo',
  params: {symbol: 'BTCUSDT'},
  uid: 'xxx' // binance accountId or hashed apiKey if accountId is not available
};

const limiter = createSpotLimiter();
const retryIn = limiter.mayDispatchRequest(req);

if (retryIn === 0) {
  // if retryIn === 0 dispatch the request immediately.
  const response = await request(req);

  const { statusCode, headers } = response;
  const res: IResponse = {statusCode, headers};

  // update counters, make sure to call this as well if you got
  // a response with a status code other then 2xx or any error during request
  limiter.completeRequest(res, req);
} else {
  // if retryIn > 0 throw and reschedule call
  throw new Error(`Rate limit exceeded retry in ${retryIn}`);
}
```
npm package: @pxtrn/bybit-api
Description: An unofficial node.js lowlevel wrapper for the Bybit Cryptocurrency Derivative exchange API
Author: Stefan Aebischer
Latest version: 1.1.5
Deprecated: This package has been deprecated and is no longer maintained. Please use bybit-api from @tiagosiebler

# @pxtrn/bybit-api

An unofficial node.js lowlevel wrapper for the Bybit Cryptocurrency Derivative
exchange API.


## Installation

`npm install --save @pxtrn/bybit-api`


## Usage

Create API credentials at bybit (obviously you need to be logged in):
- [Livenet](https://bybit.com/app/user/api-management)
- [Testnet](https://testnet.bybit.com/app/user/api-management)


### Rest client

```js
const {RestClient} = require('@pxtrn/bybit-api');

const API_KEY = 'xxx';
const PRIVATE_KEY = 'yyy';

const client = new RestClient(API_KEY, PRIVATE_KEY);

client.changeUserLeverage({leverage: 4, symbol: 'ETHUSD'})
  .then(result => {
    console.log(result);
  })
  .catch(err => {
    console.error(error);
  });
```

See rest client [api docs](./doc/rest-client.md) for further information.


### Websocket client

```js
const {WebsocketClient} = require('@pxtrn/bybit-api');

const API_KEY = 'xxx';
const PRIVATE_KEY = 'yyy';

const ws = new WebsocketClient({key: API_KEY, secret: PRIVATE_KEY});

ws.subscribe(['position', 'execution', 'trade']);
ws.subscribe('kline.BTCUSD.1m');

ws.on('open', function() {
  console.log('connection open');
});

ws.on('update', function(message) {
  console.log('update', message);
});

ws.on('response', function(response) {
  console.log('response', response);
});

ws.on('close', function() {
  console.log('connection closed');
});

ws.on('error', function(err) {
  console.error('ERR', err);
});
```

See websocket client [api docs](./doc/websocket-client.md) for further information.

### 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:

```js
const { RestClient, WebsocketClient, DefaultLogger } = require('@pxtrn/bybit-api');

// Disable all logging on the silly level
DefaultLogger.silly = () => {};

const API_KEY = 'xxx';
const PRIVATE_KEY = 'yyy';

const ws = new WebsocketClient({key: API_KEY, secret: PRIVATE_KEY}, DefaultLogger);
```

## Donations

If this library helps you to trade better on bybit, feel free to donate a coffee,
or create a bybit account using my [ref link](https://www.bybit.com/app/register?ref=j8q5l).

- BTC `1Fh1158pXXudfM6ZrPJJMR7Y5SgZUz4EdF`
- ETH `0x21aEdeC53ab7593b77C9558942f0c9E78131e8d7`
- LTC `LNdHSVtG6UWsriMYLJR3qLdfVNKwJ6GSLF`
npm package: @pxtrn/gricons
Description: web component for @gyselroth/icon-collection.
Author: Stefan Aebischer
Latest version: 1.0.2

# Gricons

Gricons is a web component to display icons from the [@gyselroth/icon-collection](https://github.com/gyselroth/icon-collection).
This repo is mostly a fork of [Ionicons](https://github.com/ionic-team/ionicons).

## Using the Web Component

The Gricons Web Component is an easy and performant way to use Gricons in your app. The component will dynamically load an SVG for each icon, so your app is only requesting the icons that you need.

Also note that only visible icons are loaded, and icons which are "below the fold" and hidden from the user's view do not make fetch requests for the svg resource.

### Installation

Place the following `<script>` near the end of your page, right before the closing </body> tag, to enable them.

```html
<script src="./node_modules/@pxtrn/gricons/dist/gricons.js"></script>
```

### Basic usage

To use a built-in icon from the Gricons package, populate the `name` attribute on the gr-icon component:

```html
<gr-icon name="alert"></gr-icon>
```

### Custom icons

To use a custom SVG, provide its url in the `src` attribute to request the external SVG file. The `src` attribute works the same as `<img src="...">` in that the url must be accessible from the webpage that's making a request for the image. Additionally, the external file can only be a valid svg and does not allow scripts or events within the svg element.

```html
<gr-icon src="/path/to/external/file.svg"></gr-icon>
```

## Size

```css
gr-icon {
  font-size: 64px;
}
```

## Color

Specify the icon color by applying the `color` CSS property on the `gr-icon` component.

```css
gr-icon {
  color: blue;
}
```

## License

Gricons is licensed under the [MIT license](http://opensource.org/licenses/MIT).
npm package: @pxtrn/timer
Description: EventEmitter emitting `tick` based on a given cron expression
Author: Stefan Aebischer
Latest version: 2.0.0

# @pxtrn/timer

Emits `tick` based on a cron expression.
See [`cron-parser`](https://www.npmjs.com/package/cron-parser#supported-format)
for supported formats.

## Installation

`npm install --save @pxtrn/timer`


## Usage

```js
const Timer = require('@pxtrn/timer');

const timer = new Timer('00 * * * * *', {delay: 200});
timer.on('tick', () => {
  console.log('Tick', new Date())
});
```

### Class: `Timer`

- `expression` {String} Cron expression. See `[cron-parser](https://www.npmjs.com/package/cron-parser#supported-format)`
- `options` {Object} Optional
  - `delay`: {Integer} Delay in milliseconds. Default 0
npm package: @pxtrn/ws
Description: Client for @pxtrn/ws pub/sub websocket server
Author: Stefan Aebischer
Latest version: 0.0.1

# @pxtrn/wss

Client for `@pxtrn/wss` pub/sub websocket server

## Installation

`npm install --save @pxtrn/ws`

## Usage

### Basic example

```js
const Ws = require('@pxtrn/ws');

const client = new Ws('wss://example.com');

client.on('update', (update) => {
  console.log(`Got update for channel ${update.channel}`, update.data);
});

client.subscribe('cats');
```

## API

### Table of Contents

- [Class: Ws](#class-ws)
  - [new Ws(url[, options[, logger]])](#new-wsurl-options-logger)
  - [Event: 'close'](#event-close)
  - [Event: 'error'](#event-error)
  - [Event: 'open'](#event-open)
  - [Event: 'update'](#event-update)
  - [async client.subscribe(channels)](#async-clientconnectchannels)
  - [async client.unsubscribe(channels)](#async-clientconnectchannels)
  - [async client.close()](#async-clientclose)

### Class: Ws

This class represents a websocket server with simple pub/sub. It extends EventEmitter.

#### new Ws(url[, options[, logger]])

  `url` {String} Url of the @pxtrn/wss server
- `options` {Object} Optional options
  - `pingInterval` {Integer} Interval in ms for heartbeat ping. Default: `10000`,
  - `pongTimeout` {Integer} Timeout in ms waiting for heartbeat pong response
     from server. Default: `1000`,
  - `reconnectTimeout` {Integer} Timeout in ms the client waits before trying
     to reconnect after a lost connection. Default: `500`
- `logger` {Object}

  custom logger containing the following methods
  ```js
  const logger = {
    silly: function(message, data) {},
    debug: function(message, data) {},
    notice: function(message, data) {},
    info: function(message, data) {},
    warning: function(message, data) {},
    error: function(message, data) {},
  }
  ```

#### Event: 'close'

Emitted when the connection has been closed.

#### Event: 'error'

- `error` {Error}

Emitted when an error occurs.

#### Event: 'open'

Emitted when the has been opened.

#### Event: 'update'

- `update` {Object}
  - `channel` {String} The channel for which the update is.
  - `data` {Mixed} Data the server sent

Emitted when the server emits a channel update.

#### async client.subscribe(channels)
- `channels` {String|Array} Single channel or array of channels

Subscribe to one or more channel(s?).

#### async client.unsubscribe(channels)
- `channels` {String|Array} Single channel or array of channels

Unsubscribe from one or more channel(s?).

#### async client.close()

Close the connection to the server