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


Authorization and electronic signature

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": 5097.04,
      "minValue": 5035.03,
      "maxValue": 5035.03,
      "closeValue": 5035.03,
      "closeBidValue": 5035.03,
      "closeAskValue": 5097.04,
      "volume": 29684.20566111,
      "base": {
        "currency": "btc",
        "precision": 6,
        "minValue": 0.001112
      },
      "quote": {
        "currency": "usd",
        "precision": 2,
        "minValue": 503.5,
        "maxValue": 9566.55
      },
      "commissions": {
        "vip": 0.05,
        "base": 0.09
      },
      "highestBid": 4914.65,
      "lowestAsk": 4022.61
    }
]

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
            "base": {
                "currency": "btc",    // Base currency code
                "precision": 6,       // Precision for base currency
                "minValue": 0.001112  // Minimal amount
            },
            "quote": {
                "currency": "usd",    // Quote currency code
                "precision": 2,       // Precision for quote currency
                "minValue": 503.5,    // Minimal price
                "maxValue": 9566.55   // Maximum price
            },
            "commissions": {
                "base": 0.09,         // Standard commission in percent
                "vip": 0.05           // Commission for "vip" plan in percent
            },
            "highestBid": 4914.65,    // Highest price in orders for buy
            "lowestAsk": 4022.61      // Lowest price in orders for sell
        }
    ],
    "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}?limit=500

Get data for chart
Period - one of value: 1m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 12h, 1d, 1w
Limit - values between 10 and 10 000, default - 500

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/user-balances

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

Get user balances for specify or all currencies

Response 200:

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

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

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

Get user orders with pagination for specify or all pairs
Cancelled - set 1 for also show cancelled orders
Completed - set 1 for also show cancelled and completed (closed) orders

Request:

?page=1&pageSize=50&cancelled=0&completed=0

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-orders/{orderId}

Get user order info by id

Response 200:

{
  "id": 26465635,
  "pairName": "pltc_eth",
  "directionType": "sell",
  "tradeType": "market",
  "amount": "500.00000000",
  "price": "0.00000000",
  "amountUsed": "500.00000000",
  "isCancelled": false,
  "createTime": "2019-03-12 09:18:07",
  "updateTime": "2019-03-12 09:18:07",
  "userHistory": [
    {
      "id": 19578548,
      "pairName": "pltc_eth",
      "tradeType": "market",
      "directionType": "sell",
      "price": "0.00129900",
      "amount": "500.00000000",
      "tradeTime": "2019-03-12 09:18:07",
      "orderId": 26465635
    }
  ]
}

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

GET /api/1.0/trade/pairs/{pairName}/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
            "orderId": 530,                         // 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
            "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
    }
}