AlienCloud API

All data is send in JSON format with UTF8 encoding. Specify in the request headers Content-Type: application/json

REST API: https://aliencloud.xyz/api/1.0
Stream API: https://aliencloud.xyz/ws


Авторизация и электронная подпись

Для операций с ордерами и получения данных по истории и балансу пользователя вам потребуется пройти авторизацию по токену, а также сделать электронную подпись запроса.

Получите API ключ в личном кабинете и скопируйте оба токена (API token и Secret Key). Подписью является HMAC SHA256 хэш тела или GET-параметров запроса. Для создания подписи используется secretKey вашего API ключа. API токен и подпись необходимо передавать в каждом запросе в заголовках следющим образом:

/* API token */
Authorization: Bearer AqyWUZWlFTdxNkDmv2222MsyFQZoCH00t3fm7p1lSq1111JQNWnbHK262D3333_g
/* HMAC SHA256 signature */
X-Signature: a87224e1fbd875b2bf8ef761a707ee59fdb1939657c565e47f61a3090df6398f

Ниже приведен пример создания подписи запроса в терминале ОС Linux.

Если вы делаете запрос типа POST, PUT или другого типа, который имеет тело, в качестве хэшируемой строки выступает тело запроса в виде JSON-объекта, например:

{"pairName":"btc_usd","amount":1,"price":3,"directionType":"buy","tradeType":"limit"}
В случае GET-запроса хэшируемой строкой будет строка GET-параметров (часть URL после знака ?), например:
pairName=btc_usd&amount=1&price=3&directionType=buy&tradeType=limit
Также вам потребуется Secret Key, который вы получили при создании токена, например:
5yoGxzQAr2QR0qnF0j3_ZBKmzY-5CoREfsDIcXV6znhHzLW2TOJqmVG7I7r9MWiQ
В терминале вам необходимо выполнить команду следующего вида:
echo -n '{"pairName":"btc_usd","amount":1,"price":3,"directionType":"buy","tradeType":"limit"}' | openssl dgst -sha256 -hmac "5yoGxzQAr2QR0qnF0j3_ZBKmzY-5CoREfsDIcXV6znhHzLW2TOJqmVG7I7r9MWiQ"
Вывод команды будет следующим
(stdin)= 33d04b93e24c18b3d2767f50ee3fd913940e834c658ee9509481a5851a2560f5
Полученное значение 33d04b93e24c18b3d2767f50ee3fd913940e834c658ee9509481a5851a2560f5 является HMAC SHA256 подписью запроса, добавьте его в заголовок X-Signature вашего запроса.


Trade: REST API

POST /api/1.0/trade/create-order

Create order

Request:

{
    "pairName": "btc_usd",      // Pair name
    "tradeType": "limit"        // Trade type: "limit" or "market"
    "directionType": "buy",     // Direction: "buy" or "sell"
    "price": 6541.21,           // Order price, required for limit
    "amount": 1.002,            // Order amount
}

Response 200:

{
    "id": 820,                              // Order unique ID
    "pairName": "btc_usd",                  // Pair name
    "tradeType": "limit",                   // Trade type: "limit" or "market"
    "directionType": "sell",                // Direction: "buy" or "sell"
    "price": 6609.37,                       // Order price
    "amount": 0.000002,                     // Order amount
    "amountUsed": 0,                        // Used amount. Order will be fully executed when amount = amountUsed.
    "isCancelled": false,                   // True, when cancelled by user
    "createTime": "2018-01-01 05:38:51",    // Order create time
    "updateTime": "2018-01-01 05:38:51",    // Order last update time
}

Response 400:

{
    "errors": {
        "amount": [
            "Not enough funds on balance"
        ]
    }
}

POST /api/1.0/trade/cancel-order

Cancel order

Request:

{
    "orderId": 820",  // Order ID
}

Response 200:

[]

Response 400:

{
    "errors": {
        "orderId": [
            "Order already canceled"
        ]
    }
}

GET /api/1.0/trade/pairs

Get exchanges for all pairs

Response 200:

[
    {
        "pairName": "btc_usd",
         "openValue": 6421.42,
         "minValue": 6421.42,
         "maxValue": 6624.85,
         "closeValue": 6609.37,
         "closeBidValue": 6609.37,
         "closeAskValue": 6609.88,
         "volume": 546.32
    }
]

GET /api/1.0/trade/pairs/{pairName}

Get initial data for pair page:
   - exchanges for all pairs
   - all aggregated orders
   - last 200 history items
   - last 20user orders for all pairs (return null for non-authenticated request)
   - last 20user history for all pairs (return null for non-authenticated request)

Response 200:

{
    "exchanges": [
        {
            "pairName": "btc_usd",  // Pair name
            "openValue": 6421.42,   // Open value 24h
            "minValue": 6421.42,    // Min value 24h
            "maxValue": 6624.85,    // Max value 24h
            "closeValue": 6609.37,  // Close value 24h (current exchange)
            "volume": 546.32        // Volume 24h
        }
    ],
    "orders": {
        "buy": [
            {
                "price": 6543.61,   // Order price
                "amount": 0.007917  // Aggregate order amounts for this price
            }
        ],
        "sell": [
            {
                "price": 6624.85,   // Order price
                "amount": 0.007147  // Aggregate order amounts for this price
            }
        ]
    },
    "history": [
        {
            "directionType": "sell"                 // Direction type: "buy" or "sell"
            "tradeType": "limit",                   // Trade type: "limit" or "market"
            "price": 6421.42,                       // Order price
            "amount": 0.000004,                     // Order amount
            "tradeTime": 1541221598,                // Trade execute timestamp in seconds
            "eventTimeMicro": "1541221598929761",   // Event time in microseconds
        }
    ],
    "userOrders": [
        {
            "id": 820,                              // Order unique ID
            "pairName": "btc_usd",                  // Pair name
            "directionType": "sell",                // Direction: "buy" or "sell"
            "tradeType": "limit",                   // Trade type: "limit" or "market"
            "price": 6609.37,                       // Order price
            "amount": 0.000006,                     // Order amount
            "amountUsed": 0.000002,                 // Used amount. Order will be fully executed when amount = amountUsed.
            "isCancelled": false,                   // True, when cancelled by user
            "createTime": "2018-01-10 05:38:51"     // Order create time
        }
    ],
    "userHistory": [
        {
            "id": 820,                              // Operation (trade) unique ID
            "pairName": "btc_usd",                  // Pair name
            "tradeType": "limit",                   // Trade type: "limit" or "market"
            "directionType": "sell",                // Direction: "buy" or "sell"
            "price": 6609.37,                       // Order price
            "amount": 0.000006,                     // Order amount
            "tradeTime": "2018-01-10 05:38:51"      // Trade execute time
        }
    ]
}

GET /api/1.0/trade/pairs/{pairName}/chart/{period}

Get data for chart
Period - one of value: 1m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 12h, 1d, 1w

Response 200:

[
    [
        1541221500000,  // Timestamp in ms
        6421.42,        // Open value
        6421.42,        // Min value
        6624.85,        // Max value
        6609.37,        // Close value
        0.41097088      // Volume
    ]
]

GET /api/1.0/trade/pairs/{pairName}/orders

Get aggregate orders for pair

Response 200:

{
    "buy": [
        {
            "price": 6543.61,   // Order price
            "amount": 0.007917  // Aggregate order amounts for this price
        }
    ],
    "sell": [
        {
            "price": 6624.85,   // Order price
            "amount": 0.007147  // Aggregate order amounts for this price
        }
    ]
}

GET /api/1.0/trade/pairs/{pairName}/history

Get history for pair

Response 200:

[
    {
        "tradeType": "limit",                   // Trade type: "limit" or "market"
        "directionType": "sell"                 // Direction type: "buy" or "sell"
        "price": 6421.42,                       // Order price
        "amount": 0.000004,                     // Order amount
        "tradeTime": 1541221598,                // Trade execute timestamp in seconds
        "eventTimeMicro": "1541221598929761",   // Event time in microseconds
    }
]

GET /api/1.0/trade/pairs/{pairName}/user-balances

Get user balances for pair

Response 200:

[
    {
        "currency": "btc",          // Currency
        "balance": "0.00002525"     // Balance
    },
    {
        "currency": "usd",          // Currency
        "balance": "0.00000000"     // Balance
    }
]

GET /api/1.0/trade/pairs/{pairName}/user-orders

Get user orders with pagination for all pairs

Request:

?page=1&pageSize=50

Response 200:

{
    "total": 410,
    "items": [
        {
            "id": 820,                              // Order unique ID
            "pairName": "btc_usd",                  // Pair name
            "tradeType": "limit",                   // Trade type: "limit" or "market"
            "directionType": "sell",                // Direction: "buy" or "sell"
            "price": 6609.37,                       // Order price
            "amount": 0.000006,                     // Order amount
            "amountUsed": 0.000002,                 // Used amount. Order will be fully executed when amount = amountUsed.
            "isCancelled": false,                   // True, when cancelled by user
            "createTime": "2018-01-10 05:38:51"     // Order create time
        }
    ]
}

GET /api/1.0/trade/pairs/user-history

Get user history with pagination for all pairs

Request:

?page=1&pageSize=50

Response 200:

{
    "total": 142,
    "items": [
        {
            "id": 820,                              // Operation (trade) unique ID
            "pairName": "btc_usd",                  // Pair name
            "tradeType": "limit",                   // Trade type: "limit" or "market"
            "directionType": "sell",                // Direction: "buy" or "sell"
            "price": 6609.37,                       // Order price
            "amount": 0.000006,                     // Order amount
            "tradeTime": "2018-01-10 05:38:51"      // Trade execute time
        }
    ]
}

Trade: Stream API (WebSocket)

Stream API is read only. The list of channels for the subscription is indicated by the GET `streams` parameter in the request. To subscribe to several channels at once, list them separated by commas:

https://aliencloud.xyz/ws?streams=exchanges,orders:btc_usd,history:btc_usd,user_orders:5555bde1-1111-2222-3333-9ff6666250b1

exchanges

{
    "stream": "exchanges",
    "data": [
        {
            "pairName": "btc_usd",                  // Pair name
            "openValue": 6421.42,                   // Open value 24h
            "minValue": 6421.42,                    // Min value 24h
            "maxValue": 6624.85,                    // Max value 24h
            "closeValue": 6609.37,                  // Close value 24h (current exchange)
            "volume": 546.32,                       // Volume 24h
            "eventTimeMicro": "1541221598929761",   // Event time in microseconds
        }
    ]
}

orders:{pairName}

{
    "stream": "orders:btc_usd",
    "data": {
        "buy": [
            {
                "price": 6543.61,                       // Order price
                "amount": 0.007917,                     // Aggregate order amounts for this price
                "eventTimeMicro": "1541221598929761",   // Event time in microseconds
            }
        ],
        "sell": [
            {
                "price": 6624.85,                       // Order price
                "amount": 0.007147,                     // Aggregate order amounts for this price
                "eventTimeMicro": "1541221598929761",   // Event time in microseconds
            }
        ]
    }
}

history:{pairName}

{
    "stream": "history:btc_usd",
    "data": [
        {
            "directionType": "sell"                 // Direction type: "buy" or "sell"
            "tradeType": "limit",                   // Trade type: "limit" or "market"
            "price": 6421.42,                       // Order price
            "amount": 0.000004,                     // Order amount
            "tradeTime": 1541221598,                // Trade execute timestamp in seconds
            "eventTimeMicro": "1541221598929761"    // Event time in microseconds
        }
    ]
}

user_orders:{userUid}

{
    "stream": "user_orders:5555bde1-1111-2222-3333-9ff6666250b1",
    "data": {
        "id": 820,                              // Order unique ID
        "pairName": "btc_usd",                  // Pair name
        "tradeType": "limit",                   // Trade type: "limit" or "market"
        "directionType": "sell",                // Direction: "buy" or "sell"
        "price": 6609.37,                       // Order price
        "amount": 0.000006,                     // Order amount
        "amountUsed": 0.000002,                 // Used amount. Order will be fully executed when amount = amountUsed.
        "isCancelled": false,                   // True, when cancelled by user
        "createTime": "2018-01-10 05:38:51"     // Order create time
    }
}

user_history:{userUid}

{
    "stream": "user_history:5555bde1-1111-2222-3333-9ff6666250b1",
    "data": {
        "id": 820,                              // Operation (trade) unique ID
        "pairName": "btc_usd",                  // Pair name
        "tradeType": "limit",                   // Trade type: "limit" or "market"
        "directionType": "sell",                // Direction: "buy" or "sell"
        "price": 6609.37,                       // Order price
        "amount": 0.000006,                     // Order amount
        "tradeTime": "2018-01-10 05:38:51"      // Trade execute time
    }
}