APIv2

02/27/2017 

0. Upgrade from APIv1

  1. API URL becomes https://api.lakebtc.com/api_v2/
  2. Authentication method remains the same.
  3. Use symbol (e.g., btceur) as input parameters.
  4. Numbers in response data are returned as strings with double quotes.
  5. Several other changes for API methods and response data. See below for details.
  6. 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.

  1. Click Me in the menu, then API Keys tab to obtain your API access and private keys. You need at least 0.1 BTC in your account to retrieve your access and private keys.
  2. Prepare the following attributes
    • tonce (timestamp in microseconds, i.e., unixtime × 1000000. Make sure your clock is correctly adjusted)
    • accesskey
    • requestmethod (post)
    • id (JSON-RPC request id, an integer)
    • method (JSON-RPC method)
    • params (JSON-RPC parameters)
  3. 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&params=
  4. Create HMAC signature with your private key by using SHA1. $hash =
    • hash_hmac('sha1', $signature, $privatetkey) #php
  5. Join your access key and the hash signature with colon (:), and sign with Base64. $b64 =
    • base64_encode("myaccesskey:<hash>") #php
  6. Set HTTP Header. Make sure tonce is the same as that in Step 2.
    • Json-Rpc-Tonce: 1389067414466757 #HTTP HEADER
    • Authorization: Basic YXRjQHF3amlhbi5jb206ZmEzM2UzYzg5MDZjg5MzdiYzFiYw== #HTTP HEADER
  7. POST params data in JSON format to this url:
    • https://api.LakeBTC.com/api_v2

API Methods

  1. getAccountInfo

    • method=getAccountInfo
    • params= (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...."}}
      
  2. buyOrder

    • method=buyOrder
    • params=823.42,0.1234,btceur (i.e., price, amount, symbol concatenated by commas)
    • This method submits orders to the match engine. Call getOrders method to check the actual order status.
    • returns

      {"id"=>877443117, "result"=>"order received"}
      
  3. sellOrder

    • method=sellOrder
    • params=823.42,0.1234,btceur (i.e., price, amount, symbol concatenated by commas)
    • This method submits orders to the match engine. Call getOrders method to check the actual order status.
    • returns

      {"id"=>877443117, "result"=>"order received"}
      
  4. openOrders

    • method=openOrders
    • params= (i.e., blank)
    • returns

      [{"id"=>877443815, "amount"=>"0.1234", "price"=>"823.42", "symbol"=>"btceur", "type"=>"buy", "at"=>1485259926}, ... ]
      
  5. getOrders

    • method=getOrders
    • params=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}, ... ]
      
  6. cancelOrders

    • method=cancelOrders
    • params=877443815,877443818 (i.e., order id's)
    • This method submits order cancelation requests to the match engine. Please call getOrders method to check the actual order status.
    • returns

      {"result"=>true}
      
  7. getTrades

    • method=getTrades
    • params=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}, ... ]
      
  8. getExternalAccounts

    • method= getExternalAccounts
    • params= (i.e., blank)
    • This is for BTC only
    • returns

      [{"id"=>"3322070951", "type"=>"btc", "address"=>"1Fo....", "alias"=>nil, "currencies"=>"btc", "state"=>"verified", "updated_at"=>1459860435}, ... ]
      
  9. createWithdraw

    • method= createWithdraw
    • params=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

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.

Bitcoin News

    News »