npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@igorpronin/deribit-client

v1.3.16

Published

Deribit client for internal purposes

Downloads

308

Readme

Deribit client

Deribit client for internal purposes

Warning: This package is currently in active development and is not recommended for production use.

Install

npm i @igorpronin/deribit-client

Usage

import {
  DeribitClient,
  Currencies,
  Kinds,
} from '@igorpronin/deribit-client';

// BTC-PERPETUAL - future contract format
// BTC_USDC - spot format
const client = new DeribitClient({
  api_env: 'prod',
  api_key: 'YOUR_DERIBIT_API_KEY',
  client_id: 'YOUR_DERIBIT_CLIENT_ID',
  instance_id: 'YOUR_INSTANCE_ID', // optional
  output_console: true, // optional, defaults to true
  readonly: true, // optional, defaults to false
  
  // at least one of two options (indexes or instruments) required and shouldn't be empty:
  indexes: ['eth_usd', 'btc_usd'], // optional
  instruments: [BTC-PERPETUAL, 'ETH-PERPETUAL', 'BTC_USDC'], // optional
  instruments_with_orderbook: true, // optional, defaults to false

  on_open: () => console.log('WebSocket opened'),
  on_close: () => console.log('WebSocket closed'),
  on_error: (error) => console.error('WebSocket error:', error),
  on_message: (msg) => console.log('Received message:', msg),
});

Open orders

// Example of opening an order
const order_params = {
  instrument_name: 'BTC-PERPETUAL',
  amount: 100,
  type: OrderType.limit,
  price: 50000,
  time_in_force: TimeInForce.GTC,
  direction: 'buy',
};

const { id, msg } = client.process_open_order(order_params);
console.log('New order ID:', id);

Events

client.ee.on('authorized', () => console.log('Authorized!'));  
client.ee.on('subscribed', (msg: any) => console.log('Subscribed!', msg));
client.ee.on('subscribed_all', () => console.log('Subscribed all!'));
client.ee.on('portfolio_updated', (ticker: Currencies) => console.log('Portfolio updated!', ticker));
client.ee.on('position_updated', (instrument_name: string) => console.log('Position updated!', instrument_name));
client.ee.on('index_updated', (pair: Indexes) => console.log('Index updated!', pair));
client.ee.once('index_updated', (pair: Indexes) => console.log('Index updated!', pair));
client.ee.on('ticker_updated', (instrument_name: string) => console.log('Ticker updated!', instrument_name));
client.ee.once('ticker_updated', (instrument_name: string) => console.log('Ticker updated!', instrument_name));
client.ee.on('all_obligatory_data_received', () => console.log('All obligatory data received!'));
client.ee.on('order_updated', (order_id: string) => console.log('Order updated!', order_id));
client.ee.on('order_filled', (order_id: string) => console.log('Order filled!', order_id));
client.ee.on('account_summaries_updated', () => console.log('Account summaries updated!'));
client.ee.on('disconnected', () => console.log('Disconnected!'));
client.ee.on('book_updated', (instrument_name: string) => console.log('Book updated!', instrument_name));

Public Methods

get_configuration()

Returns the current configuration of the client.

can_trade()

Returns a boolean indicating whether the client can trade.

get_index(index: Indexes)

Returns the current index price for the specified currency pair.

get_pending_subscriptions()

Returns an array of pending subscriptions.

get_active_subscriptions()

Returns an array of active subscriptions.

get_obligatory_data_pending()

Returns a boolean indicating whether obligatory data is pending.

get_obligatory_data_received()

Returns a boolean indicating whether obligatory data is received.

get_account_summaries()

Returns summaries of all accounts.

get_deribit_instruments(kind: Kinds)

Returns the instruments for the specified kind.

get_deribit_instrument_by_name(instrument_name: string)

Returns the instrument for the specified name.

get_deribit_currencies_list()

Returns the list of currencies supported by Deribit.

get_ticker_data(instrument_name: string)

Returns the full ticker data (raw and calculated) for the specified instrument.

get_raw_ticker_data(instrument_name: string)

Returns the raw ticker data for the specified instrument.

get_calculated_ticker_data(instrument_name: string)

Returns the calculated ticker data for the specified instrument.

get_positions()

Returns all positions.

get_position_by_instrument_name(instrument_name: string)

Returns the position for the specified instrument.

get_orders()

Returns all orders.

get_order_by_label(label: string)

Returns the order for the specified label.

get_trades()

Returns all trades.

has_pending_orders()

Returns a boolean indicating whether there are any pending orders.

process_open_order(params: OrderParams)

Opens a new order with the specified parameters.

Contacts

Any questions? DM me: @igorpronin

License

MIT License

Copyright (c) 2024 Igor Pronin

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.