Getting Started
Overview
Welcome to BlinkTrade API documentation!
BlinkTrade provides a simple and robust WebSocket API to integrate our platform, we strongly recommend you to use it over the REST API.
BlinkTrade SDK
We provide a simple WebSocket and REST JavaScript SDK that enables you runs in either Node.js or in a browser. You can easily send and cancel orders, request deposits and withdrawals, and get real time market data through our WebSocket API.
All SDK supports either promises and callbacks.
If a callback is provided as the last argument, it will be called as callback(error, result),
otherwise it will just return the original promise. We also provide event emitters that you can
use to get realtime updates through our WebSocket API.
Install
$ npm install blinktrade
var BlinkTrade = require('blinktrade');
var BlinkTradeRest = BlinkTrade.BlinkTradeRest;
var BlinkTradeWS = BlinkTrade.BlinkTradeWS;
// REST Transport
var blinktrade = new BlinkTradeRest();
// WebSocket Transport
var blinktrade = new BlinkTradeWS();
blinktrade.heartbeat().then(function(heartbeat) {
console.log(heartbeat.Latency);
});
Check our JavaScript SDK documentation
BlinkTrade Endpoints
There are two working environments: prod for production purporses and testnet for testing purporses.
Some features are accessed publicly and others require an API Key based authentication. All data messages and responses are in JSON format.
Public Rest
testnetbase URL endpoint:https://api_testnet.blinktrade.com/api/v1prodbase URL endpoint:https://api.blinktrade.com/api/v1
Trade (Rest and WebSocket)
Rest
testnetbase URL endpoint:https://api_testnet.blinktrade.com/tapi/v1/messageprodbase URL endpoint:https://api.blinktrade.com/tapi/v1/message
WebSocket
testnetURL endpoint:wss://api_testnet.blinktrade.com/trade/prodURL endpoint:wss://ws.blinktrade.com/trade/
BitCambio Endpoints
- bitcambio
prodrest endpoint:https://bitcambio_api.blinktrade.com/tapi/v1/message - bitcambio
prodwebsocket endpoint:wss://bitcambio_api.blinktrade.com/trade/
| Endpoint | Server | Browser |
|---|---|---|
| Public Rest | Yes | Yes |
| Trade | Yes | No (Origin Policy) |
| WebSocket | Yes | No (Origin Policy) |
Create API Key
- Go to some exchange powered by BlinkTrade or
https://testnet.blinktrade.comfortestnetenvironment - Signup
- Go to API page
- Click “New API Key”
- Enter a label and select the permissions for that API Key
- Get the API Key and API Secret. The API Secret will only be shown once. (The API Password is only used for the WebSocket API.)
Brokers
A broker ID is assigned for each exchange powered by BlinkTrade:
<BROKER_ID> |
Description |
|---|---|
| 3 | VBTC |
| 4̶ | F̶o̶x̶B̶i̶t̶ |
| 5 | Testnet |
| 8 | UrduBit |
| 9 | ChileBit |
| 11 | BitCambio |
Currencies
Currency codes and related brokers:
<CURRENCY> |
Description |
|---|---|
| VND | Vietnamise Dongs (VBTC) |
| BRL | Brazil Reals (BitCambio) |
| PKR | Pakistani Ruppe (UrduBit) |
| CLP | Chilean Pesos (ChileBit.NET) |
Symbols
Currency pair symbols and related brokers:
<SYMBOL> |
Description |
|---|---|
| BTCVND | BTC Pair - Vietnamise Dongs (VBTC) |
| BTCBRL | BTC Pair - Brazil Reals (BitCambio) |
| BTCPKR | BTC Pair - Pakistani Ruppe (UrduBit) |
| BTCCLP | BTC Pair - Chilean Pesos (ChileBit.NET) |
Public Rest API
Overview
var BlinkTradeRest = require("blinktrade").BlinkTradeRest;
var BlinkTrade = new BlinkTradeRest({
prod: false,
currency: "BRL",
});
The Public API can be accessed under /api/v1/<CURRENCY>, e.g, production is https://api.blinktrade.com/api/v1/<CURRENCY>
(or https://bitcambio_api.blinktrade.com/api/v1/<CURRENCY> if you are using bitcambio)
An HTTP GET request method should be used to fetch data.
Ticker
Ticker is a summary information about the current status of an exchange.
HTTP Request
GET /api/v1/<CURRENCY>/ticker?crypto_currency=BTC
BlinkTrade.ticker().then(function(ticker) {
console.log(ticker);
});
$ curl "https://api.blinktrade.com/api/v1/BRL/ticker"
$ curl "https://bitcambio_api.blinktrade.com/api/v1/BRL/ticker"
Parameters
| Name | Description |
|---|---|
| crypto_currency | Crypto currency to be used. Optional; defaults to BTC |
EXAMPLE RESPONSE
{
"pair": "BTCBRL",
"last": 2280.0,
"high": 2306.0,
"low": 2205.0,
"vol": 113.17267938,
"vol_brl": 255658.20705113,
"buy": 2263.0,
"sell": 2279.77
}
Response
| Name | Type | Description |
|---|---|---|
| pair | string | <SYMBOL> |
| last | number | Value of the last price in the last 24 hours |
| high | number | Price of the highest price in the last 24 hours |
| low | number | Price of the lowest price in the last 24 hours |
| vol | number | Trading volume in the last 24 hours |
| vol_<CURRENCY> | number | Trading volume in the last 24 hours in <CURRENCY> (lowercase) |
| buy | number | Price of the most recent buy order |
| sell | number | Price of the most recent sell order |
Orderbook
Order book is a list of orders that shows the interest of buyers (bids) and sellers (asks).
NOTE: There’s limit of 100 orders per request and you can’t paginate, use WebSockets instead.
HTTP Request
GET /api/v1/<CURRENCY>/orderbook?crypto_currency=BTC
BlinkTrade.orderbook().then(function(orderbook) {
console.log(orderbook);
});
$ curl "https://bitcambio_api.blinktrade.com/api/v1/BRL/orderbook"
Parameters
| Name | Description |
|---|---|
| crypto_currency | Crypto currency to be used. Optional; defaults to BTC |
EXAMPLE RESPONSE
{
"pair": "BTCBRL",
"bids": [
[2257.89, 0.20752212, 90852987],
[2257.88, 1.01201126, 90800395],
[2249.98, 0.05052466, 90806289]
],
"asks": [
[2272.14, 2.3648572, 90803493],
[2279.63, 0.08722052, 90840584],
[2279.75, 0.04118941, 90823262]
]
}
Response
| Name | Type | Description |
|---|---|---|
| pair | string | <SYMBOL> |
| bids | array(array) | Array of bids from buyers |
| asks | array(array) | Array of asks from sellers |
For each element of bids or asks array:
| Index Array | Type | Description |
|---|---|---|
| 0 | number | Unit price |
| 1 | number | Amount to buy/sell |
| 2 | number | User ID |
Trades
A list of the last trades executed on an exchange since a chosen date.
HTTP Request
GET /api/v1/<CURRENCY>/trades?since=<TID>&limit=<NUMBER>
BlinkTrade.trades({ limit: 100, since: 2270000 }).then(function(trades) {
console.log(trades);
});
$ curl "https://api.blinktrade.com/api/v1/BRL/trades?since=1467990302&limit=2"
$ curl "https://bitcambio_api.blinktrade.com/api/v1/BRL/trades?since=1467990302&limit=2"
Parameters
| Name | Description |
|---|---|
| since | tid (TradeID) which executed trades must be fetched from. Optional; defaults to the date of the first executed trade |
| limit | Limit of trades that will be returned. <NUMBER> should be a positive integer. Optional; defaults to 100 trades |
Response
EXAMPLE RESPONSE
[
{
"tid": 404681,
"date": 1467990302,
"price": 2280.89,
"amount": 0.53487892,
"side": "buy"
},
{
"tid": 404682,
"date": 1467990492,
"price": 2261.01,
"amount": 0.0373,
"side": "sell"
}
]
The response is an array of objects where for each object:
| Name | Type | Description |
|---|---|---|
| tid | number | Trade ID |
| date | number | Executed date in Unix Time |
| price | number | Unit price |
| amount | number | Amount bought/sold |
| side | string | “buy” for a buy order or “sell” for a sell order |
Trade API
On our RESTful API, we provide a trade endpoint that you’re allowed to send and cancel orders, request deposits and withdrawals. You need to create an API Key through our platform and set their respective permission that gives you access to it.
The Trade endpoint is internaly a bridge to our WebSocket API, so you can access it both on REST and WebSocket API.
On REST it can be accessed under /tapi/v1/message, e.g, production is https://api.blinktrade.com/tapi/v1/message (or https://bitcambio_api.blinktrade.com/tapi/v1/message if your are using bitcambio),
and API Key is needed in order to authenticate your access.
An HTTP POST request method should be used to send a RESTful HTTP message.
REST HTTP Headers
The following headers must be present in your POST message:
| Header | Description |
|---|---|
| APIKey | Your API Key generated from your exchange or testnet environment |
| Nonce | Must be an integer, always greater than the previous one |
| Signature | The HMAC-SHA256 signature of Nonce using your API Secret as key |
| Content-Type | application/json |
// REST Transport
var BlinkTradeRest = require("blinktrade").BlinkTradeRest;
var blinktrade = new BlinkTradeRest({
prod: false,
key: "YOUR_API_KEY_GENERATED_IN_API_MODULE",
secret: "YOUR_SECRET_KEY_GENERATED_IN_API_MODULE",
currency: "BRL",
});
// WebSocket Transport
var BlinkTradeWS = require("blinktrade").BlinkTradeWS;
var blinktrade = new BlinkTradeWS({ prod: false });
# Message to be sent
message='JSON_MESSAGE_TO_BE_SENT'
# REST Trade API URL
api_url='API_URL_REST_ENDPOINT'
# Set API Key and Secret
api_key='YOUR_API_KEY_GENERATED_IN_API_MODULE'
api_secret='YOUR_SECRET_KEY_GENERATED_IN_API_MODULE'
# Generate a nonce
nonce=`date +%s`
# Sign the nonce with secret using HMAC-SHA256
signature=`echo -n "$nonce" | openssl dgst -sha256 -hex -hmac "$api_secret" | cut -d ' ' -f 2`
# Send a POST message to API URL
curl -X POST "$api_url" \
-H "APIKey:$api_key" \
-H "Nonce:$nonce" \
-H "Signature:$signature" \
-H "Content-Type:application/json" \
-d "$message"
Balance
MESSAGE EXAMPLE
{
"MsgType": "U2",
"BalanceReqID": 1
}
blinktrade.balance().then(function(balance) {
console.log(balance);
});
message='{ "MsgType": "U2", "BalanceReqID": 1 }'
api_url='API_URL_REST_ENDPOINT'
api_key='YOUR_API_KEY_GENERATED_IN_API_MODULE'
api_secret='YOUR_SECRET_KEY_GENERATED_IN_API_MODULE'
nonce=`date +%s`
signature=`echo -n "$nonce" | openssl dgst -sha256 -hex -hmac "$api_secret" | cut -d ' ' -f 2`
curl -X POST "$api_url" \
-H "APIKey:$api_key" \
-H "Nonce:$nonce" \
-H "Signature:$signature" \
-H "Content-Type:application/json" \
-d "$message"
Parameters
| Name | Type | Description/Value |
|---|---|---|
| MsgType | string | “U2” |
| BalanceReqID | number | An ID assigned by you. It can be any number. The response message associated with this request will contain the same ID |
RESPONSE EXAMPLE
{
"MsgType": "U3",
"ClientID": 90800003,
"BalanceReqID": 5178228,
"Available": {
"USD": 177814907002760,
"BTC": 1468038442214
},
"5": {
"BTC_locked": 0,
"USD": 177911657052760,
"BTC": 1468038442214,
"USD_locked": 96750050000
}
}
Response
Returns your balance for each broker.
| Name | Type | Description/Value |
|---|---|---|
| MsgType | string | “U3” UserBalanceResponse message |
| <BROKER_ID> | object | The Broker ID containing your BTC and FIAT balance, e.g.: “5” stands for your balance with the Broker ID number 5 |
| ClientID | number | Your account ID |
| BalanceReqID | number | This should match the BalanceReqID sent on the message “U2” |
| Available | object | Available balance only returned on JavaScript SDK |
Balance model example for BTC and USD:
| Name | Type | Description |
|---|---|---|
| BTC | number | Amount in satoshis of BTC you have available in your account |
| USD | number | Amount in USD (or your FIAT currency) you have available in your account |
| BTC_locked | number | Amount in satoshis of BTC you have locked (open orders, margin positions, etc) |
| USD_locked | number | Amount in USD (or your FIAT currency) you have locked (open orders, margin positions, etc) |
My Orders
Request a list of your open orders.
MESSAGE EXAMPLE
{
"MsgType": "U4",
"OrdersReqID": 930019,
"Page": 0,
"PageSize": 1
}
blinktrade.myOrders().then(function(myOrders) {
console.log(myOrders);
});
message='{ "MsgType": "U4", "OrdersReqID": 930019, "Page": 0, "PageSize": 1 }'
api_url='API_URL_REST_ENDPOINT'
api_key='YOUR_API_KEY_GENERATED_IN_API_MODULE'
api_secret='YOUR_SECRET_KEY_GENERATED_IN_API_MODULE'
nonce=`date +%s`
signature=`echo -n "$nonce" | openssl dgst -sha256 -hex -hmac "$api_secret" | cut -d ' ' -f 2`
curl -X POST "$api_url" \
-H "APIKey:$api_key" \
-H "Nonce:$nonce" \
-H "Signature:$signature" \
-H "Content-Type:application/json" \
-d "$message"
Parameters
| Name | Type | Description/Value |
|---|---|---|
| MsgType | string | “U4” |
| OrdersReqID | number | An ID assigned by you. It can be any number. The response message associated with this request will contain the same ID |
| Page | number | Optional; defaults to 0 |
| PageSize | number | Optional; defaults to 20 |
RESPONSE EXAMPLE
{
"OrdListGrp": [{
"ClOrdID": "8475400",
"OrderID": 1459028830968,
"CumQty": 0,
"OrdStatus": "0",
"LeavesQty": 5000000,
"CxlQty": 0,
"AvgPx": 0,
"Symbol": "BTCUSD",
"Side": "1",
"OrdType": "2",
"OrderQty": 5000000,
"Price": 50001000000,
"OrderDate": "2016-09-07 04:35:30",
"Volume": 0,
"TimeInForce": "1"
}],
"PageSize": 1,
"OrdersReqID": 930019,
"MsgType": "U5",
"Page": 0
}
Response
Returns an array of Orders Model Objects.
| Name | Type | Description/Value |
|---|---|---|
| ClOrdID | string | Client order ID set by you |
| OrderID | number | Order ID set by blinktrade |
| CumQty | number | The executed quantity of this order |
| OrdStatus | string | “0” = New, “1” = Partially filled, “2” = Filled, “4” = Cancelled, “8” = Rejected, “A” = Pending New |
| LeavesQty | number | Quantity open for further execution |
| CxlQty | number | Total quantity canceled for this order |
| AvgPx | number | Calculated average price of all fills on this order |
| Symbol | string | <SYMBOL> |
| Side | string | “1” = Buy, “2” = Sell |
| OrdType | string | “2” = Limited |
| OrderQty | number | Quantity ordered in satoshis |
| Price | number | Price per unit in your local currency |
| OrderDate | string | Order date in UTC |
| Volume | number | Quantity x Price |
| TimeInForce | string | “0” = Day, “1” = Good Till Cancel, “4” = Fill or Kill |
Send Order
MESSAGE EXAMPLE
{
"MsgType": "D",
"ClOrdID": "8426208",
"Symbol": "BTCUSD",
"Side": "1",
"OrdType": "2",
"Price": 55000000000,
"OrderQty": 5000000,
"BrokerID": 5
}
blinktrade.sendOrder({
"side": "1", // Buy
"price": parseInt((550 * 1e8).toFixed(0)),
"amount": parseInt((0.05 * 1e8).toFixed(0)),
"symbol": "BTCUSD",
}).then(function(order) {
console.log(order);
});
message='{ "MsgType": "D", "ClOrdID": "8426208", "Symbol": "BTCUSD", "Side": "1", "OrdType": "2", "Price": 55000000000, "OrderQty": 5000000, "BrokerID": 5 }'
api_url='API_URL_REST_ENDPOINT'
api_key='YOUR_API_KEY_GENERATED_IN_API_MODULE'
api_secret='YOUR_SECRET_KEY_GENERATED_IN_API_MODULE'
nonce=`date +%s`
signature=`echo -n "$nonce" | openssl dgst -sha256 -hex -hmac "$api_secret" | cut -d ' ' -f 2`
curl -X POST "$api_url" \
-H "APIKey:$api_key" \
-H "Nonce:$nonce" \
-H "Signature:$signature" \
-H "Content-Type:application/json" \
-d "$message"
Parameters
| Name | Type | Description/Value |
|---|---|---|
| MsgType | string | “D” |
| ClOrdID | string | Unique identifier for Order as assigned by you |
| Symbol | string | <SYMBOL> |
| Side | string | “1” = Buy, “2” = Sell |
| OrdType | string | “2” = Limited |
| Price | number | Price in satoshis |
| OrderQty | number | Quantity in satoshis |
| BrokerID | number | <BROKER_ID> |
Response
Returns an Execution Report Model Object, if you’re using with REST Transport,
it will response as an array together with the balance response.
RESPONSE EXAMPLE
{
"OrderID": 1459028830972,
"ExecID": 741322,
"ExecType": "0",
"OrdStatus": "0",
"CumQty": 0,
"Symbol": "BTCUSD",
"OrderQty": 5000000,
"LastShares": 0,
"LastPx": 0,
"Price": 55000000000,
"TimeInForce": "1",
"LeavesQty": 5000000,
"MsgType": "8",
"ExecSide": "1",
"OrdType": "2",
"CxlQty": 0,
"Side": "1",
"ClOrdID": "8426208",
"AvgPx": 0
}
Execution Report Response
| field | Type | Description/Value |
|---|---|---|
| MsgType | string | “8” |
| OrderID | number | Unique identifier for Order as assigned by broker |
| ExecID | number | Unique identifier of execution message as assigned by broker |
| ExecType | string | “0” = New, “1” = Partially fill, “2” = Fill, “4” = Cancelled, “8” = Rejected, “A” = Pending New |
| OrdStatus | string | “0” = New, “1” = Partially fill, “2 ”= Fill, “4” = Cancelled, “8” = Rejected, “A” = Pending New |
| LeavesQty | number | Quantity open for further execution |
| Symbol | string | Currency pair being used |
| OrderQty | number | Quantity ordered in satoshis |
| LastShares | number | Quantity of shares bought/sold on this fill |
| LastPx | number | Price of the last fill |
| CxlQty | number | Total quantity canceled for this order |
| TimeInForce | string | “0” = Day, “1” = Good Till Cancel, “4” = Fill or Kill |
| CumQty | number | Total quantity filled |
| ClOrdID | string | Unique identifier for Order as assigned by you |
| OrdType | string | “2” = Limited |
| Side | string | “1” = Buy, “2” = Sell |
| Price | number | Price per unit of quantity in satoshis |
| ExecSide | string | Side of this fill |
| AvgPx | number | Calculated average price of all fills on this order |
| OrdRejReason | string | Rejected reason code if order was rejected based on fix protocol |
Cancel Order
MESSAGE EXAMPLE
{
"MsgType": "F",
"OrderID": 1459028830899,
"ClOrdID": "8426208"
}
blinktrade.cancelOrder({ orderID: order.OrderID, clientId: order.ClOrdID }).then(function(order) {
console.log("Order Cancelled");
});
message='{ "MsgType": "F", "OrderID": 1459028830899, "ClOrdID": 8426208 }'
api_url='API_URL_REST_ENDPOINT'
api_key='YOUR_API_KEY_GENERATED_IN_API_MODULE'
api_secret='YOUR_SECRET_KEY_GENERATED_IN_API_MODULE'
nonce=`date +%s`
signature=`echo -n "$nonce" | openssl dgst -sha256 -hex -hmac "$api_secret" | cut -d ' ' -f 2`
curl -X POST "$api_url" \
-H "APIKey:$api_key" \
-H "Nonce:$nonce" \
-H "Signature:$signature" \
-H "Content-Type:application/json" \
-d "$message"
Parameters
| Name | Type | Description/Value |
|---|---|---|
| MsgType | string | “F” Order Cancel Request message. Check for a full doc here: http://www.onixs.biz/fix-dictionary/4.4/msgType_F_70.html. |
| ClOrdID | string | ID for an Order as assigned by you. |
Response
The response will be the same as the sendOrder with ExecType: “4”
Deposits
Request Deposit List
MESSAGE EXAMPLE
{
"MsgType": "U30",
"DepositListReqID": 123,
"Page": 0,
"PageSize": 1,
"StatusList": ["1", "2", "4", "8"]
}
blinktrade.requestDepositList().then(function(deposits) {
console.log(deposits);
});
message='{ "MsgType": "U30", "DepositListReqID": 7739992, "Page": 0, "PageSize": 1 }'
api_url='API_URL_REST_ENDPOINT'
api_key='YOUR_API_KEY_GENERATED_IN_API_MODULE'
api_secret='YOUR_SECRET_KEY_GENERATED_IN_API_MODULE'
nonce=`date +%s`
signature=`echo -n "$nonce" | openssl dgst -sha256 -hex -hmac "$api_secret" | cut -d ' ' -f 2`
curl -X POST "$api_url" \
-H "APIKey:$api_key" \
-H "Nonce:$nonce" \
-H "Signature:$signature" \
-H "Content-Type:application/json" \
-d "$message"
| Name | Type | Description/Value |
|---|---|---|
| MsgType | string | “U30” |
| DepositListReqID | number | Request ID |
| Page | number | Optional; defaults to 0. |
| PageSize | number | Optional; defaults to 20. |
| StatusList | array(string) | “0” = Unconfirmed, “1” = Pending, “2” = In Progress, “4” = Completed, “8” = Cancelled |
EXAMPLE RESPONSE
{
"PageSize": 1,
"DepositListReqID": 7739992,
"MsgType": "U31",
"DepositListGrp": [{
"DepositID": "8312c0f951ef44a393050dc399fb8698",
"DepositMethodID": 502,
"DepositMethodName": "wire_transfer_usa",
"Type": "DTP",
"Currency": "USD",
"Value": 20000000000,
"PaidValue": 0,
"Data": {},
"Created": "2016-09-07 14:33:22",
"ControlNumber": 502000174,
"PercentFee": 1,
"FixedFee": 0,
"Status": "0",
"ReasonID": null,
"Reason": null,
"Username": "rodrigo",
"UserID": 90800003,
"BrokerID": 5,
"ClOrdID": "6351214",
"CreditProvided": 0,
"State": "UNCONFIRMED"
}],
"Page": 0
}
Response
Returns an array of Deposits Model Object.
Request Deposit
MESSAGE EXAMPLE
{
"MsgType": "U18",
"DepositReqID": 3115044,
"DepositMethodID": 403,
"Value": 150000000000,
"Currency": "BRL",
"BrokerID": 5
}
// Bitcoin Deposit
blinktrade.requestDeposit().then(function(deposit) {
console.log(deposit);
});
// Fiat Deposit
blinktrade.requestDeposit({
value: parseInt(200 * 1e8),
currency: "BRL",
depositMethodId: 403,
}).then(function(deposit) {
console.log(deposit);
});
message='{ "MsgType": "U18", "DepositReqID": 3115044, "DepositMethodID": 403, "Value": 150000000000, "Currency": "BRL", "BrokerID": 5 }'
api_url='API_URL_REST_ENDPOINT'
api_key='YOUR_API_KEY_GENERATED_IN_API_MODULE'
api_secret='YOUR_SECRET_KEY_GENERATED_IN_API_MODULE'
nonce=`date +%s`
signature=`echo -n "$nonce" | openssl dgst -sha256 -hex -hmac "$api_secret" | cut -d ' ' -f 2`
curl -X POST "$api_url" \
-H "APIKey:$api_key" \
-H "Nonce:$nonce" \
-H "Signature:$signature" \
-H "Content-Type:application/json" \
-d "$message"
Parameters
| Name | Type | Description/Value |
|---|---|---|
| MsgType | string | “U18” |
| DepositReqID | number | Deposit Request ID |
| DepositMethodID | number | Deposit Method ID - Check with your exchange |
| Value | number | Amount in satoshis |
| Currency | string | <CURRENCY> |
| BrokerID | number | <BROKER_ID> |
Events
| Event | Description |
|---|---|
| DEPOSIT_REFRESH | Callback when deposit refresh |
EXAMPLE RESPONSE
{
"DepositMethodName": "deposit_btc",
"UserID": 90800003,
"ControlNumber": null,
"State": "UNCONFIRMED",
"Type": "CRY",
"PercentFee": 0,
"Username": "rodrigo",
"CreditProvided": 0,
"DepositReqID": 3115044,
"DepositID": "937a0c5e2133400280a356e5902eb6bd",
"Reason": null,
"AccountID": 90800003,
"Data": {
"InputAddress": "mvehwFpiMjhGL5wVSoX3QBSQmeVRdGFTSC",
"Destination": "n19ZAH1WGoUkQhubQw71fH11BenifxpBxf"
},
"ClOrdID": "3115044",
"Status": "0",
"Created": "2016-09-07 14:33:22",
"DepositMethodID": null,
"Value": 0,
"BrokerID": 5,
"PaidValue": 0,
"Currency": "BTC",
"ReasonID": null,
"MsgType": "U19",
"FixedFee": 0
}
Response
Returns a Deposit Model Object.
Withdrawals
Request Withdrawal List
MESSAGE EXAMPLE
{
"MsgType": "U26",
"WithdrawListReqID": 1,
"Page": 0,
"PageSize": 1,
"StatusList": ["1", "2"]
}
blinktrade.requestWithdrawList().then(function(withdraws) {
console.log(withdraws);
});
message='{ "MsgType": "U26", "WithdrawListReqID": 6695476, "Page": 0, "PageSize": 1 }'
api_url='API_URL_REST_ENDPOINT'
api_key='YOUR_API_KEY_GENERATED_IN_API_MODULE'
api_secret='YOUR_SECRET_KEY_GENERATED_IN_API_MODULE'
nonce=`date +%s`
signature=`echo -n "$nonce" | openssl dgst -sha256 -hex -hmac "$api_secret" | cut -d ' ' -f 2`
curl -X POST "$api_url" \
-H "APIKey:$api_key" \
-H "Nonce:$nonce" \
-H "Signature:$signature" \
-H "Content-Type:application/json" \
-d "$message"
Parameters
| Name | Type | Description/Value |
|---|---|---|
| MsgType | string | “U26” |
| WithdrawListReqID | number | An ID chosen by you |
| Page | number | Optional; defaults to 0 |
| PageSize | number | Optional; defaults to 20 |
| StatusList | array(string) | “0” = Unconfirmed, “1” = Pending, “2” = In Progress, “4” = Completed, “8” = Cancelled |
RESPONSE EXAMPLE
{
"WithdrawListReqID": 6695476,
"PageSize": 1,
"WithdrawListGrp": [{
"WithdrawID": 365,
"Method": "bitcoin",
"Currency": "BTC",
"Amount": 100000,
"Data": {
"Wallet": "2Mx3TZycg4XL5sQFfERBgNmg9Ma7uxowK9y",
"Instant": "NO",
"Fees": "฿ 0.00010000"
},
"Created": "2016-05-03 01:15:45",
"Status": "8",
"ReasonID": null,
"Reason": null,
"PercentFee": 0,
"FixedFee": 10000,
"PaidAmount": 110000,
"UserID": 90800003,
"Username": "rodrigo",
"BrokerID": 5,
"ClOrdID": null
}],
"MsgType": "U27",
"Page": 0
}
Response
Returns an array of Withdrawals Model Objects.
Request Withdrawal
To request withdrawals, you need to pass a “data” information, which represents the information to your withdrawal. It’s related to bank accounts, numbers, or a bitcoin address, this information is dynamically and is different for each broker.
MESSAGE EXAMPLE
{
"MsgType": "U6",
"WithdrawReqID": 382616,
"Method": "bradesco",
"Currency": "BRL",
"Amount": 1500000000,
"Data": {
"AccountBranch": "111",
"AccountNumber": "4444-5",
"AccountType": "corrente",
"CPF_CNPJ": "00000000000"
}
}
blinktrade.requestWithdraw({
"amount": parseInt(400 * 1e8),
"currency": "BRL",
"method": "bradesco",
"data": {
"AccountBranch": "111",
"AccountNumber": "4444-5",
"AccountType": "corrente",
"CPF_CNPJ": "00000000000"
}
}).then(function(withdraw) {
console.log(withdraw);
});
api_key=YOUR_API_KEY_GENERATED_IN_API_MODULE
api_secret=YOUR_SECRET_KEY_GENERATED_IN_API_MODULE
nonce=`date +%s`
signature=`echo -n $nonce | openssl dgst -sha256 -hex -hmac $api_secret`
curl -XPOST https://api_testnet.blinktrade.com/tapi/v1/message \
-H "Nonce:$nonce" \
-H "APIKey:$api_key" \
-H "Content-Type:application/json" \
-H "Signature:$signature" \
-d '{"MsgType":"U6","DepositReqID":1,"WithdrawReqID":617625,"Method":"PayPal","Amount":3000000,"Currency":"USD","BrokerID":5,"Data":{"Email":"user@blinktrade.com"}}'
Paramenters
| Params | Type | Description/Value |
|---|---|---|
| MsgType | string | “U6” |
| WithdrawReqID | number | Request ID |
| Method | string | bitcoin for BTC. Check with the exchange all available withdrawal methods |
| Amount | number | Amount in satoshis |
| Currency | string | Currency code |
| Data | object | Data object containing the withdraws required fields |
Events
| Event | Description |
|---|---|
| WITHDRAW_REFRESH | Callback when withdraw refresh |
Confirm Withdraws
After request a withdraw, you might get a error asking for two factor authentication,
you should call confirmWithdraw passing the confirmationToken that was sent to your email,
or secondFactor if needed.
{
"MsgType": "U24",
"WithdrawID": 1,
"WithdrawReqID": 1,
"ConfirmationToken": "TOKEN",
"SecondFactor": "TOKEN",
"WithdrawID": 1
}
blinktrade.confirmWithdraw({
withdrawId: 523,
confirmationToken: "TOKEN"
}).then(function(withdraw) {
console.log(withdraw);
});
RESPONSE EXAMPLE
{
"Username": "rodrigo",
"Status": "1",
"SecondFactorType": "",
"Created": "2016-09-07 14:52:23",
"PaidAmount": 20000000000,
"UserID": 90800003,
"Reason": null,
"Currency": "USD",
"Amount": 20000000000,
"ReasonID": null,
"BrokerID": 5,
"ClOrdID": "3184990",
"WithdrawID": 545,
"WithdrawReqID": 3184990,
"MsgType": "U7",
"Data": {
"AccountBranch": "111",
"AccountNumber": "4444-5",
"AccountType": "corrente",
"CPF_CNPJ": "00000000000"
},
"Method": "PayPal",
"FixedFee": 0,
"PercentFee": 0
}
Response
Returns a Balance and Withdraw Model Object.
Cancel Withdraw
{
"MsgType": "U70",
"WithdrawCancelReqID": 1,
"WithdrawID" : 1
};
blinktrade.cancelWithdraw(1)
Ledger
MESSAGE EXAMPLE
{
"MsgType": "U34",
"LedgerListReqID": 1,
"Page": 0,
"PageSize": 1,
"BrokerID": 4,
"Currency": "BTC"
}
blinktrade.requestLedger().then(function(ledger) {
console.log(ledger);
});
RESPONSE EXAMPLE
{
"PageSize": 20,
"LedgerListGrp": [{
"LedgerID": 136514,
"Currency": "BTC",
"Operation": "C",
"AccountID": 90800127,
"BrokerID": 5,
"PayeeID": 90000001,
"PayeeBrokerID": 5,
"Amount": 10000,
"Balance": 3932168134,
"Reference": "732",
"Created": "2017-01-02 00:08:40",
"Description": "WFR",
"AccountName": "user"
}],
"Page": 0,
"MsgType": "U35",
"LedgerListReqID": 5219413
}
Paramenters
| Params | Type | Description/Value |
|---|---|---|
| MsgType | string | “U34” |
| LedgerListReqID | number | Request ID |
| Page | number | Optional; defaults to 0 |
| PageSize | number | Optional; defaults to 20 |
| BrokerID | number | Optional; <BROKER_ID> |
| Currency | string | Optional; Currency code. (.e.g: BTC) |
| ClientID | number | Optional; UserID used by brokers |
WebSocket API
With the WebSocket API, you have full access to the exchange, you can also check our JavaScript WebSocket implementation here.
Connectivity
The a rate limit is 16 messages per second.
var BlinkTradeWS = require("blinktrade").BlinkTradeWS;
var blinktrade = new BlinkTradeWS({ prod: true });
Heartbeat
You must send this message every 30 seconds to keep your connection alive.
EXAMPLE MESSAGE
{
"MsgType": "1",
"TestReqID": "1473241552307",
"SendTime": 1469031953
}
blinktrade.connect().then(function() {
return blinktrade.heartbeat();
}).then(function(heartbeat) {
console.log(heartbeat.Latency);
});
Paratemers
| Name | Type | Description |
|---|---|---|
| MsgType | string | 1 |
| TestReqID | string | An ID assigned by you. |
It can be any number. The response message associated with this request will contain the same ID SendTime | number | Unix Time Stamp
EXAMPLE RESPONSE
{
"ServerTimestamp": 1473241957,
"TestReqID": 1473241552307,
"MsgType": "0",
"SendTime": 1473241552307,
"Latency": 167
}
Response
| Name | Type | Description |
|---|---|---|
| MsgType | string | 0 |
| TestReqID | string | This should match the TestReqID sent on the message |
| SendTime | number | This should match your SendTime |
| ServerTimestamp | number | Server Unix Time Stamp |
Authentication
Most of WebSocket calls requires authentication, once you login with your username and password on the WebSocket connection, you will be able to access your account. You can also login with your API Key and API Password and you’ll only be allowed to send messages that your API Key has permission to send.
FingerPrint
If you’re not using the JavaScript SDK, You will need to pass a fingerprint from your browser, there’s some finger prints implementations that you can use.
Login
EXAMPLE MESSAGE
{
"MsgType": "BE",
"UserReqID": 9696784,
"BrokerID": 5,
"Username": "TYD3ZilY0FDB1QdkD1iDdlqvcRdnV0sZILNh3D18ZKs",
"Password": "ySIMrLdTqSDo3vL",
"UserReqTyp": "1",
"FingerPrint": "b959a35c7f3f5e9315c99b5a25c2bbda"
}
blinktrade.connect().then(function() {
return blinktrade.login({ username: "", password: "" });
}).then(function(logged) {
console.log(logged);
});
Parameters
| Name | Type | Description |
|---|---|---|
| MsgType | string | BE |
| UserReqID | number | Request Id |
| BrokerID | number | <BROKER_ID> |
| Username | string | The email address, username or API Key of the user |
| Password | string | The password of the user |
| UserReqTyp | string | “1” |
| FingerPrint | string | Browser fingerprint |
| SecondFactor | number | Optional; Second Factor Authentication code generated by authy |
| UserAgent | string | Optional; Browser user agent navigator |
| UserAgentLanguage | string | Optional; User agent language |
| UserAgentTimezoneOffset | number | Optional; User agent timezone offset |
| UserAgentPlatform | string | Optional; User agent platform |
Response
Returns a Login Model Object together with Profile and Broker information.
EXAMPLE RESPONSE
{
"UserID": 90800003,
"TwoFactorEnabled": false,
"EmailLang": "pt_BR",
"Username": "rodrigo",
"IsMSB": false,
"WithdrawFixedFee": null,
"Broker": {},
"Profile": {},
"HasLineOfCredit": false,
"UserStatus": 1,
"IsBroker": false,
"TakerTransactionFeeSell": null,
"ConfirmationOrder": false,
"TakerTransactionFeeBuy": null,
"UserReqID": 9696784,
"MsgType": "BF",
"IsMarketMaker": false,
"DepositPercentFee": null,
"DepositFixedFee": null,
"WithdrawPercentFee": null,
"TransactionFeeBuy": null,
"TransactionFeeSell": null,
"EmailTwoFactorEnabled": false,
"BrokerID": 5,
"PermissionList": {
"*": []
}
}
| Parameter | Type | Description |
|---|---|---|
| MsgType | string | BF |
| Broker | object | Broker model object, see broker response for more informations |
| BrokerID | number | <BROKER_ID> |
| DepositFixedFee | number | Fixed deposit fee |
| DepositPercentFee | number | Deposit fixed fee |
| EmailLang | string | Email Language |
| HasLineOfCredit | boolean | boolean indicating whether user has line of credit |
| IsBroker | boolean | boolean whether user is a broker |
| IsMSB | boolean | |
| Profile | object | Profile model object, see profile model for more informations |
| TakerTransactionFeeBuy | number | Taker fee for buy orders |
| TakerTransactionFeeSell | number | Taker fee for sell orders |
| TransactionFeeBuy | number | Maker fee for buy orders |
| TransactionFeeSell | number | Maker fee for sell orders |
| TwoFactorEnabled | boolean | boolean indicating whether user has two factor enabled |
| UserID | number | Integer with the user ID |
| UserReqTyp | number | Returns only if it’s equal to 3 when password has been changed |
| UserStatus | number | “1” = Logged In, “2” = Not Logged In, “3” = User Not Recognised |
| Username | string | String with the username of the user |
| WithdrawFixedFee | number | Fixed fee for withdrawals |
| WithdrawPercentFee | number | Percent fee for withdrawals |
Subscribe to OrderBook
You can subscribe to one or more Symbols and receive one or more Market Data Entries in realtime. Each Market Data Entry is composed by a bid, offer or a trade occurred.
EXAMPLE MESSAGE
{
"MsgType": "V",
"MDReqID": 9894272,
"SubscriptionRequestType": "1",
"MarketDepth": "0",
"MDUpdateType": "1",
"MDEntryTypes": ["0", "1", "2"],
"Instruments": ["BTCBRL"]
}
blinktrade.connect().then(function() {
return blinktrade.subscribeOrderbook(["BTCUSD"]);
}).then(function(orderbook) {
console.log(orderbook);
});
Parameters
| Name | Type | Description |
|---|---|---|
| MsgType | string | “V” |
| MDReqID | number | Request ID |
| SubscriptionRequestType | string | “1” = Subscribe, “2” = Unsubscribe |
| MarketDepth | string | “0” = Full Book, “1” = Top of Book |
| MDEntryTypes | array(string) | “0” = Bid, “1” = Offer, “2” = Trade |
| MDUpdateType | string | “0” = Full Refresh, “1” = Incremental RefreshRefresh |
| Instruments | array(string) | Array with the symbols that you want to subscribe e.g.: [‘BTCBRL’] |
Response Full Book
| Name | Type | Description |
|---|---|---|
| MsgType | string | “W” |
| MDReqID | number | Request ID |
| MarketDepth | string | “0” = Full Book, “1” = Top of Book |
| Symbol | string | Instrument symbol subscribed |
| MDFullGrp | object | Object containing all orders |
EXAMPLE RESPONSE FULL ORDER BOOK
{
"MDReqID": 9894272,
"Symbol": "BTCUSD",
"MsgType": "W",
"MarketDepth": 0,
"MDFullGrp": {
"BTCUSD": {
"bids": [[ 578, 1.59231429, 90800535 ], [ 577.79, 5.68, 90800535 ]],
"asks": [[ 578.72, 8.32039144, 90800535 ], [ 579.67, 2, 90800535 ]]
}
}
}
While you are subscribed to incremental updates, you will receive bids, asks and trades occurred in realtime.
blinktrade.subscribeOrderbook(["BTCUSD"])
.on("OB:NEW_ORDER", function(order) {
}).on("OB:UPDATE_ORDER", function(order) {
}).on("OB:DELETE_ORDER", function(order) {
}).on("OB:DELETE_ORDERS_THRU", function(order) {
}).on("OB:TRADE_NEW", function(order) {
});
Incremental Refresh Response
| Name | Type | Description |
|---|---|---|
| MsgType | string | “X” |
| MDReqID | number | Request ID |
| MDBkTyp | string | “3” = Order Depth |
| MDIncGrp | array | Array containing the new data entry |
Response MDIncGrp Entry
EXAMPLE RESPONSE
{
"index": 19,
"price": 550,
"size": 0.05,
"side": "buy",
"userId": 90800003,
"orderId": 1459028830971,
"symbol": "BTCUSD",
"time": "Wed Sep 07 2016 14:18:44 GMT-0300 (BRT)",
"type": "OB:NEW_ORDER"
}
| Name | Type | Description |
|---|---|---|
| OrderID | number | Order ID |
| MDEntryPx | number | Order Price |
| MDUpdateAction | string | “0” = New, “1” = Update, “2” = Delete, “3” = Delete Thru |
| MDEntryTime | string | Time when order was created |
| Symbol | string | Order symbol that you have subscribed on market data e.g: “BTCUSD” |
| UserID | number | User ID |
| Broker | string | Broker name that order belongs to |
| MDEntryType | string | “0” = Bid, “1” = Offer, “2” = Trade |
| MDEntryPositionNo | number | Order position on the book |
| MDEntrySize | number | Order size amount |
| MDEntryID | number | Market data entry ID |
| MDEntryDate | string | Date when market data was received |
Subscribe To Ticker
You can subscribe on one or more market symbols
EXAMPLE MESSAGE
{
"MsgType": "e",
"SecurityStatusReqID": 123,
"SubscriptionRequestType": "1",
"Instruments": ["BTCBRL"]
}
blinktrade.subscribeTicker(["BLINK:BTCUSD"]).then(function(ticker) {
console.log(ticker);
});
| Name | Type | Description |
|---|---|---|
| MsgType | string | “e” |
| SecurityStatusReqID | number | Request ID |
| SubscriptionRequestType | string | 1 = Snapshot + Updates (Subscribe) |
| Instruments | array | Array containing the symbols that you want to subscribe |
EXAMPLE RESPONSE
{
"SellVolume": 0.71399999,
"LowPx": 578,
"LastPx": 578,
"MsgType": "f",
"BestAsk": 578.47,
"HighPx": 578.71,
"BuyVolume": 412.71463421,
"BestBid": 578,
"Symbol": "BTCUSD",
"SecurityStatusReqID": 960751,
"Market": "BLINK"
}
Unsubscribe from ticker
To unsubscribe from ticker, you do the same as unSubscribeOrderbook, but passing SecurityStatusReqID to unSubscribeTicker().
EXAMPLE MESSAGE
{
"MsgType": "e",
"SecurityStatusReqID": 960751,
"SubscriptionRequestType": "2"
}
blinktrade.subscribeTicker(["BLINK:BTCUSD"]).then(function(ticker) {
// Note that there's no return when unsubscribe from ticker.
blinktrade.unSubscribeTicker(ticker.SecurityStatusReqID);
});
Response
Returns the given SecurityStatusReqID.
Execution Report
You can listen to execution reports to get when your order has been updated.
blinktrade.executionReport()
.on("EXECUTION_REPORT:NEW", function(data) {
}).on("EXECUTION_REPORT:PARTIAL", function(data) {
}).on("EXECUTION_REPORT:EXECUTION", function(data) {
}).on("EXECUTION_REPORT:CANCELED", function(data) {
}).on("EXECUTION_REPORT:REJECTED", function(data) {
});
EXAMPLE RESPONSE
{
"OrderID": 1459028830811,
"ExecID": 740972,
"ExecType": "0",
"OrdStatus": "0",
"CumQty": 0,
"Symbol": "BTCUSD",
"OrderQty": 5000000,
"LastShares": 0,
"LastPx": 0,
"Price": 55000000000,
"TimeInForce": "1",
"LeavesQty": 5000000,
"MsgType": "8",
"ExecSide": "1",
"OrdType": "2",
"CxlQty": 0,
"Side": "1",
"ClOrdID": 3251968,
"AvgPx": 0
}
Response
| field | Type | Description/Value |
|---|---|---|
| MsgType | string | “8” |
| OrderID | number | Unique identifier for Order as assigned by broker. |
| ExecID | number | Unique identifier of execution message as assigned by broker. |
| ExecType | string | “0” = New, “1” = Partially fill, “2” = Fill, “4” = Cancelled, “8” = Rejected, “A” = Pending New |
| OrdStatus | string | “0” = New, “1” = Partially fill, “2 ”= Fill, “4” = Cancelled, “8” = Rejected, “A” = Pending New |
| LeavesQty | number | Quantity open for further execution. |
| Symbol | string | Currency pair being used. |
| OrderQty | number | Quantity ordered in satoshis. |
| LastShares | number | Quantity of shares bought/sold on this fill. |
| LastPx | number | Price of the last fill. |
| CxlQty | number | Total quantity canceled for this order. |
| TimeInForce | string | “0” = Day, “1” = Good Till Cancel, “4” = Fill or Kill |
| CumQty | number | Total quantity filled. |
| ClOrdID | string | Unique identifier for Order as assigned by you |
| OrdType | string | “2” = Limited |
| Side | string | “1” = Buy, “2” = Sell |
| Price | number | Price per unit of quantity in satoshis. |
| ExecSide | string | Side of this fill. |
| AvgPx | number | Calculated average price of all fills on this order. |
Events
| Event | Description |
|---|---|
| EXECUTION_REPORT:NEW | Callback when you send a new order |
| EXECUTION_REPORT:PARTIAL | Callback when your order has been partialy executed |
| EXECUTION_REPORT:EXECUTION | Callback when an order has been sussefully executed |
| EXECUTION_REPORT:CANCELED | Callback when your order has been canceled |
| EXECUTION_REPORT:REJECTED | Callback when order has been rejected |
Deposit / Withdraw Refresh
When requesting deposits and withdraws, you can listen DEPOSIT_REFRESH and WITHDRAW_REFRESH receive updates.
blinktrade.requestDeposit().on('DEPOSIT_REFRESH', function(deposit) {
console.log(deposit);
});
blinktrade.requestWithdraw().on('WITHDRAW_REFRESH', function(withdraw) {
console.log(withdraw);
});
blinktrade.onDepositRefresh(function(deposit) {
console.log(deposit);
});
blinktrade.onWithdrawRefresh(function(withdraw) {
console.log(withdraw);
});
Reponse
Returns a deposit / withdraw model
Trade History
A list of the last trades executed on an exchange since a chosen date.
NOTE if you want to listen the last trades in real time, you should subscribe to market data instead.
blinktrade.tradeHistory().then(function(trades) {
console.log(trades);
});
Parameters
| Name | Type | Description |
|---|---|---|
| MsgType | string | “U32” |
| TradeHistoryReqID | number | Request ID |
| Since | number | Optional Since |
| Filter | number | Optional Filter |
| Page | number | Optional defaults to 0. |
| PageSize | number | Optional defaults to 80. |
EXAMPLE RESPONSE
{
"TradeHistoryReqID": 1,
"PageSize": 80,
"TradeHistoryGrp": {
"BTCBRL": [{
"TradeID": 486649,
"Market": "BTCBRL",
"Side": "2",
"Price": 202152000000,
"Size": 76389217,
"Buyer": 90869802,
"Seller": 90863020,
"Created": "2016-10-01 20:51:40"
}]
},
"MsgType": "U33",
"Page": 0
}