Markets

Index


Trading Pairs API

Return all the trading pairs supported by Bter

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


Market Info API

Returns all markets' fee, minimum order total amount, price decimal places.

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


Market Details API

Returns market details including pair, coin name, coin symbol, last price, trading volume, coin supply, coin market cap, price trend, etc.

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


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/xrp_cny
http://data.bter.com/api/1/ticker/xrp_btc
http://data.bter.com/api/1/ticker/qtum_btc
http://data.bter.com/api/1/ticker/qtum_cny
http://data.bter.com/api/1/ticker/etp_btc
http://data.bter.com/api/1/ticker/etp_cny
http://data.bter.com/api/1/ticker/btrx_cny
http://data.bter.com/api/1/ticker/btrx_btc
http://data.bter.com/api/1/ticker/bts_cny
http://data.bter.com/api/1/ticker/cnc_cny
http://data.bter.com/api/1/ticker/rep_cny
http://data.bter.com/api/1/ticker/bat_cny
http://data.bter.com/api/1/ticker/snt_cny
http://data.bter.com/api/1/ticker/snt_btc
http://data.bter.com/api/1/ticker/doge_cny
http://data.bter.com/api/1/ticker/dash_cny
http://data.bter.com/api/1/ticker/eth_cny
http://data.bter.com/api/1/ticker/etc_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/ifc_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/shell_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/xcp_cny
http://data.bter.com/api/1/ticker/xmr_cny
http://data.bter.com/api/1/ticker/xpm_cny
http://data.bter.com/api/1/ticker/xtc_cny
http://data.bter.com/api/1/ticker/ltc_btc
http://data.bter.com/api/1/ticker/bts_btc
http://data.bter.com/api/1/ticker/cnc_btc
http://data.bter.com/api/1/ticker/rep_btc
http://data.bter.com/api/1/ticker/bat_btc
http://data.bter.com/api/1/ticker/hkg_btc
http://data.bter.com/api/1/ticker/doge_btc
http://data.bter.com/api/1/ticker/dash_btc
http://data.bter.com/api/1/ticker/eth_btc
http://data.bter.com/api/1/ticker/etc_btc
http://data.bter.com/api/1/ticker/ftc_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/xtc_btc
http://data.bter.com/api/1/ticker/xcn_btc
http://data.bter.com/api/1/ticker/xcp_btc
http://data.bter.com/api/1/ticker/xem_btc
http://data.bter.com/api/1/ticker/xem_cny
http://data.bter.com/api/1/ticker/xpm_btc
http://data.bter.com/api/1/ticker/xmr_btc
http://data.bter.com/api/1/ticker/mg_btc
http://data.bter.com/api/1/ticker/ifc_ltc
http://data.bter.com/api/1/ticker/tips_ltc
http://data.bter.com/api/1/ticker/tix_ltc
http://data.bter.com/api/1/ticker/etc_eth
http://data.bter.com/api/1/ticker/zec_btc
http://data.bter.com/api/1/ticker/zec_cny

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/xrp_cny
http://data.bter.com/api/1/depth/xrp_btc
http://data.bter.com/api/1/depth/qtum_btc
http://data.bter.com/api/1/depth/qtum_cny
http://data.bter.com/api/1/depth/etp_btc
http://data.bter.com/api/1/depth/etp_cny
http://data.bter.com/api/1/depth/btrx_cny
http://data.bter.com/api/1/depth/btrx_btc
http://data.bter.com/api/1/depth/bts_cny
http://data.bter.com/api/1/depth/cnc_cny
http://data.bter.com/api/1/depth/rep_cny
http://data.bter.com/api/1/depth/bat_cny
http://data.bter.com/api/1/depth/snt_cny
http://data.bter.com/api/1/depth/snt_btc
http://data.bter.com/api/1/depth/doge_cny
http://data.bter.com/api/1/depth/dash_cny
http://data.bter.com/api/1/depth/eth_cny
http://data.bter.com/api/1/depth/etc_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/ifc_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/shell_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/xcp_cny
http://data.bter.com/api/1/depth/xmr_cny
http://data.bter.com/api/1/depth/xpm_cny
http://data.bter.com/api/1/depth/xtc_cny
http://data.bter.com/api/1/depth/ltc_btc
http://data.bter.com/api/1/depth/bts_btc
http://data.bter.com/api/1/depth/cnc_btc
http://data.bter.com/api/1/depth/rep_btc
http://data.bter.com/api/1/depth/bat_btc
http://data.bter.com/api/1/depth/hkg_btc
http://data.bter.com/api/1/depth/doge_btc
http://data.bter.com/api/1/depth/dash_btc
http://data.bter.com/api/1/depth/eth_btc
http://data.bter.com/api/1/depth/etc_btc
http://data.bter.com/api/1/depth/ftc_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/xtc_btc
http://data.bter.com/api/1/depth/xcn_btc
http://data.bter.com/api/1/depth/xcp_btc
http://data.bter.com/api/1/depth/xem_btc
http://data.bter.com/api/1/depth/xem_cny
http://data.bter.com/api/1/depth/xpm_btc
http://data.bter.com/api/1/depth/xmr_btc
http://data.bter.com/api/1/depth/mg_btc
http://data.bter.com/api/1/depth/ifc_ltc
http://data.bter.com/api/1/depth/tips_ltc
http://data.bter.com/api/1/depth/tix_ltc
http://data.bter.com/api/1/depth/etc_eth
http://data.bter.com/api/1/depth/zec_btc
http://data.bter.com/api/1/depth/zec_cny

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/xrp_cny
http://data.bter.com/api/1/trade/xrp_btc
http://data.bter.com/api/1/trade/qtum_btc
http://data.bter.com/api/1/trade/qtum_cny
http://data.bter.com/api/1/trade/etp_btc
http://data.bter.com/api/1/trade/etp_cny
http://data.bter.com/api/1/trade/btrx_cny
http://data.bter.com/api/1/trade/btrx_btc
http://data.bter.com/api/1/trade/bts_cny
http://data.bter.com/api/1/trade/cnc_cny
http://data.bter.com/api/1/trade/rep_cny
http://data.bter.com/api/1/trade/bat_cny
http://data.bter.com/api/1/trade/snt_cny
http://data.bter.com/api/1/trade/snt_btc
http://data.bter.com/api/1/trade/doge_cny
http://data.bter.com/api/1/trade/dash_cny
http://data.bter.com/api/1/trade/eth_cny
http://data.bter.com/api/1/trade/etc_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/ifc_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/shell_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/xcp_cny
http://data.bter.com/api/1/trade/xmr_cny
http://data.bter.com/api/1/trade/xpm_cny
http://data.bter.com/api/1/trade/xtc_cny
http://data.bter.com/api/1/trade/ltc_btc
http://data.bter.com/api/1/trade/bts_btc
http://data.bter.com/api/1/trade/cnc_btc
http://data.bter.com/api/1/trade/rep_btc
http://data.bter.com/api/1/trade/bat_btc
http://data.bter.com/api/1/trade/hkg_btc
http://data.bter.com/api/1/trade/doge_btc
http://data.bter.com/api/1/trade/dash_btc
http://data.bter.com/api/1/trade/eth_btc
http://data.bter.com/api/1/trade/etc_btc
http://data.bter.com/api/1/trade/ftc_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/xtc_btc
http://data.bter.com/api/1/trade/xcn_btc
http://data.bter.com/api/1/trade/xcp_btc
http://data.bter.com/api/1/trade/xem_btc
http://data.bter.com/api/1/trade/xem_cny
http://data.bter.com/api/1/trade/xpm_btc
http://data.bter.com/api/1/trade/xmr_btc
http://data.bter.com/api/1/trade/mg_btc
http://data.bter.com/api/1/trade/ifc_ltc
http://data.bter.com/api/1/trade/tips_ltc
http://data.bter.com/api/1/trade/tix_ltc
http://data.bter.com/api/1/trade/etc_eth
http://data.bter.com/api/1/trade/zec_btc
http://data.bter.com/api/1/trade/zec_cny


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://api.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://api.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 can be used for cancelling or getting order.


Cancel order API

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

Parameter submission method: POST

Parameter:

Parameter Description Example
order_id Order ID 123456
pair Pair ltc_btc

Return data format: JSON

Return data example:

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


Get order status API

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

Parameter submission method: POST

Parameter:

Parameter Description Example
order_id Order ID 123456
pair Pair ltc_btc

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 my open order list API

API URL: https://api.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",
				"pair":"ltc_btc",
				"type":"buy",
				"rate":0.033251,
				"amount":"0.39901357",
				"initial_rate":0.033251,
				"initial_amount":"1"
				"status":"open"
			},
			{
				"id":"15092",				
				"sell_type":"LTC",
				"buy_type":"BTC",				
				"sell_amount":"13.0",
				"buy_amount":"0.4210",
				"pair":"ltc_btc",
				"type":"buy",
				"rate":0.0323846,
				"amount":"0.4210",
				"initial_rate":0.0323846,
				"initial_amount":"1"
				"status":"open"
			}
			]
		"msg":"Success"
	}

				


Get my last 24h trades API

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

Parameter submission method: POST

Parameter:

Parameter Description Example
pair currency pair ltc_btc
order_id Order ID (optional) 626150

Return data format: JSON

Return data example:


	{
		"result":true,
		"trades":[
		    {
		      "id":"7942422"
		      "orderid":"38100777"
		      "pair":"ltc_btc"
		      "type":"sell"
		      "rate":"0.01719"
		      "amount":"0.0588"
		      "time":"06-12 02:49:11"
		      "time_unix":"1402512551"
		    }
		    {
		      "id":"7942422"
		      "orderid":"38100491"
		      "pair":"ltc_btc"
		      "type":"buy"
		      "rate":"0.01719"
		      "amount":"0.0588"
		      "time":"06-12 02:49:11"
		      "time_unix":"1402512551"
		    }
	  	]
	  	"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://api.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://api.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();
		
	} 
?>