How to buy crypto programmatically
Making request
Create an instant order: You can create an instant order by making a request to create an instant order A.P.I. payload includes.
PAYLOAD DATA
- bid: the currency you want to buy from eg: usdt, ngn
- ask: the currency you want to buy.
- type: values are buy or sell.
- total: the amount you are trying to sell.
- unit: amount you are to sell to.
URL PARAMS
- user_id: The User ID. Use 'me' for the main authenticated user, use the user_id if fetching for a Sub-account linked to the authenticated user.
Request:
curl --request POST \
--url https://www.quidax.com/api/v1/users/<user_id>/instant_orders \
--header 'Accept: application/json' \
--header 'Authorization: Bearer <api_secret_key>' \
--header 'Content-Type: application/json' \
--data '
{
"bid": "ngn",
"ask": "btc",
"type": "buy",
"total": "5",
"unit": "ngn"
}
'
import requests
url = "https://www.quidax.com/api/v1/users/<user_id>/instant_orders"
payload = {
"bid": "ngn",
"ask": "btc",
"type": "buy",
"total": "5",
"unit": "ngn"
}
headers = {
"accept": "application/json",
"content-type": "application/json",
"Authorization": "Bearer s3cr3tk3y"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)
const options = {
method: 'POST',
headers: {
accept: 'application/json',
'content-type': 'application/json',
Authorization: 'Bearer s3cr3tk3y'
},
body: JSON.stringify({bid: 'ngn', ask: 'btc', type: 'buy', total: '5', unit: 'ngn'})
};
fetch('https://www.quidax.com/api/v1/users/me/instant_orders', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
Response
{
"status": "success",
"message": "Successful",
"data": {
"id": "lkv4ujpy",
"reference": null,
"market": {
"id": "btcngn",
"base_unit": "BTC",
"quote_unit": "NGN"
},
"side": "buy",
"price": {
"unit": "NGN",
"amount": "35034998.99"
},
"volume": {
"unit": "BTC",
"amount": "0.00000014"
},
"total": {
"unit": "NGN",
"amount": "5.0"
},
"fee": {
"unit": "BTC",
"amount": "0.0000000014"
},
"receive": {
"unit": "BTC",
"amount": "0.0000001386"
},
"status": "pend",
"created_at": "2021-11-15T22:12:08.901Z",
"updated_at": "2021-11-15T22:12:08.901Z",
"user": {
"id": "23azi7bj",
"sn": "QDXXIRPXXKS",
"email": "[email protected]",
"reference": null,
"first_name": "Oye",
"last_name": "Olalekan",
"display_name": "appstate",
"created_at": "2021-04-09T09:48:14.000Z",
"updated_at": "2021-04-09T10:54:32.000Z"
}
}
}
Confirm Instant Order: You need to confirm the instant order after creating it, you need to copy the instant order id from the create instant order response and then add it to the confirm instant order endpoint. URL params include
URL PARAMS
- user_id: the user id belonging to the user.
- instant_order_id: instant order that has been created.
Request:
const options = {
method: 'POST',
headers: {accept: 'application/json', Authorization: 'Bearer s3cr3tk3y'}
};
fetch('https://www.quidax.com/api/v1/users/<user_id>/instant_orders/<instant_order_id>/confirm', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
import requests
url = "https://www.quidax.com/api/v1/users/<user_id>/instant_orders/<instant_order_id>/confirm"
headers = {
"accept": "application/json",
"Authorization": "Bearer s3cr3tk3y"
}
response = requests.post(url, headers=headers)
print(response.text)
curl --request POST \
--url https://www.quidax.com/api/v1/users/me/instant_orders/instant_order_id/confirm \
--header 'Authorization: Bearer s3cr3tk3y' \
--header 'accept: application/json'
Response:
{
"status": "success",
"message": "Successful",
"data": {
"id": "545gzvph",
"reference": null,
"market": {
"id": "btcngn",
"base_unit": "BTC",
"quote_unit": "NGN"
},
"side": "buy",
"price": {
"unit": "NGN",
"amount": "35225190.0"
},
"volume": {
"unit": "BTC",
"amount": "0.00000014"
},
"total": {
"unit": "NGN",
"amount": "4.99"
},
"fee": {
"unit": "BTC",
"amount": "0.0000000014"
},
"receive": {
"unit": "BTC",
"amount": "0.0000001386"
},
"status": "confirm",
"created_at": "2021-11-15T18:15:54.000Z",
"updated_at": "2021-11-15T18:16:05.701Z",
"user": {
"id": "23azi7bj",
"sn": "QDXXIRPXXKS",
"email": "[email protected]",
"reference": null,
"first_name": "Oye",
"last_name": "Olalekan",
"display_name": "appstate",
"created_at": "2021-04-09T09:48:14.000Z",
"updated_at": "2021-04-09T10:54:32.000Z"
}
}
}
Webhooks for final confirmation
After confirming the trade, this action would be processed in the background and the response would be returned through the webhook. you either get a successful webhook or failed webhook event, or you check the instant order status using the endpoint
Updated almost 2 years ago