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


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

For operations with orders and obtaining data on the history and balance of the user, you will need to pass authorization by token, as well as make an electronic signature of the request.

Get the API key on settings page and copy both tokens (API token and Secret Key). Signature is HMAC SHA256 hash of body or GET-params of request. To create a signature, use the secretKey of your API key. The API token and signature must be passed in each request in the headers as follows:

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

Below is an example of creating a signature of request in Linux terminal.

If you do a POST, PUT, or other type of request that has a body, the hashed string is the request body as a JSON object, for example:

{"pairName":"btc_usd","amount":1,"price":3,"directionType":"buy","tradeType":"limit"}
In the case of a GET request, the hash string will be a string of GET parameters (part of the URL after the?), For example:
pairName=btc_usd&amount=1&price=3&directionType=buy&tradeType=limit
You also need the Secret Key that you received when creating the token, for example:
5yoGxzQAr2QR0qnF0j3_ZBKmzY-5CoREfsDIcXV6znhHzLW2TOJqmVG7I7r9MWiQ
In the terminal you need to execute the following command:
echo -n '{"pairName":"btc_usd","amount":1,"price":3,"directionType":"buy","tradeType":"limit"}' | openssl dgst -sha256 -hmac "5yoGxzQAr2QR0qnF0j3_ZBKmzY-5CoREfsDIcXV6znhHzLW2TOJqmVG7I7r9MWiQ"
The command output will be as follows
(stdin)= 33d04b93e24c18b3d2767f50ee3fd913940e834c658ee9509481a5851a2560f5
String 33d04b93e24c18b3d2767f50ee3fd913940e834c658ee9509481a5851a2560f5 is HMAC SHA256 signature of request, add it to the X-Signature header of your request


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
    }
}