# Deribit

Client for the [Deribit API v2]( over HTTP.

## Installation

The package can be installed by adding `deribit` to your list of dependencies in `mix.exs`:

def deps do
    {:deribit, "~> 0.1.0"}

Optionally, configure the client with default credentials to be used in private methods.
Set `test: true` to use the API's test endpoint

config :deribit,
  client_id: "",
  client_secret: "",
  test: true # Defaults to false

## Usage

### Public

For endpoints with public scope, simply call a function with the name of the endpoint, optionally passing the parameters as a map:

iex(1)> Deribit.test
   "jsonrpc" => "2.0",
   "result" => %{"version" => "1.2.26"},
   "testnet" => true,
   "usDiff" => 1,
   "usIn" => 1556750102206871,
   "usOut" => 1556750102206872
iex(2)> Deribit.test %{expected_result: "exception"}

Errors have the format `{:error, {status, body}}` or `{:error, reason}`.

### Private

For endpoints with private scope, you can provide the user credentials or use the ones defined via configuration.

iex(1)> Deribit.get_subaccounts
iex(2)> Deribit.get_account_summary("client_id", "client_secret", %{currency: "btc"})