-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
80 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,189 +1,38 @@ | ||
# API Client for [Deribit API](https://www.deribit.com/docs/api/) | ||
# Deribit Simple Gui | ||
|
||
## Description | ||
|
||
The [Deribit API](https://www.deribit.com) is available in this package. | ||
An experimental GUI interface, with a few useful features, for cryptocurrency trading on [Deribit.](https://www.deribit.com) | ||
|
||
### Installation | ||
Uses Deribit API v1. (soon to be deprecated; need to integrate v2 eventually) | ||
|
||
``` | ||
sudo pip install deribit-api | ||
Deribit API docs: | ||
https://www.deribit.com/docs/api/ | ||
|
||
``` | ||
### Usage | ||
|
||
### Example | ||
The program is started from any of the `starter.py` files. | ||
|
||
Modify the variables `path_to_keyfile` and `market` inside | ||
it, to set the relative path to the .txt file containing your API keys, and your desired perpetual contract, | ||
respectively: | ||
``` | ||
from deribit_api import RestClient | ||
client = RestClient("KEY", "SECRET") | ||
client.index() | ||
client.account() | ||
path_to_keyfile = './deribit_keys.txt' # see ordermanger_interface.py for API key syntax | ||
market = 'btc' # either 'btc' or 'eth' | ||
``` | ||
|
||
## API - REST Client | ||
|
||
`new RestClient(key, secret, url)` | ||
|
||
Constructor creates new REST client. | ||
|
||
**Parameters** | ||
|
||
| Name | Type | Decription | | ||
|----------|----------|-----------------------------------------------------------| | ||
| `key` | `string` | Optional, Access Key needed to access Private functions | | ||
| `secret` | `string` | Optional, Access Secret needed to access Private functions| | ||
| `url` | `string` | Optional, server URL, default: `https://www.deribit.com` | | ||
|
||
|
||
### Methods | ||
|
||
* `getorderbook(instrument)` - [Doc](https://www.deribit.com/docs/api/#getinstruments), public | ||
|
||
Retrieve the orderbook for a given instrument. | ||
|
||
**Parameters** | ||
|
||
| Name | Type | Decription | | ||
|--------------|------------|------------------------------------------------------------| | ||
| `instrument` | `string` | Required, instrument name | | ||
|
||
* `index()` - [Doc](https://www.deribit.com/docs/api/#index), public | ||
|
||
Get price index, BTC-USD rates. | ||
|
||
* `getcurrencies()` - [Doc](https://www.deribit.com/docs/api/#getcurrencies), public | ||
|
||
Get all supported currencies. | ||
|
||
* `getorderbook(instrument)` - [Doc](https://www.deribit.com/docs/api/#getorderbook), public | ||
|
||
Retrieve the orderbook for a given instrument. | ||
|
||
**Parameters** | ||
|
||
| Name | Type | Decription | | ||
|--------------|------------|------------------------------------------------------------| | ||
| `instrument` | `string` | Required, instrument name | | ||
|
||
* `getlasttrades(instrument, count, since)` - [Doc](https://www.deribit.com/docs/api/#getlasttrades), public | ||
|
||
Retrieve the latest trades that have occured for a specific instrument. | ||
|
||
**Parameters** | ||
|
||
| Name | Type | Decription | | ||
|--------------|------------|-------------------------------------------------------------------------------| | ||
| `instrument` | `string` | Required, instrument name | | ||
| `count` | `integer` | Optional, count of trades returned (limitation: max. count is 100) | | ||
| `since` | `integer` | Optional, “since” trade id, the server returns trades newer than that “since” | | ||
|
||
* `getsummary(instrument)` - [Doc](https://www.deribit.com/docs/api/#getsummary), public | ||
|
||
Retrieve the summary info such as Open Interest, 24H Volume etc for a specific instrument. | ||
|
||
**Parameters** | ||
|
||
| Name | Type | Decription | | ||
|--------------|------------|------------------------------------------------------------| | ||
| `instrument` | `string` | Required, instrument name | | ||
|
||
* `account()` - [Doc](https://www.deribit.com/docs/api/#account), Private | ||
|
||
Get user account summary. | ||
|
||
* `buy(instrument, quantity, price, postOnly, label)` - [Doc](https://www.deribit.com/docs/api/#buy), private | ||
|
||
Place a buy order in an instrument. | ||
The example above starts the program for the BTC-PERPETUAL swap instrument, using API keys in `deribit_keys.txt`, | ||
located in the same (root) directory. | ||
|
||
**Parameters** | ||
### Keyfile | ||
|
||
| Name | Type | Decription | | ||
|--------------|------------|-----------------------------------------------------------------------------------| | ||
| `instrument` | `string` | Required, instrument name | | ||
| `quantity` | `integer` | Required, quantity, in contracts ($10 per contract for futures, ฿1 — for options) | | ||
| `price` | `float` | Required, USD for futures, BTC for options | | ||
| `postOnly` | `boolean` | Optional, if true then the order will be POST ONLY | | ||
| `label` | `string` | Optional, user defined maximum 4-char label for the order | | ||
|
||
* `sell(instrument, quantity, price, postOnly, label)` - [Doc](https://www.deribit.com/docs/api/#sell), private | ||
|
||
Place a sell order in an instrument. | ||
|
||
**Parameters** | ||
|
||
| Name | Type | Decription | | ||
|--------------|------------|-----------------------------------------------------------------------------------| | ||
| `instrument` | `string` | Required, instrument name | | ||
| `quantity` | `integer` | Required, quantity, in contracts ($10 per contract for futures, ฿1 — for options) | | ||
| `price` | `float` | Required, USD for futures, BTC for options | | ||
| `postOnly` | `boolean` | Optional, if true then the order will be POST ONLY | | ||
| `label` | `string` | Optional, user defined maximum 4-char label for the order | | ||
|
||
* `edit(orderId, quantity, price)` - [Doc](https://www.deribit.com/docs/api/#edit) | ||
|
||
Edit price and/or quantity of the own order. (Authorization is required). | ||
|
||
**Parameters** | ||
|
||
| Name | Type | Decription | | ||
|--------------|------------|-----------------------------------------------------------------------------------| | ||
| `orderId` | `integer` | Required, ID of the order returned by "sell" or "buy" request | | ||
| `quantity` | `integer` | Required, quantity, in contracts ($10 per contract for futures, ฿1 — for options) | | ||
| `price` | `float` | Required, USD for futures, BTC for options | | ||
|
||
* `cancel(orderId)` - [Doc](https://www.deribit.com/docs/api/#cancel), private | ||
|
||
Cancell own order by id. | ||
|
||
**Parameters** | ||
|
||
| Name | Type | Decription | | ||
|--------------|------------|-----------------------------------------------------------------------------------| | ||
| `orderId` | `integer` | Required, ID of the order returned by "sell" or "buy" request | | ||
|
||
* `cancelall(type)` - [Doc](https://www.deribit.com/docs/api/#cancelall) | ||
|
||
Cancel all own futures, or all options, or all. | ||
|
||
**Parameters** | ||
|
||
| Name | Type | Decription | | ||
|--------------|------------|-----------------------------------------------------------------------------------------------| | ||
| `type` | `string` | Optional, type of instruments to cancel, allowed: "all", "futures", "options", default: "all" | | ||
|
||
* `getopenorders(instrument, orderId)` - [Doc](https://www.deribit.com/docs/api/#getopenorders), private | ||
|
||
Retrieve open orders. | ||
|
||
**Parameters** | ||
|
||
| Name | Type | Description | | ||
|--------------|------------|-----------------------------------------------------------------------| | ||
| `instrument` | `string` | Optional, instrument name, use if want orders for specific instrument | | ||
| `orderId` | `integer` | Optional, order id | | ||
|
||
* `positions()` - [Doc](https://www.deribit.com/docs/api/#positions), private | ||
|
||
Retreive positions. | ||
|
||
* `orderhistory(count)` - [Doc](https://www.deribit.com/docs/api/#orderhistory), private | ||
|
||
Get history. | ||
|
||
**Parameters** | ||
|
||
| Name | Type | Description | | ||
|------------|------------|------------------------------------------------------------| | ||
| `count` | `integer` | Optional, number of requested records | | ||
|
||
* `tradehistory(count, instrument, startTradeId)` - [Doc](https://www.deribit.com/docs/api/#tradehistory), private | ||
|
||
Get private trade history of the account. (Authorization is required). The result is ordered by trade identifiers (trade id-s). | ||
|
||
**Parameters** | ||
The contents of your keyfile should be 2 separate lines. On the first is your API key, and the second, your API secret. | ||
``` | ||
ABzGtz9QGVeN | ||
URT2ZLHGG6WTK6XZWKTVZSJLQCXZES46 | ||
test | ||
``` | ||
For use on the [testnet](https://www.test.deribit.com), add a third line containing only the text `test` (as in | ||
above example). | ||
|
||
| Name | Type | Description | | ||
|----------------|------------|----------------------------------------------------------------------------------------------------| | ||
| `count` | `integer` | Optional, number of results to fetch. Default: 20 | | ||
| `instrument` | `string` | Optional, name of instrument, also aliases “all”, “futures”, “options” are allowed. Default: "all" | | ||
| `startTradeId` | `integer` | Optional, number of requested records | | ||
For live usage, leave the third line off completely. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters