This tutorial will walk through how to interact with Deribit’s RESToverHTTP Interface and provide a few Python examples you can use!

This guide is suitable for beginners and experienced users alike!

Deribit has an API that anyone is able to interact with to receive or send requests. There are three primary interfaces of the API:

The JSON-RPC over HTTP (RESToverHTTP) interface is amazing to perform tasks such as:

  • Requesting all of your existing Deribit Positions.
  • Requesting the latest Market Data for different currencies and kinds of Instruments.
  • Requesting your historical Order and Trade information.

In this guide, we will:

  1. Walkthrough how to create your Deribit API Keys.
  2. Run the provided Python Examples with your Deribit API Keys*.
  3. Discuss solutions you could build using Deribit’s RESToverHTTP interface.

*Examples:

  • Unauthenticated [GET] request Python Example.
  • Authenticated [GET] request Python Example.
  • Authenticated [POST] request Python Example.

This guide will use Deribit’s Testnet as so we don’t risk real capital.

To complete this guide, you will need:

  • A Python environment installed on your system. Anaconda is a great place to start if you are new to Python and using Windows. If you are using macOS or Linux, you can install python directly using your terminal.
  • An IDE like VSCode or Pycharm (Pycharm for Anaconda).
  • A Deribit testnet account.
  • The Deribit API Documentation open at all times. It is the single best resource and reference for any API question now and in the future.

1. Creating your Deribit API Keys

1. Login to your Deribit TESTNET account.

If you do not have a TESTNET account, you should create one. You will need a separate account from your live Deribit account.

Make sure to never share your API Keys with anyone. They are even more sensitive than your username and password & do not require 2FA before critical interactions. Best Deribit Security Practices Guide.

2. In the top right-hand corner of test.deribit.com, hover over the “Person” icon to reveal a dropdown menu. Click on the “API” menu item.

3. In the top right-hand corner, click “ADD NEW KEY”.

4. In the bottom right-hand corner, click “Create a new API key”.

Select “read” for each of the Scope permissions. We did this to make it easy to try out the API, but we strongly recommend you limit the permissions enabled depending upon the solution you’re building. Your Deribit API Credentials’ “Scope permissions” are a key part of your account’s security.

We suggest you name your created Deribit API Key something recognizable. You will be able to see the Trades in your Transaction log and the associated name of the Deribit API Key.

5. In the top right-hand corner, click “Load Keys”.

If you have two-factor authentication enabled on your Deribit account (you 100% should, maybe not TESTNET though….), you will need to enter the code to reveal your Deribit API Key(s).

6. You can now see your Deribit API Key’s “Client ID” and “Client Secret”. Note them as we will use them in the following steps.

It is strongly recommended you thoroughly test your code using the TESTNET first before using the Live exchange. Mistakes as a result of errant code using your Deribit API Key are entirely your own responsibility and cannot be reversed.

2. Run the provided Python examples with your Deribit API Keys

There are three RESToverHTTP Python Examples we will be quickly going through:

  • Unauthenticated [GET] request Python Example.
  • Authenticated [GET] request Python Example.
  • Authenticated [POST] request Python Example.

1. Ensure that you have installed the Python package aiohttp using your package manager (eg. pip, Conda).

Running something similar to `pip install aiohttp` in your IDE’s terminal will install the aiohttp package in your Python environment.

2. Copy the Unauthenticated [GET] request Python Example code into the IDE on your computer (eg. VsCode or Pycharm).

a. The provided code is an example only and Deribit is not responsible for any actions as a result of running, using, or deploying the example.

b. Run the file and observe the output in your terminal. This example requests the [GET] `public/get_instruments` endpoint with the `currency` query string parameter equal to `BTC`.

3. Copy the Authenticated [GET] request Python Example code into the IDE on your computer (eg. VsCode or Pycharm).

a. The provided code is an example only and Deribit is not responsible for any actions as a result of running, using, or deploying the example.

b. Update the variable `client_id` and `client_secret` on lines 62 & 64 to match your Deribit TESTNET API Credentials.

c. Run the file and observe the output in your terminal. This example requests the [GET] `private/get_positions` endpoint with the `currency` query string parameter equal to `ETH`.

4. Copy the Authenticated [POST] request Python Example code into the IDE on your computer (eg. VsCode or Pycharm).

a. The provided code is an example only and Deribit is not responsible for any actions as a result of running, using, or deploying the example.

b. Update the variable `client_id` and `client_secret` on lines 64 & 66 to match your Deribit TESTNET API Credentials.

c. Run the file and observe the output in your terminal. This example requests the [POST] `private/buy` endpoint with a payload specifying that you would like to BUY 500USD of the “BTC-PERPETUAL” instruments using a MARKET Order Type.

3. Discuss solutions you could build using Deribit’s RESToverHTTP interface

The aforementioned examples allow you to interact with Deribit’s RESToverHTTP interface in every way possible!

Where to start when there are so many ideas! Here’s a collection for inspiration; you could:

– Create a solution that sends you a Telegram message of the existing Futures Spreads term structure!

– Create a solution which downloads historical market data and ingests new market data for you to backtest strategies.

– Create a hacky solution that runs on a loop & checks the price of an existing Position and then submits a CLOSE POSITION request if the condition is met.

There are many other great examples on Deribit’s Dev Hub. CryptArbitrage’s example demonstrating the greeks of your existing Deribit Positions is worth checking out!

AUTHOR(S)

Deribit Deribit

We are the best resource for Crypto Derivatives trading. Deribit is not available in the United States or other restricted countries.

THANKS TO

Elliot Parker

Telegram: @ElliotPark
Twitter: @ElliotP789

RECENT ARTICLES