Markets

Index


Trading Pairs API

Return all the trading pairs supported by Bter

URL: http://data.bter.com/api/1/pairs


Tickers API

returns the tickers for all the supported trading pairs at once, cached in 10 seconds::

URL: http://data.bter.com/api/1/tickers


Ticker API

returns the current ticker for the selected currency, cached in 10 seconds:

URL: http://data.bter.com/api/1/ticker/[CURR_A]_[CURR_B]

Replace [CURR_A] and [CURR_B] with the selected currencies.

Links:

http://data.bter.com/api/1/ticker/btc_cny
http://data.bter.com/api/1/ticker/ltc_cny
http://data.bter.com/api/1/ticker/bqc_cny
http://data.bter.com/api/1/ticker/btb_cny
http://data.bter.com/api/1/ticker/btq_cny
http://data.bter.com/api/1/ticker/cent_cny
http://data.bter.com/api/1/ticker/cmc_cny
http://data.bter.com/api/1/ticker/cnc_cny
http://data.bter.com/api/1/ticker/dgc_cny
http://data.bter.com/api/1/ticker/doge_cny
http://data.bter.com/api/1/ticker/dtc_cny
http://data.bter.com/api/1/ticker/dvc_cny
http://data.bter.com/api/1/ticker/exc_cny
http://data.bter.com/api/1/ticker/ftc_cny
http://data.bter.com/api/1/ticker/frc_cny
http://data.bter.com/api/1/ticker/ifc_cny
http://data.bter.com/api/1/ticker/max_cny
http://data.bter.com/api/1/ticker/mec_cny
http://data.bter.com/api/1/ticker/mint_cny
http://data.bter.com/api/1/ticker/mmc_cny
http://data.bter.com/api/1/ticker/net_cny
http://data.bter.com/api/1/ticker/nmc_cny
http://data.bter.com/api/1/ticker/nxt_cny
http://data.bter.com/api/1/ticker/ppc_cny
http://data.bter.com/api/1/ticker/pts_cny
http://data.bter.com/api/1/ticker/qrk_cny
http://data.bter.com/api/1/ticker/red_cny
http://data.bter.com/api/1/ticker/src_cny
http://data.bter.com/api/1/ticker/tag_cny
http://data.bter.com/api/1/ticker/tips_cny
http://data.bter.com/api/1/ticker/tix_cny
http://data.bter.com/api/1/ticker/vtc_cny
http://data.bter.com/api/1/ticker/wdc_cny
http://data.bter.com/api/1/ticker/xcp_cny
http://data.bter.com/api/1/ticker/xpm_cny
http://data.bter.com/api/1/ticker/yac_cny
http://data.bter.com/api/1/ticker/zcc_cny
http://data.bter.com/api/1/ticker/zet_cny
http://data.bter.com/api/1/ticker/ltc_btc
http://data.bter.com/api/1/ticker/aur_btc
http://data.bter.com/api/1/ticker/bc_btc
http://data.bter.com/api/1/ticker/bqc_btc
http://data.bter.com/api/1/ticker/btb_btc
http://data.bter.com/api/1/ticker/buk_btc
http://data.bter.com/api/1/ticker/c2_btc
http://data.bter.com/api/1/ticker/cdc_btc
http://data.bter.com/api/1/ticker/cmc_btc
http://data.bter.com/api/1/ticker/cnc_btc
http://data.bter.com/api/1/ticker/dgc_btc
http://data.bter.com/api/1/ticker/doge_btc
http://data.bter.com/api/1/ticker/dtc_btc
http://data.bter.com/api/1/ticker/exc_btc
http://data.bter.com/api/1/ticker/flt_btc
http://data.bter.com/api/1/ticker/frc_btc
http://data.bter.com/api/1/ticker/ftc_btc
http://data.bter.com/api/1/ticker/kdc_btc
http://data.bter.com/api/1/ticker/max_btc
http://data.bter.com/api/1/ticker/mec_btc
http://data.bter.com/api/1/ticker/mint_btc
http://data.bter.com/api/1/ticker/mmc_btc
http://data.bter.com/api/1/ticker/nec_btc
http://data.bter.com/api/1/ticker/nmc_btc
http://data.bter.com/api/1/ticker/nxt_btc
http://data.bter.com/api/1/ticker/ppc_btc
http://data.bter.com/api/1/ticker/prt_btc
http://data.bter.com/api/1/ticker/pts_btc
http://data.bter.com/api/1/ticker/qrk_btc
http://data.bter.com/api/1/ticker/src_btc
http://data.bter.com/api/1/ticker/tag_btc
http://data.bter.com/api/1/ticker/yac_btc
http://data.bter.com/api/1/ticker/vtc_btc
http://data.bter.com/api/1/ticker/wdc_btc
http://data.bter.com/api/1/ticker/xcp_btc
http://data.bter.com/api/1/ticker/xpm_btc
http://data.bter.com/api/1/ticker/zcc_btc
http://data.bter.com/api/1/ticker/zet_btc
http://data.bter.com/api/1/ticker/cent_ltc
http://data.bter.com/api/1/ticker/dvc_ltc
http://data.bter.com/api/1/ticker/ifc_ltc
http://data.bter.com/api/1/ticker/net_ltc
http://data.bter.com/api/1/ticker/red_ltc
http://data.bter.com/api/1/ticker/tips_ltc
http://data.bter.com/api/1/ticker/tix_ltc

Depth API

Return the market depth including ask and bid orders.

URL: http://data.bter.com/api/1/depth/[CURR_A]_[CURR_B]

Replace [CURR_A] and [CURR_B] with the selected currencies.

Links:

http://data.bter.com/api/1/depth/btc_cny
http://data.bter.com/api/1/depth/ltc_cny
http://data.bter.com/api/1/depth/bqc_cny
http://data.bter.com/api/1/depth/btb_cny
http://data.bter.com/api/1/depth/btq_cny
http://data.bter.com/api/1/depth/cent_cny
http://data.bter.com/api/1/depth/cmc_cny
http://data.bter.com/api/1/depth/cnc_cny
http://data.bter.com/api/1/depth/dgc_cny
http://data.bter.com/api/1/depth/doge_cny
http://data.bter.com/api/1/depth/dtc_cny
http://data.bter.com/api/1/depth/dvc_cny
http://data.bter.com/api/1/depth/exc_cny
http://data.bter.com/api/1/depth/ftc_cny
http://data.bter.com/api/1/depth/frc_cny
http://data.bter.com/api/1/depth/ifc_cny
http://data.bter.com/api/1/depth/max_cny
http://data.bter.com/api/1/depth/mec_cny
http://data.bter.com/api/1/depth/mint_cny
http://data.bter.com/api/1/depth/mmc_cny
http://data.bter.com/api/1/depth/net_cny
http://data.bter.com/api/1/depth/nmc_cny
http://data.bter.com/api/1/depth/nxt_cny
http://data.bter.com/api/1/depth/ppc_cny
http://data.bter.com/api/1/depth/pts_cny
http://data.bter.com/api/1/depth/qrk_cny
http://data.bter.com/api/1/depth/red_cny
http://data.bter.com/api/1/depth/src_cny
http://data.bter.com/api/1/depth/tag_cny
http://data.bter.com/api/1/depth/tips_cny
http://data.bter.com/api/1/depth/tix_cny
http://data.bter.com/api/1/depth/vtc_cny
http://data.bter.com/api/1/depth/wdc_cny
http://data.bter.com/api/1/depth/xcp_cny
http://data.bter.com/api/1/depth/xpm_cny
http://data.bter.com/api/1/depth/yac_cny
http://data.bter.com/api/1/depth/zcc_cny
http://data.bter.com/api/1/depth/zet_cny
http://data.bter.com/api/1/depth/ltc_btc
http://data.bter.com/api/1/depth/aur_btc
http://data.bter.com/api/1/depth/bc_btc
http://data.bter.com/api/1/depth/bqc_btc
http://data.bter.com/api/1/depth/btb_btc
http://data.bter.com/api/1/depth/buk_btc
http://data.bter.com/api/1/depth/c2_btc
http://data.bter.com/api/1/depth/cdc_btc
http://data.bter.com/api/1/depth/cmc_btc
http://data.bter.com/api/1/depth/cnc_btc
http://data.bter.com/api/1/depth/dgc_btc
http://data.bter.com/api/1/depth/doge_btc
http://data.bter.com/api/1/depth/dtc_btc
http://data.bter.com/api/1/depth/exc_btc
http://data.bter.com/api/1/depth/flt_btc
http://data.bter.com/api/1/depth/frc_btc
http://data.bter.com/api/1/depth/ftc_btc
http://data.bter.com/api/1/depth/kdc_btc
http://data.bter.com/api/1/depth/max_btc
http://data.bter.com/api/1/depth/mec_btc
http://data.bter.com/api/1/depth/mint_btc
http://data.bter.com/api/1/depth/mmc_btc
http://data.bter.com/api/1/depth/nec_btc
http://data.bter.com/api/1/depth/nmc_btc
http://data.bter.com/api/1/depth/nxt_btc
http://data.bter.com/api/1/depth/ppc_btc
http://data.bter.com/api/1/depth/prt_btc
http://data.bter.com/api/1/depth/pts_btc
http://data.bter.com/api/1/depth/qrk_btc
http://data.bter.com/api/1/depth/src_btc
http://data.bter.com/api/1/depth/tag_btc
http://data.bter.com/api/1/depth/yac_btc
http://data.bter.com/api/1/depth/vtc_btc
http://data.bter.com/api/1/depth/wdc_btc
http://data.bter.com/api/1/depth/xcp_btc
http://data.bter.com/api/1/depth/xpm_btc
http://data.bter.com/api/1/depth/zcc_btc
http://data.bter.com/api/1/depth/zet_btc
http://data.bter.com/api/1/depth/cent_ltc
http://data.bter.com/api/1/depth/dvc_ltc
http://data.bter.com/api/1/depth/ifc_ltc
http://data.bter.com/api/1/depth/net_ltc
http://data.bter.com/api/1/depth/red_ltc
http://data.bter.com/api/1/depth/tips_ltc
http://data.bter.com/api/1/depth/tix_ltc

Trade History API

Return the most recent 80 trade history records:

URL: http://data.bter.com/api/1/trade/[CURR_A]_[CURR_B]

Return at most 1,000 trade history records after [TID]:

URL: http://data.bter.com/api/1/trade/[CURR_A]_[CURR_B]/[TID]

Replace [CURR_A] and [CURR_B] with the selected currencies.

Links:

http://data.bter.com/api/1/trade/btc_cny
http://data.bter.com/api/1/trade/ltc_cny
http://data.bter.com/api/1/trade/bqc_cny
http://data.bter.com/api/1/trade/btb_cny
http://data.bter.com/api/1/trade/btq_cny
http://data.bter.com/api/1/trade/cent_cny
http://data.bter.com/api/1/trade/cmc_cny
http://data.bter.com/api/1/trade/cnc_cny
http://data.bter.com/api/1/trade/dgc_cny
http://data.bter.com/api/1/trade/doge_cny
http://data.bter.com/api/1/trade/dtc_cny
http://data.bter.com/api/1/trade/dvc_cny
http://data.bter.com/api/1/trade/exc_cny
http://data.bter.com/api/1/trade/ftc_cny
http://data.bter.com/api/1/trade/frc_cny
http://data.bter.com/api/1/trade/ifc_cny
http://data.bter.com/api/1/trade/max_cny
http://data.bter.com/api/1/trade/mec_cny
http://data.bter.com/api/1/trade/mint_cny
http://data.bter.com/api/1/trade/mmc_cny
http://data.bter.com/api/1/trade/net_cny
http://data.bter.com/api/1/trade/nmc_cny
http://data.bter.com/api/1/trade/nxt_cny
http://data.bter.com/api/1/trade/ppc_cny
http://data.bter.com/api/1/trade/pts_cny
http://data.bter.com/api/1/trade/qrk_cny
http://data.bter.com/api/1/trade/red_cny
http://data.bter.com/api/1/trade/src_cny
http://data.bter.com/api/1/trade/tag_cny
http://data.bter.com/api/1/trade/tips_cny
http://data.bter.com/api/1/trade/tix_cny
http://data.bter.com/api/1/trade/vtc_cny
http://data.bter.com/api/1/trade/wdc_cny
http://data.bter.com/api/1/trade/xcp_cny
http://data.bter.com/api/1/trade/xpm_cny
http://data.bter.com/api/1/trade/yac_cny
http://data.bter.com/api/1/trade/zcc_cny
http://data.bter.com/api/1/trade/zet_cny
http://data.bter.com/api/1/trade/ltc_btc
http://data.bter.com/api/1/trade/aur_btc
http://data.bter.com/api/1/trade/bc_btc
http://data.bter.com/api/1/trade/bqc_btc
http://data.bter.com/api/1/trade/btb_btc
http://data.bter.com/api/1/trade/buk_btc
http://data.bter.com/api/1/trade/c2_btc
http://data.bter.com/api/1/trade/cdc_btc
http://data.bter.com/api/1/trade/cmc_btc
http://data.bter.com/api/1/trade/cnc_btc
http://data.bter.com/api/1/trade/dgc_btc
http://data.bter.com/api/1/trade/doge_btc
http://data.bter.com/api/1/trade/dtc_btc
http://data.bter.com/api/1/trade/exc_btc
http://data.bter.com/api/1/trade/flt_btc
http://data.bter.com/api/1/trade/frc_btc
http://data.bter.com/api/1/trade/ftc_btc
http://data.bter.com/api/1/trade/kdc_btc
http://data.bter.com/api/1/trade/max_btc
http://data.bter.com/api/1/trade/mec_btc
http://data.bter.com/api/1/trade/mint_btc
http://data.bter.com/api/1/trade/mmc_btc
http://data.bter.com/api/1/trade/nec_btc
http://data.bter.com/api/1/trade/nmc_btc
http://data.bter.com/api/1/trade/nxt_btc
http://data.bter.com/api/1/trade/ppc_btc
http://data.bter.com/api/1/trade/prt_btc
http://data.bter.com/api/1/trade/pts_btc
http://data.bter.com/api/1/trade/qrk_btc
http://data.bter.com/api/1/trade/src_btc
http://data.bter.com/api/1/trade/tag_btc
http://data.bter.com/api/1/trade/yac_btc
http://data.bter.com/api/1/trade/vtc_btc
http://data.bter.com/api/1/trade/wdc_btc
http://data.bter.com/api/1/trade/xcp_btc
http://data.bter.com/api/1/trade/xpm_btc
http://data.bter.com/api/1/trade/zcc_btc
http://data.bter.com/api/1/trade/zet_btc
http://data.bter.com/api/1/trade/cent_ltc
http://data.bter.com/api/1/trade/dvc_ltc
http://data.bter.com/api/1/trade/ifc_ltc
http://data.bter.com/api/1/trade/net_ltc
http://data.bter.com/api/1/trade/red_ltc
http://data.bter.com/api/1/trade/tips_ltc
http://data.bter.com/api/1/trade/tix_ltc


Trade API

The following APIs can be used for auto-trading in a program.
Notice: please set Content-Type to application/x-www-form-urlencoded in your HTTP request header if it's not the default value.

Click here to obtain a Key and Secret. Use the the Secret as a passphrase to sign the POST data in SHA512 encryption. Send the Key and Sign back in HTTPS Header for Authentication. Please refer to the following instructions and PHP example codes.

Get account fund balances API

API URL: https://bter.com/api/1/private/getfunds

Parameter submission method: POST

Parameter: None

Return data format: JSON

Return data example:

	{
		"result":"true",
		"available_funds":{
			"CNY":"1122.16",
			"BTC":"0.83337671",
			"LTC":"94.364",
			"YAC":"0.07161",
			"WDC":"82.35029899"
		},
		"locked_funds":{
			"BTC":"0.0002",
			"YAC":"10.01"
		}
	}
				


Place order API

API URL: https://bter.com/api/1/private/placeorder

Parameter submission method: POST

Parameter:

Parameter Description Example
pair currency pair ltc_btc
type trading type SELL or BUY
rate The rate to buy or sell 0.023
amount The amount to buy or sell 100

Return data format: JSON

Return data example:

	{
		"result":"true",
		"order_id":"123456",
		"msg":"Success"
	}
				

Notice: The returned order_id is meaningless, please use this API https://bter.com/api/1/private/orderlist to obtain all your open order IDs


Cancel order API

API URL: https://bter.com/api/1/private/cancelorder

Parameter submission method: POST

Parameter:

Parameter Description Example
order_id Order ID 123456

Return data format: JSON

Return data example:

	{
		"result":"true",
		"msg":"Success"
	}
				


Get order status API

API URL: https://bter.com/api/1/private/getorder

Parameter submission method: POST

Parameter:

Parameter Description Example
order_id Order ID 123456

Return data format: JSON

Return data example:


	{
		"result":true,
		"order":{
			"id":"15088",
			"status":"cancelled",
			"pair":"btc_cny",
			"type":"sell",
			"rate":811,
			"amount":"0.39901357",
			"initial_rate":811,
			"initial_amount":"1"
		},
		"msg":"Success"
	}

				


Get open order list API

API URL: https://bter.com/api/1/private/orderlist

Parameter submission method: POST

Parameter: None

Return data format: JSON

Return data example:


	{
		"result":true,
		"orders":[
			{
				"id":"15088",				
				"sell_type":"BTC",
				"buy_type":"LTC",				
				"sell_amount":"0.39901357",
				"buy_amount":"12.0"
			},
			{
				"id":"15092",				
				"sell_type":"LTC",
				"buy_type":"BTC",				
				"sell_amount":"13.0",
				"buy_amount":"0.4210"
			}
			]
		"msg":"Success"
	}

				


Example codes in PHP

				

<?php

	function bter_query($path, array $req = array()) {
		// API settings, add your Key and Secret at here
		$key = '';
		$secret = '';
	 
		// generate a nonce to avoid problems with 32bits systems
		$mt = explode(' ', microtime());
		$req['nonce'] = $mt[1].substr($mt[0], 2, 6);
	 
		// generate the POST data string
		$post_data = http_build_query($req, '', '&');
		$sign = hash_hmac('sha512', $post_data, $secret);
	 
		// generate the extra headers
		$headers = array(
			'KEY: '.$key,
			'SIGN: '.$sign,
		);

		//!!! please set Content-Type to application/x-www-form-urlencoded if it's not the default value

		// curl handle (initialize if required)
		static $ch = null;
		if (is_null($ch)) {
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
			curl_setopt($ch, CURLOPT_USERAGENT, 
				'Mozilla/4.0 (compatible; Bter PHP bot; '.php_uname('a').'; PHP/'.phpversion().')'
				);
		}
		curl_setopt($ch, CURLOPT_URL, 'https://bter.com/api/'.$path);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

		// run the query
		$res = curl_exec($ch);

		if ($res === false) throw new Exception('Curl error: '.curl_error($ch));
		//echo $res;
		$dec = json_decode($res, true);
		if (!$dec) throw new Exception('Invalid data: '.$res);
		return $dec;
	}
	 
	 function get_top_rate($pair, $type='BUY') {
		$rate = 0;

		// our curl handle (initialize if required)
		static $ch = null;
		if (is_null($ch)) {
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
			curl_setopt($ch, CURLOPT_USERAGENT, 
				'Mozilla/4.0 (compatible; Bter PHP bot; '.php_uname('a').'; PHP/'.phpversion().')'
				);
		}
		curl_setopt($ch, CURLOPT_URL, 'https://bter.com/api/1/depth/'.$pair);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

		// run the query
		$res = curl_exec($ch);
		if ($res === false) throw new Exception('Could not get reply: '.curl_error($ch));
		//echo $res;
		$dec = json_decode($res, true);
		if (!$dec) throw new Exception('Invalid data: '.$res);
		
		if (strtoupper($type) == 'BUY') {
			$r =  $dec['bids'][0];
			$rate = $r[0];
		} else  {
			$r = end($dec['asks']);
			$rate = $r[0];
		}

		return $rate;
	}


	try {
		// example 1: get funds
		var_dump(bter_query('1/private/getfunds'));
		
		// example 2: place a buy order
		$pair = 'ltc_btc';
		$type = 'buy';
		$rate = get_top_rate($pair, $type) * 1.01;
		var_dump(bter_query('1/private/placeorder', 
			array(
				'pair' => "$pair",
				'type' => "$type",
				'rate' => "$rate",
				'amount' => '0.01',
				)
			  )
			);
		
		// example 3: cancel an order
		var_dump(bter_query('1/private/cancelorder', array('order_id' => 125811)));
		
		// example 4: get order status
		var_dump(bter_query('1/private/getorder', array('order_id' => 15088)));

		//example 5: list all open orders
		var_dump(bter_query('1/private/orderlist'));
		
	} catch (Exception $e) {
		echo "Error:".$e->getMessage();
		
	} 
?>