Introduction
Why?
Orderbook uses client-side cryptography to preserve the highest level of security. And there is no client-side when using API. Therefore was created special service that would be run locally by an API implementator to preserve the same level of security along with ease of use.
Pre-conditions
Before using the service make sure you have already registered an account at Orderbook.io and passed all required verifications. This version of API Service does not yet cover operations like registration, verification, deposit, and withdrawal.
Please refer to https://help.orderbook.io/ should you have any questions. Or you can contact our support at support@orderbook.io.
Setup
Download the service repository https://github.com/Orderbookio/orderbook-api-service
Install latest LTS Node.js from https://nodejs.org/en/download/
To check that you have installed Node.js correctly, open terminal and execute node -v
.
As a result, you should see Node.js latest version, like 8.11.X, it means everything is okay.
Then go to the project root directory and install dependencies by executing npm install
Configuration
In the properties.json file you have to define the following properties:
- orderbookUrl - by default http://localhost:3000, for production: https://api.orderbook.io
- isAuthEnabled - true/false.
false
- Disable authentication. Use this option if you are using only one account for this service. There will be no authentication for your account. If you have more than one account, the first one from the config array (users) would be used. Use this option only locally with closed TCP ports.true
- Enable basic authentication for the API service. Requires adding authPassword for each user in properties.json. - users - the array of orderbook users, each user
should have email, OBPassword, authPassword (if isAuthEnabled is true),
email
is an email you used for registration at Orderbook.OBPassword
is your Orderbook password.authPassword
any password for basic authentication.
an example of USERS :
"users": [
{
"email":"test@mail.com",
"OBPassword":"123456",
"authPassword":"11111111"
},
{
"email":"test1@mail.com",
"OBPassword":"123456",
"authPassword":"11111111"
}
]
Starting server
To start server execute:
npm run prod
To see swagger documentation open http://localhost:5000/documentation
markets
GET
curl -X GET --header 'Accept: application/json' 'http://localhost:5000/v1/markets'
(async function () {
const response = await axios.get(`${SERVICE_URL}/v1/markets`, {
auth: {
username: email,
password: authPassword
}
});
console.log('markets: ', JSON.stringify(response.data, null, 2));
}());
Summary: Get available market names
Description: Returns an array of market names, for example [
"OBTC-ETH",
"OUSD-ETH"
]
HTTP Request
GET /v1/markets
balances
GET
curl -X GET -u email:authPassword --header 'Accept: application/json' 'http://localhost:5000/v1/balances'
(async function () {
const response = await axios.get(`${SERVICE_URL}/v1/balances`, {
auth: {
username: email,
password: authPassword
}
});
console.log('balances: ', JSON.stringify(response.data, null, 2));
}());
Summary: Get user balances
Description: Get user balance by all the assets
HTTP Request
GET /v1/balances
orderbook/{market}
GET
curl -X GET --header 'Accept: application/json' 'http://localhost:5000/v1/orderbook/{market}'
(async function () {
const response = await axios.get(`${SERVICE_URL}/v1/orderbook/OBTC-ETH`, {
auth: {
username: email,
password: authPassword
}
});
console.log('open orders: ', JSON.stringify(response.data, null, 2));
}());
Summary: Get open orders by market name
Description: Returns buy and sell orders for specified market, example {
"buy": [],
"sell": [
{
"price": "0.5",
"amount": "3",
}
]
}
HTTP Request
GET /v1/orderbook/{market}
orders/{market}
GET
Possible order statuses:
- PENDING - not mined
- CREATED - created without matching
- FILLED - partially filled
- COMPLETED - fully filled
- CANCELED - canceled by user
- PENDING_CANCEL - not mined order cancel
- FAILED - transaction error
curl -X GET -u email:authPassword --header 'Accept: application/json' 'http://localhost:5000/v1/orders/{market}'
(async function () {
const response = await axios.get(`${SERVICE_URL}/v1/orders/OBTC-ETH`, {
auth: {
username: email,
password: authPassword
}
});
console.log('user orders: ', JSON.stringify(response.data, null, 2));
}());
Summary: Get user open orders by market name
Description: Returns user buy and sell orders for specified market, example {
"buy": [],
"sell": [
{
"id": "10",
"status": "FILLED",
"type": "SELL",
"price": "0.5",
"amount": "2",
"openAmount": "3",
"filled": "1",
"lastFilledAmount": "1",
"lastFilledPrice": "0.5",
"createdAt": "2018-07-20T11:39:44.000Z",
"updatedAt": "2018-07-20T11:40:11.000Z"
}
]
}
HTTP Request
GET /v1/orders/{market}
orders
POST
curl -X POST -u email:authPassword --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"type":"sell", "amount":"1", "price":"100", "market":"OBTC-ETH"}' 'http://localhost:5000/v1/orders'
(async function () {
const response = await axios.post(`${SERVICE_URL}/v1/orders`, {
type: 'sell',
amount: '1',
price: '30',
market: 'OBTC-ETH'
}, {
auth: {
username: email,
password: authPassword
}
});
console.log('order created: ', JSON.stringify(response.data, null, 2));
}());
Summary: Create order
Description: Returns hash of created order
HTTP Request
POST /v1/orders
Parameters
Name | Located in | Description | Required | Type |
---|---|---|---|---|
type | body | 'buy' or 'sell' | Yes | String |
amount | body | Yes | String | |
price | body | Yes | String | |
market | body | market name | Yes | String |
DELETE
curl -X DELETE -u email:authPassword --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"orderId":"1", "market":"OBTC-ETH"}' 'http://localhost:5000/v1/orders'
(async function () {
const response = await axios.delete(`${SERVICE_URL}/v1/orders`, {
orderId: '2',
market: 'OBTC-ETH'
}, {
auth: {
username: email,
password: authPassword
}
});
console.log('order deleted: ', JSON.stringify(response.data, null, 2));
}());
Summary: Delete user order by orderId where orderId you can get from user open orders endpoint: '/orders/${market}'
Description: Returns hash of deleted order
HTTP Request
DELETE /v1/orders
Parameters
Name | Located in | Description | Required | Type |
---|---|---|---|---|
orderId | body | 'orderId' you can get from '/orders/{market}' | Yes | String |
market | body | market name | Yes | String |
orders/{market}/status/{orderHash}
GET
Possible order statuses:
- PENDING - not mined
- CREATED - created without matching
- FILLED - partially filled
- COMPLETED - fully filled
- CANCELED - canceled by user
- PENDING_CANCEL - not mined order cancel
- FAILED - transaction error
curl -X GET -u email:authPassword --header 'Accept: application/json' 'http://localhost:5000/v1/orders/{market}/status/{orderHash}'
(async function () {
const response = await axios.get(`${SERVICE_URL}/v1/orders/OBTC-ETH/status/0xc00000000774b9e1f4c13c7182c7f0ebfbff342a9a582c614cd60f0946384909`, {
auth: {
username: email,
password: authPassword
}
});
console.log('user orders: ', JSON.stringify(response.data, null, 2));
}());
Summary: Get user order status by hash
Description: Returns order status, example {
"orderHash": "0xcf297e3c0369320ee7ea3da049ac4c2027384c79403659486f352a318e4f5699",
"orderId": 198,
"status": "COMPLETED",
"type": "SELL",
"amount": "0",
"filled": "1",
"price": "1.1",
"lastFilledAmount": "1",
"lastFilledPrice": "1.1",
"createdAt": "2018-07-20T11:18:17.000Z",
"updatedAt": "2018-07-20T11:18:40.000Z",
"openAmount": "1"
}
HTTP Request
GET /v1/orders/{market}/status/{orderHash}
trades/{market}
GET
curl -X GET --header 'Accept: application/json' 'http://localhost:5000/v1/trades/{market}'
(async function () {
const response = await axios.get(`${SERVICE_URL}/v1/trades/OBTC-ETH`, {
auth: {
username: email,
password: authPassword
}
});
console.log('trading history: ', JSON.stringify(response.data, null, 2));
}());
Summary: Get trades by market name
Description: Returns trades array by market name
HTTP Request
GET /v1/trades/{market}
License
See the LICENSE file for details