Deribit client for internal purposes
Warning: This package is currently in active development and is not recommended for production use.
npm i @igorpronin/deribit-client
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),
});
// 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);
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));
Returns the current configuration of the client.
Returns a boolean indicating whether the client can trade.
Returns the current index price for the specified currency pair.
Returns an array of pending subscriptions.
Returns an array of active subscriptions.
Returns a boolean indicating whether obligatory data is pending.
Returns a boolean indicating whether obligatory data is received.
Returns summaries of all accounts.
Returns the instruments for the specified kind.
Returns the instrument for the specified name.
Returns the list of currencies supported by Deribit.
Returns the full ticker data (raw and calculated) for the specified instrument.
Returns the raw ticker data for the specified instrument.
Returns the calculated ticker data for the specified instrument.
Returns all positions.
Returns the position for the specified instrument.
Returns all orders.
Returns the order for the specified label.
Returns all trades.
Returns a boolean indicating whether there are any pending orders.
Opens a new order with the specified parameters.
Any questions? DM me: @igorpronin
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.