Giter Site home page Giter Site logo

jimmy-sha256 / deribit_websocket_v2 Goto Github PK

View Code? Open in Web Editor NEW
41.0 2.0 17.0 688 KB

This is a python wrapper written to make it simple to connect to Deribit's JSON-RPC api v2 using websockets.

License: MIT License

Python 100.00%
deribit deribit-api deribit-api-v2 python websocket v2

deribit_websocket_v2's Introduction

Deribit Websocket API v2

This is a python wrapper written to make it simple to connect to Deribit's JSON-RPC api v2 using websockets.

Table of Contents

  1. Installation
  2. Credentials
  3. Index Price
  4. Ticker Data
  5. Buy
  6. Sell
  7. Stop Buy
  8. Stop Sell
  9. Edit
  10. Cancel
  11. Cancel All
  12. Account Summary
  13. Get Position
mkdir deribit_ws && cd deribit_ws

git clone https://github.com/Jimmy-sha256/deribit_ws.git

virtualenv --python=/usr/bin/python3.10 venv

source /venv/bin/activate

pip install -r requirements.txt

Add your deribit api access key and access secret to the credentials.py file:

Add either main-net or test-net websocket url to credentials.py file:

  • wss://testapp.deribit.com/ws/api/v2
  • wss://deribit.com/ws/api/v2

index(currency)
Paramaters Type Description
currency string 'BTC', 'ETH'

https://docs.deribit.com/v2/#public-get_index

ticker(instrument_name)

Paramaters Type Description
instrument_name string 'BTC-PERPETUAL', 'ETH-PERPETUAL'

https://docs.deribit.com/v2/#public-ticker

buy(instrument_name, amont, order_type, price, post_only)

Paramaters Type Description
instrument_name string 'BTC-PERPETUAL', 'ETH-PERPETUAL'
amount int number of contracts to purchase
order_type string 'market', 'limit'
price int price to purchase contracts at
post_only boolean True / False

https://docs.deribit.com/v2/#private-buy

sell(instrument_name, amont, order_type, price, post_only)

Paramaters Type Description
instrument_name string 'BTC-PERPETUAL', 'ETH-PERPETUAL'
amount int number of contracts to purchase
order_type string 'market', 'limit'
price int price to purchase contracts at
post_only boolean True / False

https://docs.deribit.com/v2/#private-sell

stop_buy(instrument_name, trigger, amont, order_type, stop_price, price)

Paramaters Type Description
instrument_name string 'BTC-PERPETUAL', 'ETH-PERPETUAL'
trigger string 'index_price', 'mark_price', 'last_price'
amount int number of contracts to purchase
order_type string 'stop_market', 'stop_limit'
stop_price int price at which order is triggered
price int price to purchase contracts at

https://docs.deribit.com/v2/#private-buy

stop_sell(instrument_name, trigger, amont, order_type, stop_price, price)

Paramaters Type Description
instrument_name string 'BTC-PERPETUAL', 'ETH-PERPETUAL'
trigger string 'index_price', 'mark_price', 'last_price'
amount int number of contracts to purchase
order_type string 'stop_market', 'stop_limit'
stop_price int price at which order is triggered
price int price to purchase contracts at

https://docs.deribit.com/v2/#private-sell

edit(order_id, amount, price)

Paramaters Type Description
order_id string id of order '3032588463'
amount int edit number of contracts
price int edit price of contracts

https://docs.deribit.com/v2/#private-edit

cancel(order_id)

Paramaters Type Description
order_id string id of order to be canceled '3032588463'

https://docs.deribit.com/v2/#private-cancel

cancel_all()

This method takes no parameters

https://docs.deribit.com/v2/#private-cancel_all

account_summary(currency)

Paramaters Type Description
currency string 'BTC', 'ETH'

https://docs.deribit.com/v2/#private-get_account_summary

get_position(currency)

Paramaters Type Description
instrument_name string 'BTC-PERPETUAL', 'ETH-PERPETUAL'

https://docs.deribit.com/v2/#private-get_position

deribit_websocket_v2's People

Contributors

dependabot[bot] avatar jimmy-sha256 avatar

Stargazers

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

Watchers

 avatar  avatar

deribit_websocket_v2's Issues

Subscribe to multiple options?

I am trying to subscribe to basically all options i can via deribit to stream their order book data. Can this be done in this wrappers current state? If not I would be willing to help to try to bring it to an ability to do this

retrieve subscriptions and heartbeat

I wonder how it is possible to subscribe to a few private channels, and just keep an active loop and print any changes that come during the subscription.

also heartbeat seems not inserted yet, are you making this later on?

Orders do not get posted

Thanks for the code. I am new to python and api but I managed to authenticate to the test version of deribit and to fill market orders. However, limit orders that are not filled immediately always get cancelled, so I am unable to use stop limit orders or buy orders that are too low or well orders that are too high. I use the default option good_til_cancelled for time in force. Thanks for your help.

Work with subscriptions

Hi. Do you plan to add a possibility to work with the subscription outputs? It would be very effective to just "ping" once, let the WS open forever and fetch only one variable in some other Python class to get the updates.

Need get actual order list. How?

Great simple code. I am not so familar with websocket, threading, etc , but strongly need actual order list for fantastic HTF scalping and have similar bot on bitmex.
This code is very simple and beautiful, but without actual order list feature useless for me (
If I right understand , i need this functional:

  1. take full order list from REST API
  2. do separate infinite loop on orders change channel, maybe at separate thread
  3. modify local order list with events from orders change channel
    Not trivial task for me, unfortunally ((
    Maybe anybody, who can do this easy, can help me with this big trouble

Market orders working / but not limit orders?

answer = client.buy('BTC-PERPETUAL', 10, 'limit', False, price = 64460)
would be
{'jsonrpc': '2.0', 'id': 1, 'result': {'trades': [], 'order': {'is_liquidation': False, 'risk_reducing': False, 'order_type': 'limit', 'creation_timestamp': 1709663161987, 'order_state': 'open', 'contracts': 1.0, 'average_price': 0.0, 'reduce_only': False, 'post_only': False, 'last_update_timestamp': 1709663161987, 'filled_amount': 0.0, 'replaced': False, 'web': False, 'api': True, 'mmp': False, 'instrument_name': 'BTC-PERPETUAL', 'order_id': '66581975120', 'max_show': 10.0, 'time_in_force': 'good_til_cancelled', 'amount': 10.0, 'direction': 'buy', 'price': 64460.0, 'label': ''}}, 'usIn': 1709663161985366, 'usOut': 1709663161988051, 'usDiff': 2685, 'testnet': False}

trying to cancel this order_id
d = client.cancel(order_id)
returns
{'jsonrpc': '2.0', 'id': 1, 'error': {'message': 'not_open_order', 'code': 11044}, 'usIn': 1709663172181556, 'usOut': 1709663172183829, 'usDiff': 2273, 'testnet': False}

Any help greatly appreciated : very nice code otherwise; good start to build more

How will unsubscription work?

Deribit API provides public/unsubscribe_all method to unsubscribe all channels. I am running a script that is subscribing to multiple channels. I am using asyncio.get_event_loop() to run in coroutines. My issue is that after a certain time period I have to disconnect from existing channels and subscribe to newer ones. I ran another script to call unsubscribe_all but in other window it does not un-subscribe at all and it keeps pulling data.

Can you tell me some way to do it?

Version 2.0

Hello,

I want to contribute and am just working on an enhanced version, capable of more account sessions (in order to be possibly able to work with more accounts with different API keys at the same time), correctly and immediately parsed response to work with and more endpoints. Could you or would you be willing to merge it later or put a link to it in the description?

Thanks.

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.