Please adjust your script settings in order to trade on Quedex.Net.
Version: 0.6.0 (2020-02-11)
Quedex provides a realtime asynchronous WebSocket API, which is divided into two parts: User Stream and Market Stream, which are described in detail below. User Stream enables sending of authenticated Commands on behalf of an account and receiving Events describing changes to an account. Market Stream enables receiving Events describing public trading data.
We provide implementations of the API in Java and Python. If you use one of these two languages we encourage you to use these implementations, as they hide most of the technical details. Please refer to the Github repositories linked above for the documentation; documentation on this page may still be useful, as it provides some general information and restrictions of the API.
There is also a simplistic, exemplary market making bot presenting how the Java API may be used.
The whole API uses JSON as data serialization format. All the entities described below are JSON objects with the described fields. The following types are used throughout the API (other custom types are described in detail where they occur):
Type name | Type description |
---|---|
String | standard JSON string |
Decimal | represents decimal value; always serialized to JSON string (events); accepted as JSON string or number (commands) |
long | 64 bit precision signed integer; serialized to JSON string in all cases when it does not represent a timestamp, where JSON number is used (events); accepted as JSON string or number (commands) |
int | 32 bit precision signed integer; serialized to JSON string in all cases; accepted as JSON string or number (commands) |
Serialization of types Btc, long, int to JSON string in case of events and accepting JSON string in case of commands is motivated by compatibility with JavaScript (64 bit integers may not fit into JavaScript's number and JavaScript has no native representation of fixed precision numbers).
To connect to the stream open a WebSocket connection to wss://api.quedex.net/user_stream. The stream enables sending authenticated Commands and receiving Events for an account. Each Command is accompanied by an Event which constitutes a response. Additionally, there is a number of asynchronous Events, which are emitted after subscribing (see subscribe Command).
Commands should be sent as text WebSocket messages, ASCII-armored PGP-signed and encrypted as defined by the PGP protocol (and implemented by e.g. GPG). The account's key should be used for signing - ASCII-armored key may be found in our web application - on the trading dashboard select the dropdown menu with your email address in the upper right corner and go to User Profile; they key is encrypted with your Session Password. Quedex's key with fingerprint 0C56 7B5B CE92 7242 05AD 9EC4 CEC2 D052 6BFA BE4F should be used for encryption (may be found e.g. on pgp.mit.edu). Whenever account_id is needed in a Command, it should be the id of your account - may be found in User Profile, similarly to the account's key.
Sending Commands is subject to the following limits:
Each command (apart from get_last_nonce) has a nonce field, which has to be a strictly increasing (per nonce_group) number. Please note that nonce_group equal to 0 is used in the webapplication, so if you want to be able to use the webapplication when your trading bot is running, you'll need to use a different nonce_group in the bot.
The following commands are available:
Creates a new timer in the exchange core. Based on the timer configuration, at some point in the future (between execution_start_timestamp and execution_expiration_timestamp), the carried user command is processed.
Note:The granularity of execution is 1 second.
If the time difference between execution_start_timestamp and execution_expiration_timestamp is lower than 1000 ms, then the timer may not be triggered. The recommended minimum difference is 2000 ms. But this does not guarantee that timer will be triggered in two situations:If execution_start_timestamp is in the past and execution_expiration_timestamp is in the future, the carried command will be processed immediately.
Timers are ordered by execution_start_timestamp and order of arrival. Timers with earlier execution_start_timestamp are processed first. When there are more timers with the same execution_start_timestamp they are triggered by the order of arrival.
Note:Each user can have up to 10 active timers.
In response timer_added or timer_rejected event is sent. Additionally when the added timer is triggered and the carried command is processed a timer_triggered is sent. In a case when the added timer is not triggered before execution_expiration_timestamp a timer_expired is sent.Command fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "add_timer" |
nonce | long | strictly increasing (per nonce group) number > 0 |
nonce_group | int | number between 0-9 |
account_id | long | id > 0 of the account |
timer_id | long | non null id of the timer, must be unique among all currently active timers, it is used to update and cancel timers, but also to identify content of registered timers |
command | UserCommand | command to be executed between execution_start_timestamp and execution_expiration_timestamp, if the command has nonce, it must be > than nonce of the parent add_timer command |
execution_start_timestamp | long | beginning of the execution interval > 0 |
execution_expiration_timestamp | long | end of the execution interval > 0 |
Sends a batch of place_order and cancel_order commands. Commands from the list will be run sequentially and no other command will interleave the execution. Errors in processing commands do not stop processing of the whole batch. Batching should be used whenever possible to minimise latency and maximise throughput.
Command fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "batch" |
account_id | long | id > 0 of the account |
batch | OrderCommand[] | nonempty list of objects containing place, cancel or modify order commands; the list must not contain more than 4 entries (if you need to send larger batches please contact us) |
Cancels all orders placed by user. In case of success zero or more order_cancelled events are emitted, each for every cancelled order followed by single all_orders_cancelled event. In case of failure single cancel_all_orders_failed event is emitted. All responses have nonce the same as nonce of this command.
Command fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "cancel_all_orders" |
nonce | long | strictly increasing (per nonce group) number > 0 |
nonce_group | int | number between 0-9 |
account_id | long | id > 0 of the account |
Cancels a placed order. In response order_cancelled or order_cancel_failed event is sent.
Command fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "cancel_order" |
nonce | long | strictly increasing (per nonce group) number > 0 |
nonce_group | int | number between 0-9 |
account_id | long | id > 0 of the account |
client_order_id | long | id > 0 of the order to cancel as specified in place order command |
Cancels a created timer. In response timer_cancelled or timer_cancel_failed event is sent.
Command fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "cancel_timer" |
nonce | long | strictly increasing (per nonce group) number > 0 |
nonce_group | int | number between 0-9 |
account_id | long | id > 0 of the account |
timer_id | long | non null id of the existing timer |
Requests last nonce. In response last_nonce event is sent.
Command fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "get_last_nonce" |
account_id | long | id > 0 of the account |
nonce_group | int | number between 0-9 for which last nonce is requested |
Requests an internal transfer of BTC from the sender to user with given id. In response to this command, an internal_transfer_executed or internal_transfer_rejected event is sent. This functionality is disabled by default - please contact us, if you'd like to have it enabled.
Command fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "internal_transfer" |
nonce | long | strictly increasing (per nonce group) number > 0 |
nonce_group | int | number between 0-9 |
account_id | long | id > 0 of the sender account |
amount | Decimal | amount > of the internal transfer in BTC, has to be < account's free balance |
destination_account_id | long | id > of the account to send funds to |
Modifies price ond/or quantity of a placed order. In response order_modified or order_modification_failed event is sent.
Command fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "modify_order" |
nonce | long | strictly increasing (per nonce group) number > 0 |
nonce_group | int | number between 0-9 |
account_id | long | id > 0 of the account |
client_order_id | long | id > 0 of the order, must be unique among all currently pending orders |
new_price | Decimal | new limit price of the order in USD for futures and BTC for options; may be absent or null if new quantity is specified |
new_quantity | Integer | new initial quantity > 0 of the order, must be < 1000000; the filled quantity of the order will not be changed; may be absent or null if new price is specified |
post_only | boolean | boolean, whether this order modification should be post-only (cannot cause an immediate trade) |
Places new order. In response order_placed or order_place_failed event is sent. When the order is matched order_filled event is emitted (requires subscription). When the order is forcefully cancelled order_forcefully_cancelled event is emitted (requires subscription).
Command fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "place_order" |
nonce | long | strictly increasing (per nonce group) number > 0 |
nonce_group | int | number between 0-9 |
account_id | long | id > 0 of the account |
client_order_id | long | id > 0 of the order, must be unique among all currently pending orders |
instrument_id | int | id > 0 of an instrument, must specify a valid tradable instrument |
order_type | OrderType | string, currently always equal to "limit" |
limit_price | Decimal | limit price of the order in USD for futures and BTC for options |
side | OrderSide | string, either "buy" or "sell" |
quantity | int | quantity > 0 of the order, must be < 1000000 |
post_only | boolean | boolean, whether this order should be post-only (cannot cause an immediate trade) |
Creates subscription on the user stream. In response to this command subscribed event is sent. Afterwards, events which require subscription will be sent, i.e.: account_state, deposit_confirmed, internal_transfer_received, socialised_losses, withdrawal_broadcast, withdrawal_cancelled, open_position, order_filled. An account may have up to 10 subscriptions at a time. A subscription is cancelled automatically when WebSocket connection is closed.
Command fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "subscribe" |
nonce | long | strictly increasing (per nonce group) number > 0 |
nonce_group | int | number between 0-9 |
account_id | long | id > 0 of the account |
Modifies a created timer. At least one of the following must be specified:
new_commandreplaces a command registered during the timer creation.
When only new_execution_expiration_timestamp or/and new_command are specified, the timer is modified in place. This means that the update does not change the order of already registered timers. When new_execution_start_timestamp is specified, then the timer will be placed after other existing timers with the same execution_start_timestamp.
In response timer_updated or timer_update_failed event is sent.See: add_timer
Command fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "update_timer" |
nonce | long | strictly increasing (per nonce group) number > 0 |
nonce_group | int | number between 0-9 |
account_id | long | id > 0 of the account |
timer_id | long | non null id of the timer, must be unique among all currently active timers |
new_command | UserCommand | a new command to be executed; replaces a command specified by the create command |
new_execution_start_timestamp | Long | a new beginning of the execution interval |
new_execution_expiration_timestamp | Long | a new end of the execution interval |
Requests a withdrawal of account funds. In response withdrawal_accepted or withdrawal_rejected event is sent.
Command fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "withdraw" |
nonce | long | strictly increasing (per nonce group) number > 0 |
nonce_group | int | number between 0-9 |
account_id | long | id > 0 of the account |
amount | Decimal | amount > 0.01 of the withdrawal in BTC, has to be < account's free balance |
btc_address | String | valid BTC address the withdrawal should go to |
Events are received as text WebSocket messages. Each arrives as JSON with the following fields:
Name | Type | Description |
type | String | one of "data", "error", "keepalive" (be prepared that new types may be added) |
error_code | String | present if type is "error", specifies the error |
data | String | present if type is "data"; contains ASCII-armored PGP-signed and encrypted message (signed using Quedex's key and encrypted using account's - for how to get the keys see section Commands above); the message is a JSON list of JSON objects, which may be one of the Events listed below |
Keepalive messages are sent every 15 seconds. Lack of such message may indicate broken connection.
The following events are available (be prepared that new events not listed here may arrive):
Emitted on changes to account state. All contained numeric values are in BTC.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "account_state" |
balance | Decimal | total cash balance of the account in BTC |
free_balance | Decimal | cash balance available for opening new positions in BTC |
locked_free_balance | Decimal | locked cash balance available for opening new positions in BTC for locked accounts |
total_initial_margin | Decimal | total initial margin of all positions and pending orders in BTC |
total_maintenance_margin | Decimal | total maintenance margin of all positions and pending orders in BTC |
total_locked_for_orders | Decimal | total amount locked for order fees in BTC |
total_unsettled_pnl | Decimal | total unsettled PnL of the account in BTC |
total_pending_withdrawal | Decimal | total pending withdrawal of the account in BTC |
total_referrer_rebate | Decimal | total amount earned from referred users in BTC |
account_status | AccountStatus | String status of the account, one of "active", "margin_call", "liquidation", "locked" |
Emitted in response to cancel_all_orders command.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "all_orders_cancelled" |
message_nonce | long | nonce of the command this event responds to |
message_nonce_group | int | nonce group of the command this event responds to |
Emitted when authentication of a command failed.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "authentication_failed" |
Emitted in response to failed cancel_all_orders command.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "cancel_all_orders_failed" |
message_nonce | long | nonce of the command this event responds to |
message_nonce_group | int | nonce group of the command this event responds to |
cause | Cause | string, currently only one possible: "session_not_active" |
Emitted when a BTC deposit is confirmed. Represents deposit which is confirmed on the BTC network, added to locked deposits and needs an administrative unlock to be available for trading.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "deposit_confirmed_2" |
source_addresses | Set | source BTC addresses of the deposit |
destination_address | BtcAddress | deposit BTC address of the account |
btc_amount | Decimal | amount of the deposit, in BTC |
btc_transaction_id | String | txid of the deposit transaction |
btc_output_number | int | vout of the deposit transaction |
confirmations | long | number of confirmations of the deposit transaction |
Emitted after a BTC deposit is unlocked administratively.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "deposit_unlocked" |
destination_address | BtcAddress | deposit BTC address of the account |
btc_transaction_id | String | txid of the deposit transaction |
btc_output_number | int | vout of the deposit transaction |
btc_amount | Decimal | amount of the deposit, in BTC |
Emitted in response to internal_transfer command on successful transfer.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "internal_transfer_executed" |
message_nonce | long | nonce of the command this event responds to |
message_nonce_group | int | nonce group of the command this event responds to |
destination_account_id | long | id of the account the funds were sent to |
amount | Decimal | amount of the internal transfer in BTC |
Emitted when different account sends internal_transfer successful command with this account specified as destination.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "internal_transfer_received" |
source_account_id | long | id of the account sending the internal transfer |
amount | Decimal | amount of the internal transfer received in BTC |
Emitted in response to internal_transfer command on rejected transfer.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "internal_transfer_rejected" |
message_nonce | long | nonce of the command this event responds to |
message_nonce_group | int | nonce group of the command this event responds to |
cause | Cause | String cause of rejection, one of "insufficient_funds", "forbidden" |
destination_account_id | long | id of the account the funds were sent to |
amount | Decimal | amount of the internal transfer in BTC |
Emitted after a command with an invalid nonce is received.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "invalid_nonce" |
message_nonce | Long | nonce of the command this event responds to |
message_nonce_group | int | nonce group of the command this event responds to |
last_nonce | Long | last nonce of the account |
Emitted in response to get_last_nonce command.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "last_nonce" |
nonce_group | int | nonce group of the command this event responds to |
last_nonce | long | last nonce of the account |
Emitted by Quedex exchange when a liquidation order is cancelled.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "liquidation_order_cancelled" |
system_order_id | long | system id of the cancelled order |
instrument_id | int | instrument id this order is for |
side | OrderSide | string, either "buy" or "sell" |
order_type | OrderType | string, aways equal to "market" |
initial_quantity | int | initial quantity of the order |
Emitted when liquidation order is filled (a trade is made).
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "liquidation_order_filled" |
system_order_id | long | system id of the order |
instrument_id | int | id of the instrument this order is for |
order_fill_id | long | unique id of the order fill |
order_type | OrderType | string, always equal to "market" |
order_side | OrderSide | string, either "buy" or "sell" |
order_initial_quantity | int | initial quantity the order was created with |
leaves_order_quantity | int | current unfilled quantity of the order |
trade_price | Decimal | price of the trade |
trade_quantity | int | quantity filled in this trade |
effective_fee | Decimal | effective fee paid to the exchange |
taker_to_maker | Decimal | fee paid from the taker to maker of this trade |
Emitted when a liquidation order is placed by the exchange.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "liquidation_order_placed" |
system_order_id | long | system id of the order |
instrument_id | int | id of the instrument this order is for |
order_type | OrderType | string, always equal to "market" |
side | OrderSide | string, either "buy" or "sell" |
quantity | int | current quantity of the order |
initial_quantity | int | initial quantity of the order |
Emitted by Quedex exchange on each change to an open position.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "open_position" |
instrument_id | int | id of the instrument this position is for |
pnl | Decimal | total PnL of this position in BTC |
maintenance_margin | Decimal | maintenance margin of this position in BTC |
initial_margin | Decimal | initial margin of this position in BTC |
side | PositionSide | string, either "long" or "short" |
quantity | int | quantity >= 0 of this position |
average_opening_price | Decimal | average price this position has been opened at in BTC |
Emitted by Quedex engine after open position is automatically closed in order to prevent bankruptcy.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "open_position_forcefully_closed" |
instrument_id | int | id of the instrument the position was for |
side | PositionSide | string, either "long" or "short" |
closed_quantity | int | quantity > 0 which was closed |
remaining_quantity | int | quantity >= 0 which remained after closing (0 if position was fully closed) |
close_price | Decimal | price at which the position was closed |
cause | Cause | string, either "bankruptcy" or "deleveraging" |
Emitted in response to failed cancel_order command.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "order_cancel_failed" |
message_nonce | long | nonce of the command this event responds to |
message_nonce_group | int | nonce group of the command this event responds to |
client_order_id | long | id of the order |
cause | Cause | string, one of "not_found", "session_not_active" |
Emitted in response to a successful cancel_order command.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "order_cancelled" |
message_nonce | long | nonce of the command this event responds to |
message_nonce_group | int | nonce group of the command this event responds to |
client_order_id | long | id of the order |
instrument_id | int | id of the instrument the order is for |
limit_price | Decimal | limit price of the order |
side | OrderSide | string, either "buy" or "sell" |
order_type | OrderType | string, always equal to "limit" |
initial_quantity | int | quantity the order was created with |
Emitted when order is filled (a trade is made).
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "order_filled" |
client_order_id | long | id of the order |
instrument_id | int | id of the instrument the order is for |
order_fill_id | long | unique id of the order fill |
order_limit_price | Decimal | limit price of the order |
order_type | OrderType | string, always equal to "limit" |
order_side | OrderSide | string, either "buy" or "sell" |
order_initial_quantity | int | initial quantity the order was created with |
leaves_order_quantity | int | current unfilled quantity of the order |
trade_price | Decimal | price of the trade |
trade_quantity | int | quantity filled in this trade |
effective_fee | Decimal | effective fee paid to the exchange |
taker_to_maker | Decimal | fee paid from the taker to maker of this trade |
Emitted when an order has been forcefully cancelled by the exchange.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "order_forcefully_cancelled" |
client_order_id | long | id of the order |
instrument_id | int | id of the instrument the order was for |
limit_price | Decimal | limit price of the order in BTC |
side | OrderSide | string, either "buy" or "sell" |
order_type | OrderType | string, always equal to "limit" |
initial_quantity | int | initial quantity the order has been placed with |
cause | Cause | string, either "liquidation" or "settlement" |
Emitted in response to a failed modify_order command.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "order_modification_failed" |
message_nonce | long | nonce of the command this event responds to |
message_nonce_group | int | nonce group of the command this event responds to |
client_order_id | long | id of the order |
new_limit_price | Decimal | price of the order after modification |
new_initial_quantity | int | updated initial quantity of the order |
cause | Cause | string, one of "invalid_order_id", "invalid_instrument_id", "session_not_active", "invalid_tick_size", "insufficient_funds", "margin_call", "not_found", "open_position_quantity_too_high", "not_post" |
Emitted in response to successful modify_order command.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "order_modified" |
message_nonce | long | nonce of the command this event responds to |
message_nonce_group | int | nonce group of the command this event responds to |
client_order_id | long | id of the order |
instrument_id | int | id of the instrument the order is for |
new_limit_price | Decimal | price of the order after modification |
new_initial_quantity | int | updated initial quantity of the order |
new_leaves_quantity | int | current quantity of the order after the modification |
side | OrderSide | string, either "buy" or "sell" |
order_type | OrderType | string, always equal to "limit" |
Emitted in a response to failed place_order command.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "order_place_failed" |
message_nonce | long | nonce of the command this event responds to |
message_nonce_group | int | nonce group of the command this event responds to |
client_order_id | long | id of the order |
instrument_id | int | id of the instrument the order was for |
order_type | OrderType | string, always equal to "limit" |
limit_price | Decimal | limit price of the order |
side | OrderSide | string, either "buy" or "sell" |
quantity | int | quantity of the order |
cause | Cause | string, one of "invalid_order_id", "invalid_instrument_id", "session_not_active", "invalid_tick_size", "insufficient_funds", "too_many_open_orders", "open_position_quantity_too_high", "not_post" |
Emitted in response to successful place_order command.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "order_placed" |
message_nonce | long | nonce of the command this event responds to |
message_nonce_group | int | nonce group of the command this event responds to |
client_order_id | long | id of the order |
instrument_id | int | id of the instrument the order is for |
order_type | OrderType | string, always equal to "limit" |
limit_price | Decimal | limit price of the order |
side | OrderSide | string, either "buy" or "sell" |
quantity | int | quantity of the order |
initial_quantity | int | quantity of the order |
Emitted in response to subscribe command. Immediately after this event is emitted, a "welcome pack" of events is sent, which will consist of order_placed event for each pending order, open_position event for each open position, timer_added for each registered timer and an initial account_state. All the events emitted afterwards are guaranteed to modify this initial state.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "subscribed" |
message_nonce | long | nonce of the command this event responds to |
message_nonce_group | int | nonce group of the command this event responds to |
Emitted in response to a successful add_timer command. It is also emitted in a "welcome pack" for each registered timer.
See: subscribed
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "timer_added" |
message_nonce | long | nonce of the command this event responds to |
message_nonce_group | int | nonce group of the command this event responds to |
timer_id | long | id of the added timer which uniquely identifies timer and its content |
Emitted in response to a failed cancel_timer command.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "timer_cancel_failed" |
message_nonce | long | nonce of the command this event responds to |
message_nonce_group | int | nonce group of the command this event responds to |
timer_id | long | id of the non cancelled timer |
cause | Cause | String cause of failure; currently only "not_found" |
Emitted in response to a successful cancel_timer command.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "timer_cancelled" |
message_nonce | long | nonce of the command this event responds to |
message_nonce_group | int | nonce group of the command this event responds to |
timer_id | long | id of the cancelled timer |
Emitted in response to an expired add_timer command.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "timer_expired" |
timer_id | long | id of the expired timer |
Emitted in response to a rejected add_timer command.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "timer_rejected" |
message_nonce | long | nonce of the command this event responds to |
message_nonce_group | int | nonce group of the command this event responds to |
timer_id | long | id of the accepted timer |
cause | Cause | String cause of rejection; one of "too_many_active_timers", "timer_already_expired", "timer_already_exists" |
Emitted in response to a triggered add_timer command.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "timer_triggered" |
timer_id | long | id of the triggered timer |
Emitted in response to a failed update_timer command.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "timer_update_failed" |
message_nonce | long | nonce of the command this event responds to |
message_nonce_group | int | nonce group of the command this event responds to |
timer_id | long | id of the non updated timer |
cause | Cause | String cause of failure; one of "not_found", "timer_execution_interval_broken" |
Emitted in response to a successful update_timer command.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "timer_updated" |
message_nonce | long | nonce of the command this event responds to |
message_nonce_group | int | nonce group of the command this event responds to |
timer_id | long | id of the updated timer |
Emitted in response to a successful withdraw command or to an administrative withdrawal action.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "withdrawal_accepted" |
message_nonce | Long | nonce of the command this event responds to, null if "is_administrative" is true |
message_nonce_group | Integer | nonce group of the command this event responds to, null if "is_administrative" is true |
destination_address | BtcAddress | BTC address the withdrawal should go to |
btc_amount | Decimal | amount of the withdrawal in BTC |
is_administrative | boolean | flag indicating whether this withdrawal has been submitted administratively (by platform operator) |
Emitted when a BTC withdrawal is broadcast to the network.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "withdrawal_broadcast" |
destination_address | BtcAddress | BTC address the withdrawal goes to |
btc_amount | Decimal | amount of the withdrawal in BTC |
Emitted when a BTC withdrawal is forcefully cancelled during liquidation.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "withdrawal_cancelled" |
destination_address | BtcAddress | BTC address the withdrawal goes to |
btc_amount | Decimal | amount of the withdrawal in BTC |
Emitted in response to a rejected withdraw command.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "withdrawal_rejected" |
message_nonce | long | nonce of the command this event responds to |
message_nonce_group | int | nonce group of the command this event responds to |
cause | Cause | String cause of rejection, one of "insufficient_funds", "amount_too_small", "too_many_pending_withdrawals" |
destination_address | BtcAddress | valid BTC address the withdrawal should go to |
btc_amount | Decimal | amount of the withdrawal in BTC |
To connect to the stream open a WebSocket connection to wss://api.quedex.net/market_stream. The stream enables receiving asynchronous Events, which are described below. Once you connect to the stream a "welcome pack" will be sent, consisting of the following events: instrument_data, session_state and for each active instrument: last quotes, last order_book and last 10 trade events.
Events are received as text WebSocket messages. Each arrives as JSON with the following fields:
Name | Type | Description |
type | String | one of "data", "error", "keepalive" (be prepared that new types may be added) |
error_code | String | present if type is "error", specifies the error |
data | String | present if type is "data"; contains ACSII-armored PGP-clearsigned message (signed using Quedex's key - for how to get the key see section Commands in User Stream above); the message is a JSON object, which may be one of the Events listed below |
Keepalive messages are sent every 15 seconds. Lack of such message may indicate broken connection.
The following events are available (be prepared that new events not listed here may arrive):
Information about currently tradable instruments. Emitted when instruments expire or are issued.
The objects describing instruments are as follows:
Inverse futures contract definition.
Instrument parameters:
Name | Type | Description |
---|---|---|
type | String | always equal to "inverse_futures" |
symbol | String | symbol pattern is "F.BTCUSD.DDMMMYY", e.g. "F.BTCUSD.02FEB18" |
instrument_id | int | unique id of the instrument |
tick_size | Btc | tick size of the instrument; price of all orders must be divisable by this number |
issue_date | long | millis from epoch pointing to the midnight of the issue day |
underlying_symbol | String | currently always "USD" |
notional_amount | long | the amount of underlying the contact delivers |
expiration_date | long | millis from epoch pointing to the midnight of the expiration day |
settlement_method | SettlementMethod | string, currently always "financial" |
fee | Btc | base fee fraction paid to the exchange by maker and taker from trade value |
taker_to_maker | Btc | taker to maker fee fraction paid from taker to maker from trade value |
initial_margin | Btc | fraction of the contracts value locked as initial margin |
maintenance_margin | Btc | fraction of the contract value locked as maintenance margin |
Inverse Option instrument definition.
Instrument parameters:
Name | Type | Description |
---|---|---|
type | String | always equal to "inverse_option" |
symbol | String | symbol pattern is "O.BTCUSD.DDMMMYY:TXXXX", e.g. "F.BTCUSD.02FEB18:C7500" were T denotes option type and XXXX is the option strike |
instrument_id | int | unique id of the instrument |
tick_size | Btc | tick size of the instrument; price of all orders must be divisable by this number |
issue_date | long | millis from epoch pointing to the midnight of the issue day |
underlying_symbol | String | currently always "USD" |
notional_amount | long | the amount of underlying the contact delivers |
expiration_date | long | millis from epoch pointing to the midnight of the expiration day |
settlement_method | SettlementMethod | string, currently always "financial" |
option_type | OptionType | string, either "call_european" or "put_european" |
strike | Btc | strike of the option in USD |
fee | Btc | base fee fraction paid to the exchange by maker and taker |
taker_to_maker | Btc | taker to maker fee fraction paid from taker to maker |
initial_margin | Btc | fraction locked as initial margin |
maintenance_margin | Btc | fraction locked as maintenance margin |
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "instrument_data" |
data | Map | map from int instrument id to object describing an instrument |
Snapshot of single instrument's order book.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "order_book" |
instrument_id | int | id of the instrument this order book is for |
bids | List | list of lists, where the internal lists are of size 2, the first element is Decimal price and the second element is integer quantity defining a level of an order book (max 100 levels) |
asks | List | list of lists, where the internal lists are of size 2, the first element is Decimal price and the second element is integer quantity defining a level of an order book (max 100 levels) |
Snapshot of single instrument's quotes.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "quotes" |
instrument_id | int | id of the instrument these quotes are for |
last | Decimal | price of last trade |
last_quantity | int | quantity of last trade |
bid | Decimal | price of the best buy level in the order book |
bid_quantity | int | size of the best buy level in the order book |
ask | Decimal | price of the best sell level in the order book |
ask_quantity | int | size of the best sell level in the order book |
volume | int | cumulative volume on this instrument from the beginning of the current trading day (from opening auction) |
open_interest | int | current open interest in this instrument |
tap | Decimal | theoretical auction price or `null` if session state is not auction or tap can't be calculated |
lower_limit | Decimal | lower limit for TAP or `null` if session state is not auction or there's no lower limit on price |
upper_limit | Decimal | upper limit for TAP or `null` if session state is not auction or there's no upper limit on price |
Information about current state of trading session. Emitted when the state changes.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "session_state" |
state | GlobalSessionState | string, new state of the session, one of "no_trading", "opening_auction", "continuous", "auction", "closing_auction" |
start_timestamp | long | millis from epoch, start of the new session state |
scheduled_end_timestamp | long | millis from epoch, scheduled end of the new session state |
Emitted when a trade occurs.
Event fields:
Name | Type | Description |
---|---|---|
type | String | always equal to "trade" |
instrument_id | int | id of the instrument this trade is for |
trade_id | long | unique id of the trade |
timestamp | long | millis from epoch timestamp this trade happened at |
price | Decimal | price of the trade |
quantity | int | quantity of the trade |
liquidity_provider | LiquidityProvider | string, specifies the maker side of a trade, one of "buyer", "seller", "auction", "reference", "settlement" |