Rest Client for Delta Exchange
Project description
python-rest-client
Get started
-
Create an account on https://testnet.delta.exchange/signup
-
Install the package:
pip install delta-rest-client
- Follow the below snippet to trade on testnet:
from delta_rest_client import DeltaRestClient, create_order_format, cancel_order_format, round_by_tick_size
delta_client = DeltaRestClient(
base_url='https://testnet-api.delta.exchange',
api_key='',
api_secret=''
)
# Get orders
product_id = 2
product = delta_client.get_product(product_id)
settling_asset = product['settling_asset']
# Single Order
order = create_order_format(7078.5, 10, "buy", product_id)
delta_client.create_order(order) # will create order on testnet
# Batch orders
order1 = create_order_format(7078.5, 10, "buy", product_id)
order2 = create_order_format(7078.5, 10, "sell", product_id)
orders = [order1, order2]
delta_client.batch_create(product_id, orders)
# get my open orders
delta_client.get_orders(query={
'state': 'open'
})
# Get l2 orderbook
delta_client.get_L2_orders(product_id)
# Get l1 orderbook
delta_client.get_ticker(product_id)
# Get wallet balance
delta_client.get_wallet(settling_asset['id'])
# Change Leverage for all open orders
delta_client.set_leverage(product_id=product_id, leverage='2.5')
# Change margin for a product
delta_client.change_position_margin(product_id=product_id, delta_margin='0.05')
# Use can use .request to access rest apis which are not covered
# Example on how to top up a position without using the exposed function
response = delta_client.request('POST', 'positions/change_margin', {
'product_id': product_id,
'delta_margin': '0.05'
}, auth=True)
print(response.json())
# Calculating position value & unrealized pnl for the position
from decimal import Decimal
product_id = 2
product = delta_client.get_product(product_id)
position = delta_client.get_position(product_id=product_id)
print('Liquidation Price: %s, Entry Price: %s, Margin: %s' % (
position['liquidation_price'], position['entry_price'], position['margin'])
mark_price = delta_client.get_mark_price(product_id=product_id)
if product['product_type'] == 'inverse_future':
position_value = int(position['size']) / Decimal(position['entry_price'])
unrealized_pnl = int(position['size']) * (1/Decimal(position['entry_price']) - 1/Decimal(mark_price))
else:
position_value = int(position['size']) * Decimal(position['entry_price'])
unrealized_pnl = int(position['size']) * (Decimal(mark_price) - Decimal(position['entry_price']))
- Verify your orders on https://testnet.delta.exchange
Same steps can used for production trading.
- Production base_url is https://api.delta.exchange
- Production trade terminal url is https://trade.delta.exchange/
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for delta_rest_client-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07673c5092cd2fcd13456487cb30b46db288b1a2867cbab2949b6f06f762071c |
|
MD5 | a7f1a598700c6c89dc6f7bd9c3e660b9 |
|
BLAKE2b-256 | 5fb0addc870c35c59ea022fbf53865bd6dafefa3a376d352d3c810e9140111f4 |