AlienCloud API

Все данные передаются в JSON формате с кодировкой UTF8. В заголовках запроса указывайте 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": [
            "На балансе недостаточно средств"
        ]
    }
}

POST /api/1.0/trade/cancel-order

Cancel order

Request:

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

Response 200:

[]

Response 400:

{
    "errors": {
        "orderId": [
            "Заявка уже отменена"
        ]
    }
}

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 - только для чтения. Список каналов, на которые необходимо подписаться, указывается GET параметром `streams` в запросе. Чтобы подписаться сразу на несколько каналов, перечислите их через запятую:

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