Coder Social home page Coder Social logo

ocaml-gemini's Introduction

Introduction

This library implements the Gemini exchange v1 REST, Market Data, and Order events websockets services. It is backed by yojson, cohttp-async and cohttp_async_websocket to do the heavy lifting. A provisional console interface is also provided using s-expressions to encode request parameters.

Installation

From your project directory run

opam pin . -y

You can also build the code locally with make or dune.

Api Documentation

The autogenerated api documentation is here.

Configuration

Default environment property

export GEMINI_ENV=production

or

export GEMINI_ENV=sandbox

Sandbox properties

export GEMINI_SANDBOX_API_KEY=...
export GEMINI_SANDBOX_API_SECRET=...

Production properties

export GEMINI_PRODUCTION_API_SECRET=...
export GEMINI_PRODUCTION_API_KEY=...

Example command line usage

gemini tradevolume

2018-03-30 22:01:44.029835-04:00 Info response:
 ((((account_id 123456) (symbol Ethusd) (base_currency Eth)
   (notional_currency Usd) (data_date 2018-03-07)
   (total_volume_base 1.35528896) (maker_buy_sell_ratio 0) (buy_maker_base 0)
   (buy_maker_notional 0) (buy_maker_count 0) (sell_maker_base 0)
   (sell_maker_notional 0) (sell_maker_count 0) (buy_taker_base 1.35528896)
   (buy_taker_notional 997.5062274496) (buy_taker_count 1)
   (sell_taker_base 0) (sell_taker_notional 0) (sell_taker_count 0))
  ((account_id 123456) (symbol Ethusd) (base_currency Eth)
   (notional_currency Usd) (data_date 2018-03-12)
   (total_volume_base 0.30208043) (maker_buy_sell_ratio 0) (buy_maker_base 0)
   (buy_maker_notional 0) (buy_maker_count 0) (sell_maker_base 0)
   (sell_maker_notional 0) (sell_maker_count 0) (buy_taker_base 0.80208043)
   (buy_taker_notional 428.72431038315204) (buy_taker_count 10)
   (sell_taker_base 0) (sell_taker_notional 0) (sell_taker_count 0))
  ....
 gemini order new '((symbol Ethusd) (price 500.0) (amount .001) (type_ Exchange_limit) (client_order_id "test-order") (options ()) (side Sell))'

2018-03-30 22:18:01.210962-04:00 Info response:
 ((client_order_id (test-order)) (order_id 1392122353) (id 1190026576)
 (symbol Ethusd) (exchange Gemini) (avg_execution_price 0.00) (side Sell)
 (type_ Exchange_limit) (timestamp (2018-03-30 22:18:01.000000-04:00))
 (timestampms (2018-03-30 22:18:01.198000-04:00)) (is_live true)
 (is_cancelled false) (is_hidden false) (was_forced false)
 (executed_amount 0) (remaining_amount 0.001) (options ()) (price 500.00)
 (original_amount 0.001))

License

MIT

Features and Bugs

Open issues on github. I am too busy to add new features personally but will review and accept PRs when time permits.

TODO

  • order status web sockets api
  • fix unit test harness
  • document code
  • make opam release
  • rich cli support for order commands
  • write to binary format instead of csv
  • switch to eio where applicable
  • integration test against sandbox environment

ocaml-gemini's People

Contributors

bcc32 avatar struktured avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

useada

ocaml-gemini's Issues

Block trade support

The market data web socket feed eventually crashes with the following error:

{"type":"update","eventId":5468663668,"timestamp":1549627437,"timestampms":1549627437723,"socket_sequence":44738,"events":[{"type":"block_trade","eid":5468663668,"timestamp":1549627437,"timestampms":1549627437723,"price":"107.05","amount":"100"}]}]
2019-02-08 07:03:57.841258-05:00 Error ("Exception raised to [Monitor.try_with] that already returned.""This error was captured by a default handler in [Async.Log]."(exn(monitor.ml.Error(Failure"String \"block_trade\" is not a valid enumeration value. Expected one of trade, change, auction")("Raised at file \"pervasives.ml\", line 32, characters 17-33""Called from file \"src/pipe.ml\", line 924, characters 65-70""Called from file \"src/job_queue.ml\", line 159, characters 6-47""Caught by monitor Monitor.protect"))))
2019-02-08 07:03:57.841323-05:00 Debug <- [text (0x0) (final=true) {"type":"update","eventId":5468663670,"timestamp":1549627437,"timestampms":1549627437736,"socket_sequence":44739,"events":[{"type":"change","side":"bid","price":"107.31","remaining":"15","delta":"-14.236","reason":"cancel"}]}]

deserialization error of enum type

reason Place) (remaining 42.283316)
        (delta 42.283316)))))
    (timestamp ((2019-03-27 07:59:58.000000-04:00)))
    (timestampms ((2019-03-27 07:59:58.568000-04:00)))))))
((socket_sequence 114675)
 (message
  (Update
   ((event_id 5788815432)
    (events
     ((Change
       ((price 138.08) (side Bid) (reason Cancel) (remaining 1.082695)
        (delta -15.493)))))
    (timestamp ((2019-03-27 07:59:59.000000-04:00)))
    (timestampms ((2019-03-27 07:59:59.212000-04:00)))))))
((socket_sequence 114676)
 (message
  (Update
   ((event_id 5788815435)
    (events
     ((Change
       ((price 138.26) (side Ask) (reason Cancel) (remaining 0)
        (delta -50.631)))))
    (timestamp ((2019-03-27 07:59:59.000000-04:00)))
    (timestampms ((2019-03-27 07:59:59.234000-04:00)))))))
((socket_sequence 114677)
 (message
  (Update
   ((event_id 5788815447)
    (events
     ((Change
       ((price 138.45) (side Ask) (reason Cancel) (remaining 0)
        (delta -34.356)))))
    (timestamp ((2019-03-27 07:59:59.000000-04:00)))
    (timestampms ((2019-03-27 07:59:59.246000-04:00)))))))
((socket_sequence 114678)
 (message
  (Update
   ((event_id 5788815451)
    (events
     ((Change
       ((price 138.53) (side Ask) (reason Place) (remaining 35.23)
        (delta 35.23)))))
    (timestamp ((2019-03-27 07:59:59.000000-04:00)))
    (timestampms ((2019-03-27 07:59:59.246000-04:00)))))))
((socket_sequence 114679)
 (message
  (Update
   ((event_id 5788815472)
    (events
     ((Change
       ((price 138.33) (side Ask) (reason Place) (remaining 50.6156)
        (delta 50.6156)))))
    (timestamp ((2019-03-27 07:59:59.000000-04:00)))
    (timestampms ((2019-03-27 07:59:59.359000-04:00)))))))
((socket_sequence 114680)
 (message
  (Update
   ((event_id 5788815475)
    (events
     ((Change
       ((price 138.86) (side Ask) (reason Place) (remaining 37.2)
        (delta 37.2)))))
    (timestamp ((2019-03-27 07:59:59.000000-04:00)))
    (timestampms ((2019-03-27 07:59:59.369000-04:00)))))))
((socket_sequence 114681)
 (message
  (Update
   ((event_id 5788815504)
    (events
     ((Change
       ((price 138.03) (side Bid) (reason Cancel) (remaining 0)
        (delta -42.283316)))))
    (timestamp ((2019-03-27 07:59:59.000000-04:00)))
    (timestampms ((2019-03-27 07:59:59.630000-04:00)))))))
((socket_sequence 114682)
 (message
  (Update
   ((event_id 5788815522)
    (events
     ((Change
       ((price 138.86) (side Ask) (reason Cancel) (remaining 0)
        (delta -37.2)))))
    (timestamp ((2019-03-27 07:59:59.000000-04:00)))
    (timestampms ((2019-03-27 07:59:59.738000-04:00)))))))
((socket_sequence 114683)
 (message
  (Update
   ((event_id 5788815535)
    (events
     ((Change
       ((price 138.07) (side Bid) (reason Place) (remaining 32.836021)
        (delta 5.485909)))))
    (timestamp ((2019-03-27 07:59:59.000000-04:00)))
    (timestampms ((2019-03-27 07:59:59.833000-04:00)))))))
((socket_sequence 114684)
 (message
  (Update
   ((event_id 5788815538)
    (events
     ((Change
       ((price 138.03) (side Bid) (reason Place) (remaining 16.645372)
        (delta 16.645372)))))
    (timestamp ((2019-03-27 07:59:59.000000-04:00)))
    (timestampms ((2019-03-27 07:59:59.833000-04:00)))))))
((socket_sequence 114685)
 (message
  (Update
   ((event_id 5788815541)
    (events
     ((Change
       ((price 138.12) (side Bid) (reason Place) (remaining 33.430907)
        (delta 33.430907)))))
    (timestamp ((2019-03-27 07:59:59.000000-04:00)))
    (timestampms ((2019-03-27 07:59:59.837000-04:00)))))))
((socket_sequence 114686)
 (message
  (Update
   ((event_id 5788815544)
    (events
     ((Change
       ((price 138.13) (side Bid) (reason Place) (remaining 4) (delta 4)))))
    (timestamp ((2019-03-27 07:59:59.000000-04:00)))
    (timestampms ((2019-03-27 07:59:59.838000-04:00)))))))
((socket_sequence 114687)
 (message
  (Update
   ((event_id 5788815549)
    (events
     ((Change
       ((price 138.11) (side Bid) (reason Cancel) (remaining 54.6232)
        (delta -16.681)))))
    (timestamp ((2019-03-27 07:59:59.000000-04:00)))
    (timestampms ((2019-03-27 07:59:59.853000-04:00)))))))
((socket_sequence 114688)
 (message
  (Update
   ((event_id 5788815556)
    (events
     ((Change
       ((price 138.46) (side Ask) (reason Place) (remaining 8.465)
        (delta 8.465)))))
    (timestamp ((2019-03-27 07:59:59.000000-04:00)))
    (timestampms ((2019-03-27 07:59:59.878000-04:00)))))))
2019-03-27 08:00:00.135226-04:00 Error ("Exception raised to [Monitor.try_with] that already returned.""This error was captured by a default handler in [Async.Log]."(exn(monitor.ml.Error(Failure"String \"auction_open\" is not a valid enumeration value. Expected one of trade, change, auction, block_trade")("Raised at file \"stdlib.ml\", line 33, characters 17-33""Called from file \"src/pipe.ml\", line 924, characters 65-70""Called from file \"src/job_queue.ml\", line 159, characters 6-47""Caught by monitor Monitor.protect"))))

Event to csv serialization

It would be useful for the client to produce a csv representation of some events. Using ppx_deriving_csv ought to simplify the task. Support the web socket protocols and maybe the REST versions in the future.

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.