Skip to main content

Python Rest Client for Delta Api

Delta Exchange is a crypto derivatives exchange where you can trade bitcoin, ethereum, ripple futures upto 100x leverage. This package is a wrapper around rest apis of Delta Exchange. User Guide - https://www.delta.exchange/user-guide API Documentation - https://docs.delta.exchange

Please read the Changelog before using this package.

Get started

  1. Create an account on Testnet-India: https://testnet.delta.exchange/
    For non-Indian customers use Testnet-Global: https://testnet-global.delta.exchange/
  2. Install the package:
    pip install delta-rest-client
    
  3. Follow the below snippet to trade on testnet:
from delta_rest_client import DeltaRestClient

delta_client = DeltaRestClient(
  base_url='https://cdn-ind.testnet.deltaex.org',
  api_key='',
  api_secret=''
)
base_url for different environments:
Production-India : https://api.india.delta.exchange
(Site at: https://india.delta.exchange/)

Testnet-India : https://cdn-ind.testnet.deltaex.org
(Site at: https://testnet.delta.exchange/)

Production-Global : https://api.delta.exchange
(Site at: https://www.delta.exchange/)

Testnet-Global : https://testnet-api.delta.exchange
(Site at: https://testnet-global.delta.exchange/)
  1. Get json list of available contracts to trade from given url and note down the product_id and asset_id, as it will be used in most of the api calls.

Methods

Get Assets

Get list of assets supported on Delta.

response = delta_client.get_assets()

Get Product Detail

Get product detail of current product. See sample response

product = delta_client.get_product(product_id) # Current Instrument
settling_asset = product['settling_asset'] # Currency in which the pnl will be realised
Name Type Description Required
product_id integer id of product true

Get Ticker Data

See sample response

response = delta_client.get_ticker(symbol)
Name Type Description Required
symbol string product symbol true

Get Orderbook

Get level-2 orderbook of the product. See sample response

response = delta_client.get_l2_orderbook(product_id)
Name Type Description Required
product_id integer id of product true

Open Orders

Get open orders. Authorization required. See sample response

orders = delta_client.get_live_orders()

Place Order

Create a new market order or limit order. Authorization required. See sample response

order_response = delta_client.place_stop_order(
        product_id=product_id,
        size=10,
        side='sell',
				limit_price='7800',
        order_type=OrderType.LIMIT,
     		time_in_force=TimeInForce.FOK
        reduce_only='false'
    )
Name Type Description Required
product_id int id of product true
size int order size true
side string buy or sell true
limit_price string order price (ignored if market order) false
order_type string limit or market false (LIMIT by default)
time_in_force string IOC or GTC or FOK false (GTC by default)
post_only string maker order (true or false) false (false by default)
reduce_only string reduce only order (true or false) false (false by default)

Place Stop Order

Add stop loss or trailing stop loss. Authorization required. See sample response

# Trailing Stop loss
order_response = delta_client.place_stop_order(
        product_id=product_id,
        size=10,
        side='sell',
				limit_price='7800',
        order_type=OrderType.LIMIT,
        trail_amount='20',
        isTrailingStopLoss=True
    )

# Stop loss
order_response = delta_client.place_stop_order(
        product_id=product_id,
        size=10,
        side='sell',
        order_type=OrderType.MARKET,
        stop_price='8010.5',
    )
Name Type Description Required
product_id int id of product true
size int order size true
side string buy or sell true
stop_price string price at which order will be triggered false(required if stop_loss)
trail_amount string trail price false(required if trailing_stop_loss)
limit_price string order price (ignored if market order) false
order_type string limit or market false (LIMIT by default)
time_in_force string IOC or GTC or FOK false (GTC by default)
isTrailingStopLoss string true or false false (false by default)

Cancel Order

Delete open order. Authorization required. See sample response

cancel_response = delta_client.cancel_order(product_id, order_id)
Name Type Description Required
product_id int id of product true
order_id int order id true

Batch Create Orders

Create multiple limit orders. Max number of order is 5. Authorization required. See sample response

response = delta_client.batch_create(product_id, orders)
Name Type Description Required
order array array of orders true

Batch Cancel Orders

Cancel multiple open orders. Max number of order is 5. Authorization required. See sample response

response = delta_client.batch_cancel(product_id, orders)
Name Type Description Required
order array array of orders true

Change Order Leverage

Change leverage for new orders. Authorization required. See sample response

response = delta_client.set_leverage(product_id, leverage)
Name Type Description Required
product_id integer id of product true
leverage string leverage value true

Open Position

Current open position of product. Authorization required. See sample response

response = delta_client.get_position(product_id)
Name Type Description Required
product_id integer id of product true

Change Leverage Positions

Change leverage for open position by adding or removing margin to an open position. Authorization required. See sample response

response = delta_client.change_position_margin(product_id, margin)
Name Type Description Required
product_id integer id of product true
margin string new margin true

Get Wallet Balances

Get user's balance. Authorization required. See sample response

response = delta_client.get_balances(asset_id)
Name Type Description Required
asset_id integer id of asset true

Order History

query = { "product_id": 27 }
response = delta_client.order_history(query, page_size=100)
old_orders = response['result']
after_cursor_for_next_page = response["meta"]["after"]
more_orders = delta_client.order_history(query, page_size=100, after=after_cursor_for_next_page)
Name Type Description Required
page_size integer page size false

Fills

Get fill history of your orders

query = { "contract_types": "futures,interest_rate_swaps" }
response = delta_client.fills(query, page_size=100)

fills = response['result']
after_cursor_for_next_page = response["meta"]["after"]
more_fills = delta_client.fills(query, page_size=100, after=after_cursor_for_next_page)
Name Type Description Required
page_size integer page size false

Metadata

Release files for delta-rest-client 1.0.14

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for delta-rest-client 1.0.14
File Size Uploaded
delta_rest_client-1.0.14.tar.gz 9.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for delta-rest-client 1.0.14
File Interpreter ABI Platform
delta_rest_client-1.0.14-py3-none-any.whl Python 3 none any Details

Total release size: 16.7 kB

Release files / delta_rest_client-1.0.14.tar.gz

Download URL delta_rest_client-1.0.14.tar.gz
Size 9.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d350340961d7867796fea1e5873d5982dda7d1f7c528d60ae60da0dd5d7f0cc6
BLAKE2b-256 checksum
How to use checksums
4894fcb6f1530f96973f6356a31bdda6b456cb7bc070bb671e890a3e8ff36f53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.6

Release files / delta_rest_client-1.0.14-py3-none-any.whl

Download URL delta_rest_client-1.0.14-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
54cfdd74e6842f08c14a4e0100a529a36003d65dc84649b7b4ca43b4b8b1c587
BLAKE2b-256 checksum
How to use checksums
2e7212415938f2161273f910278b20faa3c50ff3711580eb249b168b76a01d1e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.6

Release history Release notifications | RSS feed

This release

1.0.14 This release

2 release files

1.0.12

2 release files

1.0.11

2 release files

1.0.10

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.15

2 release files

0.1.14

2 release files

0.1.13

2 release files

0.1.11

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page