Rest API Endpoints
Public Endpoints
Ping
Pings the Digitex server and returns server timestamp in microseconds. Is used only to check whether server is alive.
ping = client.ping():
Currencies
Returns a list of currencies that the use can have a wallet at.
currencies = client.get_currencies(**kwargs):
Markets
Returns list of markets available to trade.
markets = client.get_markets(**kwargs):
Exchange Information
Returns list of meta data of the exchange, such as list of currencies, list of markets and list of order parameters (ENUMS for order types, duration, etc).
Using integer representation of order parameters is heavily used in our websocket api. At one moment in the future we will fully synchronise these two api’s, hence we use same approach with order parameters as much as possible in this client. And yes, it would have been much easier to use string representation of orders and market names, yet string representation of ‘BUY’ is bigger in size then int 1.
exchange_info = get_exchange_info()
Get Order Book
Returns order book of selected market
order_book = private.get_order_book(market_id=1):
Get Recent Trades
Get recent trades executed at the exchange for selected market
recent_trades = private.get_recent_trades(market_id=1, max_trades=5):
Get K-Lines / OHLCV values
Returns list of K-Lines / OHLCV values for selected market and selected resolution with optional date filters
ohlcv = client.get_k_lines(market_id=1, resolution='1D')
Private Endpoints
Get Account Balance
Get trader’s account balance. In addition to wallet balance, returns available balance per currency - balance that is available for trading
my_balance = client.get_balance()
Get Position
Shows current position of the trader in the futures market.
position = client.get_position():
Get Trade History
Returns paginated trade history
trade_history = client.get_trade_history(**kwargs)
Get Order History
Get trader’s order history. Returns orders that are no longer in execution. These are orders with statuses:
FILLED - numerical status 5. Order has been fully filled
CANCELLED - numerical status 4. Order has been cancelled by user. Note partially filled order can be cancelled as well
REJECTED - numerical status 3. Order has been rejected by matching engine.
order_history = client.get_order_history(**kwargs)
Get Open Orders
Get trader’s open orders. Returns orders that are currently in execution.
These are order with order_status:
PENDING - numerical status 1 - the order has been recieved, however not yet accepted by the exchange matching engine
ACCEPTED - numerical status 2 - the order has been recieved, validated and accepted by the exchange matching engine
PARTIAL - numerical status 6 - ACCEPTED + partially filled. Partial filled information and remaining volume are part of the open order information
orders = client.get_orders(**kwargs)
Get Order Status
Get single order status
order_status = client.get_order_status(order_id='d3c32cc8-89b7-4a4a-8847-7a255e7739ad)
Place an order
Create and place a new order. This requires importing some additional classes:
from dgtx.digitex_rest_core.model.order_duration import OrderDuration
from dgtx.digitex_rest_core.model.order_side import OrderSide
from dgtx.digitex_rest_core.model.order_type import OrderType
from dgtx.extra_data_classes import PlaceOrderMeta
new_order = PlaceOrderMeta(
market_id=1, # BTCUSDS Futures
side=OrderSide(1), # see order_meta for description
duration=OrderDuration(2), # see order_meta for description
leverage=10, # desired leverage
type=OrderType(2), # see order_meta for description
quantity=Decimal(9),
price=Decimal(38000)
)
placed_order = client.place_order(new_order)
“placed_order” is just confirmation of your order params, not the confirmation that the order has been accepted or executed. You can then query order status by calling.
my_order_status = client.get_order_status(client_id=placed_order.client_id)
Cancel order
Cancel order an existing order or orders list or cancel by market_id. This requires additional import of CancelOrder data model.
from dgtx.client import Client
from dgtx.digitex_rest_core.model.cancel_order import CancelOrder
# get order to cancel, e.g. all
orders = client.get_orders()
orders_to_cancel = CancelOrder(
market_id=1, # unique order id is insured only per market level
orders_client_ids=[i.client_id for i in orders.results] # list of orders to cancel
)
cancelled_orders = client.cancel_order(orders_to_cancel)
Status of the orders can then be queried with:
for order_id in cancelled_orders.orders_client_ids:
my_cancelled_order = client.get_order_status(client_id=order_id)
print(my_cancelled_order)