Exit Trades
How do I exit trades?
Overview
The exit trades feature allows users to create a new trade that will counter a previous trade that is currently settling. This provides a way for users to address buyer's remorse, where they made a trade (e.g. buying Bitcoin) and then want to back out of the transaction, either because the price has moved against them or they want to lock in gains.
To exit a trade, the user references the original trade they want to counter. The system then generates a quote for an exit trade, which effectively creates an opposite transaction to the original trade.
This exit trade is then settled at the same time as the original trade. There may be losses or gains due to price fluctuations in the time between the original trade quote and the exit trade quote.
The key criteria for exit trades:
- The original trade must be "state":"settling".
- The original trade must not have already been included in a settlement batch.
The following steps are required to exit a trade on the Cybrid Platform:
- Create an exit trade quote.
- Create an exit trade.
Create an exit trade quote
For a trade that is "state":"settling" and not yet included in a trade settlement batch, you may create an exit trade quote via the POST /api/quotes
endpoint.
An example POST /api/quotes
request body is below:
{
"product_type": "trading_exit",
"customer_guid": "<insert customer_guid>",
"reference_trade_guid": "<insert reference_trade_guid>"
}
When executed, the following response body will be returned:
{
"created_at": "<created_at timestamp>",
"updated_at": "<updated_at timestamp>",
"guid": "<created quote_guid>",
"product_type": "trading_exit",
"customer_guid": "<inserted customer_guid>",
"symbol": "<associated symbol>",
"side": "<associated side>",
"receive_amount": <associated receive_amount>,
"deliver_amount": <associated deliver_amount>,
"fee": <associated fee>,
"issued_at": "<issued_at timestamp>",
"expires_at": "<expires_at timestamp>"
}
Create a trade
Use the the above quote GUID in the POST /api/trades
request.
An example POST /api/trades
request body is below:
{
"trade_type": "exit",
"quote_guid": "2557a7cdc0da3c535159ad64ba1397b0"
}
When executed, the following response body will be returned:
{
"created_at": "<created_at timestamp>",
"updated_at": "<updated_at timestamp>",
"guid": "<created trade_guid>",
"trade_type": "exit",
"customer_guid": "<associated customer_guid>",
"quote_guid": "<inserted quote_guid>",
"symbol": "<associated symbol>",
"side": "<associated side>",
"state": "storing",
"failure_code": null,
"receive_amount": <associated receive_amount>,
"deliver_amount": <associated deliver_amount>,
"fee": <associated fee>,
"reference_trade_guid": "<inserted reference_trade_guid>",
"labels": null
}
The trade will begin in "state":"storing", and automatically progress to "state":"settling".
Once the trade has progressed to "state":"completed", the trade has been successfully exited.
Using the GET /api/trades/{trade_guid}
endpoint, the following response will be returned:
{
"created_at": "<created_at timestamp>",
"updated_at": "<updated_at timestamp>",
"guid": "<created trade_guid>",
"trade_type": "exit",
"customer_guid": "<associated customer_guid>",
"quote_guid": "<inserted quote_guid>",
"symbol": "<associated symbol>",
"side": "<associated side>",
"state": "completed",
"failure_code": null,
"receive_amount": <associated receive_amount>,
"deliver_amount": <associated deliver_amount>,
"fee": <associated fee>,
"reference_trade_guid": "<inserted reference_trade_guid>",
"labels": null
}
Note: If the original trade (i.e. inserted reference_trade_guid) has already been included in a trade settlement batch, the trade will progress to "state":"failed" with "failure_code":"invalid_reference_trade".
Updated 3 months ago