#PHP Library of BTCChina Trade API A PHP wrapper to trade bitcoin and litecoin via BTCChina API.
##Installation
Firstly, download the library via:
git clone https://github.com/BTCChina/btcchina-api-php
Then, add the following line to your project:
require_once('BTCChinaLibrary.php');cURL extension is required.
##Usage Create Trade API keys at https://vip.btcchina.com/account/apikeys, and set proper permissions as indicated.
Spawn BTCChinaAPI instance with access key and secret key mentioned above. Notice that these keys cannot be modified later.
$btcAPI = new BTCChinaAPI(access_key, secret_key);Call methods similiar to the format described in API documentation.
$res = $btcAPI->getAccountInfo();##Returns Decoded JSON objects of result or error on successful cURL executions.
##Exceptions There are three exceptions extended from BTCChinaException:
- ConnectionException
- JsonRequestException
- ContentException
Aside from standard getMessage(), two more functions are added:
- getMethod(): return name of the method where exception occurred.
- getErrorCode(): implemented in JsonRequestException only, to return the http error code or trade api error code.
##Examples ###Get user information
$res = btcAPI->getAccountInfo();Result: JSON Objects of profile, balance and frozen.
###Place order
$ res = btcAPI->placeOrder($price = NULL, $amount, $market = 'BTCCNY');Market type determines the precision of price and amount. See FAQ No.6 for details. Parameters:
- price: set it to null to trade at market price.
- amount: negative value to sell while positive value to buy.
- market: name of the market to place this order. Default is 'BTCCNY'. Notice that ALL is not supported.
Result: orderID on success. Invalid amount or invalid price error may occur.
###Cancel order
$res = btcAPI->cancelOrder($orderID, $market = 'BTCCNY');Parameters:
- orderID: the ID returned by placeOrder method
- market: name of the market of the order placed previously. Notice that ALL is not supported.
Result: TRUE if successful, otherwise FALSE.
###Get Market Depth
$res = btcAPI->getMarketDepth($limit = 10, $market = 'BTCCNY');Get the complete market depth. Parameters:
- limit: number of orders returned per side.
- market: the market to get depth of. Notice that ALL is not supported.
Result: market_depth JSON object.
###Get Deposits
$res = btcAPI->getDeposits($currency, $pendingonly = true);Get all user deposits.
Parameters:
- currency: type of currency to get deposit records of.
- pendingonly: whether to get open deposits only.
Result: Array of deposit JSON objects.
###Get Withdrawals
$res = btcAPI->getWithdrawals($currency, $pendingonly = true);Get all user withdrawals.
Parameters:
- currency: type of currency to get deposit records of.
- pendingonly: whether to get open withdrawals only.
Result: Array of withdrawal JSON object.
###Get single withdrawal status
$res = btcAPI->getWithdrawal($withdrawalID, $currency = 'BTC');Parameters:
- withdrawalID: the withdrawal to get status of.
- currency: type of currency.
Result: withdrawal JSON object.
###Request a withdrawal
$res = btcAPI->requestWithdrawal($currency, $amount);Make a withdrawal request. BTC withdrawals will pick last used withdrawal address from user profile.
Parameters:
- currency: type of currency to withdraw.
- amount: amount of currency to withdraw.
Result: JSON object: {"id":"withdrawalID"} Notice that the return format of withdrawalID is different from that of orderID.
###Get order status
$res = btcAPI->getOrder($orderID, $market = 'BTCCNY');Parameters:
- orderID: the order to get status of.
- market: the market in which the order is placed. Notice that ALL is not supported.
Result: order JSON object.
###Get all order status
$res = btcAPI->getOrders($openonly = true, $market = 'BTCCNY', $limit = 1000, $offset = 0);Parameters:
- openonly: whether to get open orders only.
- market: the market in which orders are placed.
- limit: the number of orders to show.
- offset: page index of orders.
Result: Array of order JSON objects.
###Get transaction log
$res = btcAPI->getTransactions($transaction = 'all', $limit = 10, $offset = 0);Notice that prices returned by this method may differ from placeOrder as it is the price get procceeded.
Parameters:
- transaction: type of transaction to fetch.
- limit: the number ot transactions.
- offset: page index ot transactions.
Result: Array of transaction JSON objects.
Written with StackEdit.