Coder Social home page Coder Social logo

icostan / deribit-websockets-api-elixir Goto Github PK

View Code? Open in Web Editor NEW

This project forked from arthurcolle/deribit-websockets-api-elixir

0.0 1.0 0.0 18 KB

Deribit Websockets API client for Elixir and Phoenix

License: Other

Elixir 96.28% HTML 3.72%

deribit-websockets-api-elixir's Introduction

Deribit

Client for the Deribit API v2 over a secure WebSocket connection. Adaptation and expansion of earlier work done by @gabrielpra1.

Installation

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

def deps do
  [
    {:deribit, "~> 0.2.0"}
  ]
end

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
{:ok,
 %{
   "jsonrpc" => "2.0",
   "result" => %{"version" => "1.2.26"},
   "testnet" => true,
   "usDiff" => 1,
   "usIn" => 1556750102206871,
   "usOut" => 1556750102206872
 }}
iex(2)> Deribit.test %{expected_result: "exception"}
{:error,
 {500,
  %{
    "error" => %{"code" => 11094, "message" => "internal_server_error"},
    "jsonrpc" => "2.0",
    "testnet" => true,
    "usDiff" => 101,
    "usIn" => 1556925879289043,
    "usOut" => 1556925879289144
  }}}

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
{:error,
 {400,
  %{
    "error" => %{"code" => 13004, "message" => "invalid_credentials"},
    "jsonrpc" => "2.0",
    "testnet" => true,
    "usDiff" => 19,
    "usIn" => 1556925904685704,
    "usOut" => 1556925904685723
  }}}
iex(2)> Deribit.get_account_summary("client_id", "client_secret", %{currency: "btc"})
{:error,
 {400,
  %{
    "error" => %{"code" => 13004, "message" => "invalid_credentials"},
    "jsonrpc" => "2.0",
    "testnet" => true,
    "usDiff" => 24,
    "usIn" => 1556925927518909,
    "usOut" => 1556925927518933
  }}}

Quick how to use

iex(1)> Deribit.API.WebSockets.start_link(); Deribit.API.WebSockets.authenticate(Deribit.client_id(), Deribit.client_secret())
iex(2)> Deribit.subscribe(%{"channels" => ["book.BTC-27DEC19-11000-C.raw"]})

deribit-websockets-api-elixir's People

Contributors

arthurcolle avatar gabrielpra1 avatar stochastic-thread avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.