- Warning: Unofficial Mobile Apps. Read More
APIv2
0. Upgrade from APIv1
- API URL becomes
https://api.lakebtc.com/api_v2/ - Authentication method remains the same.
- Use
symbol(e.g.,btceur) as input parameters. - Numbers in response data are returned as strings with double quotes.
- Several other changes for API methods and response data. See below for details.
- APIv1 is deprecated. Cutoff date is April 1st, 2017
1. Market Data (REST)
Ticker
For last price, best bid, best ask, 24-hour high and 24-hour low prices for different symbols.
GET https://api.LakeBTC.com/api_v2/ticker
Result is as follows. Data is cached on the server-side so it is unnecessary to make frequent visits.
{"btcusd":{"high":"1188.96","low":"1162.44","volume":"3395.566569","last":"1175.0","bid":"1174.99","ask":"1178.7"},"btceur":{"high":"1123.83","low":"1099.86","volume":"374.586756","last":"1108.28","bid":"1108.28","ask":"1112.2"}, ... }
Order Book
GET this url: https://api.LakeBTC.com/api_v2/bcorderbook?symbol=btcusd
Data is cached at the server-side so it is unnecessary to make frequent visits. For a list of available symbols, go to https://www.LakeBTC.com and scroll to the page bottom.
{"asks":[["1112.7","0.0911"],["1112.8","0.0161"],["1112.91","0.1708"],["1113.01","7.6425"], ... ],"bids":[["1108.28","0.0019"],["1107.98","30.7106"],["1107.88","0.0053"],["1107.86","0.0191"], ... ]}
Trade Histroy
GET this url: https://api.lakebtc.com/api_v2/bctrades?symbol=btceur
Returns the most recent trades for a particular symbol.
[{"date":1488204142,"price":"1108.28","amount":"0.077146","tid":1488204142},{"date":1488204143,"price":"1108.17","amount":"0.022854","tid":1488204143},{"date":1488204352,"price":"1108.28","amount":"0.0051","tid":1488204352}, ....]
2. Trading API (REST)
Authentication
LakeBTC provides trading JSON-RPC API interface. HMAC (Hash-based Message Authentication Code) is employed as our authentication mechanisms.
- Click Me in the menu, then API Keys tab to obtain your API access and private keys. You need at least 1 BTC in your account to retrieve your access and private keys.
- Prepare the following attributes
tonce(timestamp in microseconds, i.e., unixtime × 1000000. Make sure your clock is correctly adjusted)accesskeyrequestmethod(post)id(JSON-RPC request id, an integer)method(JSON-RPC method)params(JSON-RPC parameters)
- Concatenate the above parameters with
&, in that order (like a query string). Parameters can be blank. For example,$params=tonce=1389067414466757&accesskey=myaccesskey&requestmethod=post&id=123&method=ticker¶ms=
- Create HMAC signature with your private key by using SHA1. $hash =
hash_hmac('sha1', $signature, $privatetkey) #php
- Join your access key and the hash signature with colon (:), and sign with Base64. $b64 =
base64_encode("myaccesskey:<hash>") #php
- Set HTTP Header. Make sure tonce is the same as that in Step 2.
Json-Rpc-Tonce: 1389067414466757 #HTTP HEADERAuthorization: Basic YXRjQHF3amlhbi5jb206ZmEzM2UzYzg5MDZjg5MzdiYzFiYw== #HTTP HEADER
- POST
paramsdata in JSON format to this url:https://api.LakeBTC.com/api_v2
API Methods
getAccountInfo
method=getAccountInfoparams=(i.e., blank)returns
{"balance"=>{"btc"=>"2339.327", "eur"=>"539323.47", ... }, "locked"=>{"btc"=>"1309.2538", "eur"=>"286.47", ... }, "profile"=>{"email"=>"johndoe@example.com", "uid"=>"U123456789", "btc_deposit_addres"=>"14n...."}}
buyOrder
method=buyOrderparams=823.42,0.1234,btceur(i.e., price, amount, symbol concatenated by commas)- This method submits orders to the match engine. Call
getOrdersmethod to check the actual order status. returns
{"id"=>877443117, "result"=>"order received"}
sellOrder
method=sellOrderparams=823.42,0.1234,btceur(i.e., price, amount, symbol concatenated by commas)- This method submits orders to the match engine. Call
getOrdersmethod to check the actual order status. returns
{"id"=>877443117, "result"=>"order received"}
openOrders
method=openOrdersparams=(i.e., blank)returns
[{"id"=>877443815, "amount"=>"0.1234", "price"=>"823.42", "symbol"=>"btceur", "type"=>"buy", "at"=>1485259926}, ... ]
getOrders
method=getOrdersparams=877443815,877443818(i.e., order id's)returns
[{"id"=>877443815, "original_amount"=>"0.1234", "amount"=>"0.01", "price"=>"823.42", "symbol"=>"btceur", "type"=>"buy", "state"=>"active", "at"=> 1485259926}, ... ]
cancelOrders
method=cancelOrdersparams=877443815,877443818(i.e., order id's)- This method submits order cancelation requests to the match engine. Please call
getOrdersmethod to check the actual order status. returns
{"result"=>true}
getTrades
method=getTradesparams=1403078138(i.e., start timestamp)returns up to 100 records
[{"type"=>"ask", "symbol"=>"btceur", "amount"=>"0.0001", "total"=>"0.1", "at"=>1481463286}, {"type"=>"bid", "symbol"=>"gbpusd", "amount"=>"0.09", "total"=>"0.11", "at"=>1481463462}, ... ]
getExternalAccounts
method= getExternalAccountsparams=(i.e., blank)- This is for BTC only
returns
[{"id"=>"3322070951", "type"=>"btc", "address"=>"1Fo....", "alias"=>nil, "currencies"=>"btc", "state"=>"verified", "updated_at"=>1459860435}, ... ]
createWithdraw
method= createWithdrawparams=0.1,btc,3322070951(i.e., amount, currency, External Account ID)- This is for BTC only
returns
{"id"=>"3344007518", "amount"=>"0.1", "currency"=>"btc", "fee"=>"0.0005", "state"=>"accepted", "source"=>"btc", "external_account_id"=>"3322070951", "at"=>1485262315}
3. Sample Code (REST)
Simply save the following code to a file test.php, put in your keys, and run php test.php in command line. It'll print out debug information. If you are on an old Operating System, you may need to uncomment curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); temporarily to avoid SSL certificate problems.
<?php
function sign($method, $params){
$accessKey = "myaccesskey";
$secretKey = "mysecretkey";
$mt = explode(' ', microtime());
$ts = $mt[1] . substr($mt[0], 2, 6);
$signature = urldecode(http_build_query(array(
'tonce' => $ts,
'accesskey' => $accessKey,
'requestmethod' => 'post',
'id' => 1,
'method' => $method,
'params' => is_array($params) ? implode(',', $params) : $params
)));
var_dump($signature);
$hash = hash_hmac('sha1', $signature, $secretKey);
return array(
'ts' => $ts,
'hash' => $hash,
'auth' => base64_encode($accessKey.':'. $hash),
);
}
function request($method, $params){
$sign = sign($method, $params);
$postData = json_encode(array(
'method' => $method,
'params' => $params,
'id' => 1
));
$headers = array(
'Authorization: Basic ' . $sign['auth'],
'Json-Rpc-Tonce: ' . $sign['ts'],
'Content-Type:application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT,
'LakeBTC Trader; '.php_uname('a').'; PHP/'.phpversion().')'
);
curl_setopt($ch, CURLOPT_URL, 'https://api.lakebtc.com/api_v2');
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$res = curl_exec($ch);
return $res;
}
try {
var_dump(request('getAccountInfo', array()));
// var_dump(request('buyOrder', array(123.45, 1.23, 'btcusd')));
// var_dump(request('getOrders', array(61576, 61812)));
// var_dump(request('cancelOrders', array(61576, 69123)));
// var_dump(request('getTrades', 1480334314));
} catch (Exception $e) {
echo "Error:".$e->getMessage();
}
?>
You can also refer to APIv1 Sample Code. Although those code snippets do not work off the shelf for APIv2, most parts (including authentication method) are the same for APIv2 and APIv1.
4. Sample Code (WebSocket)
<!DOCTYPE html>
<meta charset="utf-8" />
<title>WebSocket Test</title>
<script src="https://js.pusher.com/4.2/pusher.min.js"></script>
<script type="text/javascript">
var pusher = new Pusher("lakebtc", {encrypted: true, wsHost: "ws.lakebtc.com", wssPort: 8085, disableStats: true, httpHost: "ws.lakebtc.com", statsHost: "ws.lakebtc.com"});
var channel = pusher.subscribe("market-global");
channel.bind('tickers', function(data) {
var div = document.getElementById('data');
div.innerHTML += '<p>' + JSON.stringify(data) + '</p>';
});
var channel2 = pusher.subscribe("market-eurusd-global")
channel2.bind('update', function(data) {
console.log('orderbook: ' + JSON.stringify(data));
});
channel2.bind('trades', function(data) {
console.log('trades: ' + JSON.stringify(data));
});
</script>
<body>
<h1>WebSocket Example</h1>
<div id='data'></div>
</body>
</html>


日本語
Svenska
Français
Español
Português Brasileiro