LakeBTC API

01/07/2014 

Market Data (REST)

Ticker

For last price, best bid, best ask, 24-hour high and 24-hour low prices in USD and CNY.

  1. GET this url:
    • https://www.LakeBTC.com/api_v1/ticker
  2. Result is as follows. Data is cached on the server-side so it is unnecessary to make frequent visits.

     {"USD"=>{"last"=>829.69, "bid"=>949.58, "ask"=>949.59, "high"=>829.69, "low"=>829.69}, "CNY"=>{"last"=>4763.8, "bid"=>5728.66, "ask"=>5728.67, "high"=>5812, "low"=>4898}}
    

Order Book

GET this url: https://www.LakeBTC.com/api_v1/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.

Trade Histroy

GET this url: https://www.lakebtc.com/api_v1/bctrades?since=1393684528

We had a major database migration in March and only history data after that is available in this API.

Trading API (REST)

Authentication

LakeBTC provides trading JSON-RPC API interface. HMAC (Hash-based Message Authentication Code) is employed as our authentication mechanisms. You need at 0.1 BTC in your account to retrieve your private key.

  1. Besides your private key, the client needs to 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)
  2. Concatenate the above parameters with &, in that order. Parameters can be blank. For example, $signature =
    • tonce=1389067414466757&accesskey=foo@bar.com&requestmethod=post&id=123&method=ticker&params=
  3. Create HMAC signature with your private key by using SHA1. $hash =
    • hash_hmac('sha1', $signature, $privatetkey) #php
  4. Join your access key and the hash signature with colon (:), and sign with Base64. $b64 =
    • base64_encode("myaccesskey:<hash>") #php YXRjQHF3amlhbi5jb206ZmEzM2UzYzg5MDZjg5MzdiYzFiYw==
  5. Set HTTP Header. Note tonce is the same as that in Step 2.
    • Json-Rpc-Tonce: 1389067414466757 #HTTP HEADER
    • Authorization: Basic YXRjQHF3amlhbi5jb206ZmEzM2UzYzg5MDZjg5MzdiYzFiYw== #HTTP HEADER
  6. POST params data in JSON format to this url:
    • https://www.LakeBTC.com/api_v1

API Methods

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

      {"profile"=>{"email"=>"foo@bar.com", "id"=>"U826459145", "btc_deposit_addres"=>"16pVfBxNog3pxtbaEBVDEVRZJhJ8PZoxnX"}, "balance"=>{"USD"=>4829.33, "CNY"=>1008215.55, "BTC"=>20.8613}}
      
  2. buyOrder
    • method=buyOrder
    • params=823.42,0.1234,USD (i.e., unit price, amount, currency concatenated by commas)
    • returns

      {"id"=>3252, "result"=>{"trades"=>0, "total_traded_btc"=>0, "total_traded_currency"=>0, "currency"=>"CNY"}}
      
  3. sellOrder
    • method=sellOrder
    • params=823.42,0.1234,USD (i.e., unit price, amount, currency concatenated by commas)
    • returns

      {"id"=>3253, "result"=>{"trades"=>1, "total_traded_btc"=>0.0001, "total_traded_currency"=>0.47565, "currency"=>"CNY", "ppc"=>4756.5}}
      
  4. getOrders
    • method=getOrders
    • params= (i.e., blank)
  5. cancelOrder
    • method=cancelOrder
    • params=1234 (i.e., order id)
    • returns

      {"result"=>true}
      
  6. getTrades
    • method=getTrades
    • params=1403078138 (i.e., start timestamp)
    • returns up to 100 records

      [{"type"=>"sell", "currency"=>"USD", "amount"=>0.8284, "total"=>506.62, "at"=>1403078138}, {"type"=>"sell", "currency"=>"USD", "amount"=>0.3816, "total"=>233.37, "at"=>1403078141}, {"type"=>"buy", "currency"=>"CNY", "amount"=>1.115, "total"=>5550.91, "at"=>1403078152}]
      

Sample Code

If you are using a different programming language and not familiar with PHP, you can simply save the following code to a file test.php, and run php test.php in your command line. It'll print debug information.

<?php
  function sign($method, $params){

    $accessKey = "foo@bar.com"; 
    $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' => implode(',', $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);

    $options = array( 
      CURLOPT_HTTPHEADER => array(
        'Authorization: Basic ' . $sign['auth'],
        'Json-Rpc-Tonce: ' . $sign['ts'],
      ),
  );

    $postData = json_encode(array(
      'method' => $method,
      'params' => $params,
      'id' => 1,
    ));
    print($postData);

    $headers = array(
      'Authorization: Basic ' . $sign['auth'],
      'Json-Rpc-Tonce: ' . $sign['ts'],
    );        
    $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://www.lakebtc.com/api_v1');
    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(523.45, 1.23, 'USD')));
  } catch (Exception $e) {                
    echo "Error:".$e->getMessage();         
  } 

?>

Bitcoin News

    News »