Crypto Buy/Sell
Overview
The general workflow for crypto trades will look like the following:
- Pull the market price for the crypto your end user is looking to buy/sell from our API.
- Give the end user the ability to confirm a trade after looking at the market price.
- Call the Fortress API to initiate a
trade
- Monitor the webhooks sent for a change in the
status
of a trade. - Once completed, update your front end with the new balance for the end user.
Testnet Tokens
When testing trades in sandbox, please keep amounts low (greater than $15 but less than $30) as testnet tokens are in limited supply. Once finished testing, please "sell" the tokens so we can maintain a steady supply for all integrators in sandbox.
Lets review each step a bit more.
1. Pull the market price
GET /api/trust/v1/crypto-currency/crypto-currency-price/{network}/{currency}
//Sample Response
{
"price": {
"buy": 21489.79,
"sell": 21457.19
}
}
_Note: The API can return zero values for buy or sell market prices. Zero dollar value trades ($0.00) will not be executed.
2. Allow the end user to confirm that they want the trade after presenting them the market price.
3. Initiate a trade
using the API
POST /api/trust/v1/trades
//Sample Request
{
"accountId": "A3CA08AB-3058-4C3C-81E7-51DA24B171FF",
"type": "market", //only "market" is available at this time
"from": {
"asset": "usd",
"amount": 100
},
"to": {
"asset": "eth",
"network": "mainnet"
},
"comment": "Any Comment Here"
}
OR
POST /api/trust/v1/trades
// Sample Request
{
"accountId": "A3CA08AB-3058-4C3C-81E7-51DA24B171FF",
"type": "market", //only "market" is availbable at this time
"from": {
"asset": "eth",
"network": "mainnet"
"amount": 100
},
"to": {
"asset": "usd"
},
"comment": "Any Comment Here"
}
All in one
The
trades
endpoint facilitates both buys and sells by designating thefrom
andto
fields.
4. Monitor webhooks
An integrator will receive one webhook when the buy/sell crypto transaction is moved to the Processing
status and another webhook when the settlement process is completed. Here are a list of the status's available for the trades
endpoint:
-
Pending (the buy/sell crypto request is created)
-
InProgress (the buy/sell crypto request is in progress and has executed at a particular price, pending incoming crypto/fiat is displayed in an account balance)
-
Completed (settlement process is completed)
-
Aborted (processing of the buy/sell crypto request is failed)
5. Once a trade is completed, update your front end with the new balance
GET /custodial-accounts/{custodialAccountId}/balances
//Sample Response
{
"data": [
{
"assetType": "cryptoCurrency",
"assetFiatType": "eth",
"network": "mainnet",
"disbursable": .001,
"locked": 0,
"pending": 0,
"total": .001
}
]
}
Crypto Trading Settlement Times
Trades are executed almost immediately, but settlement for those trades take up to one business day. Contact your account rep if you have specific settlement time needs.
Trading Pending Balances
After an order is executed, but awaiting settlement, the custodial account's balance will update with a value update in the pendingFromTrade
field (as well as the pending
field). If the end user decides to, they can initiate a trade in the opposite direction, and receive the assets/fiat they requested without needing to wait for the settlement to happen. If the order in the opposite direction is a subset of the initial trade, then the asset/fiat being traded will settle, and the remaining assets/fiat from the initial transaction will lower in amount for what needs to be settled.
GET /custodial-accounts/balances
{
"data": [
{
"assetType": "fiatCurrency",
"assetFiatType": "usd",
"disbursable": 525.000000000000000000,
"locked": 0.000000000000000000,
"pending": 0.000000000000000000,
"total": 525.000000000000000000,
"subBalances": {
"pendingFromTrade": 0.000000000000000000,
"lockedPendingFromTrade": 0.000000000000000000
}
},
{
"assetType": "cryptoCurrency",
"assetFiatType": "btc",
"network": "bitcoinTestnet",
"disbursable": 0.000000000000000000,
"locked": 0.000000000000000000,
"pending": 0.001052660000000000,
"total": 0.000000000000000000,
"subBalances": {
"pendingFromTrade": 0.001052660000000000,
"lockedPendingFromTrade": 0.000000000000000000
}
}
]
}
Updated about 1 year ago