PHP code example of buzorin / php-cobinhood-api

1. Go to this page and download the library: Download buzorin/php-cobinhood-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

buzorin / php-cobinhood-api example snippets



$cobinhood = new Cobinhood\API_client("<api key>");


$cobinhood = new Cobinhood\API_client("<api key>");

$last_price = $cobinhood->get_last_price("COB-BTC");
if (!$last_price["error"]) {
    echo $last_price;
    // 0.00001601
}

$limit = 5; // Optional. Defaults to 50 if not specified, if limit is 0, it means to fetch the whole order book.

$depth = $cobinhood->get_order_book("COB-BTC", $limit);
if (!$depth["error"]) {
    print_r($depth);
}

$currencies = $cobinhood->get_currencies();
if (!$currencies["error"]) {
    print_r($currencies);
}

$trading_pairs = $cobinhood->get_trading_pairs();
if (!$trading_pairs["error"]) {
    print_r($trading_pairs);
}

$stats = $cobinhood->get_stats();
if (!$stats["error"]) {
    print_r($stats);
}

$ticker = $cobinhood->get_ticker("COB-BTC");
if (!$ticker["error"]) {
    print_r($ticker);
}

$tickers = $cobinhood->get_tickers();
if (!$tickers["error"]) {
    print_r($tickers);
}

$limit = 3; // Optional. Defaults to 20 if not specified, max 50.

$trades = $cobinhood->get_trades("COB-BTC", $limit);
if (!$trades["error"]) {
    print_r($trades);
}

$timeframe = "5m"; // Timeframes: 1m, 5m, 15m, 30m, 1h, 3h, 6h, 12h, 1D, 7D, 14D, 1M
$startTime = 1519307723000; // Optional. Unix timestamp in milliseconds. Defaults to 0 if not specified. You can set it to false.
$endTime   = 1519308723000; // Optional. Unix timestamp in milliseconds. Defaults to current server time if not specified. You can set it to false.

$candles = $cobinhood->get_candles("COB-BTC", $timeframe, $endTime, $startTime);
if (!$candles["error"]) {
    print_r($candles);
}

$server_time = $cobinhood->get_server_time();
if (!$server_time["error"]) {
    echo $server_time;
    // 1520076475432
}

$server_info = $cobinhood->get_server_info();
if (!$server_info["error"]) {
    print_r($server_info);
}

$price = 0.000017;
$quantity = 1000;

$limit_buy_order = $cobinhood->limit_buy("COB-BTC", $price, $quantity);
if (!$limit_buy_order["error"]) {
    print_r($limit_buy_order);
}

$price = 0.000017;
$quantity = 1000;

$limit_sell_order = $cobinhood->limit_sell("COB-BTC", $price, $quantity);
if (!$limit_sell_order["error"]) {
    print_r($limit_sell_order);
}

$quantity = 1000;

$market_buy_order = $cobinhood->market_buy("COB-BTC", $quantity);
if (!$market_buy_order["error"]) {
    print_r($market_buy_order);
}

$quantity = 1000;

$market_sell_order = $cobinhood->market_sell("COB-BTC", $quantity);
if (!$market_sell_order["error"]) {
    print_r($market_sell_order);
}

$order_id = "37f550a2-2aa6-20f4-a3fe-e120f420637c";

$order_status = $cobinhood->get_order_status($order_id);
if (!$order_status["error"]) {
    print_r($order_status);
}

$order_id = "37f550a2-2aa6-20f4-a3fe-e120f420637c";

$cancel_order = $cobinhood->cancel_order($order_id);
if (!$cancel_order["error"] && $cancel_order) {
    echo "Order cancelled";
    // Order cancelled
}

$orderId = '37f550a2-2aa6-20f4-a3fe-e120f420637c';
$price = 0.000018;
$quantity = 1000;

$modify_order = $cobinhood->modify_order($order_id);
if (!$modify_order["error"] && $modify_order) {
    echo "Order modified";
    // Order modified
}

$limit = 2; // Optional. Defaults to 20 if not specified, max 50.

$open_orders = $cobinhood->get_open_orders("COB-ETH", $limit);
if (!$open_orders["error"]) {
    print_r($open_orders);
}

$limit = 2; // Optional. Defaults to 20 if not specified, max 50.

$open_orders_all = $cobinhood->get_open_orders_all($limit);
if (!$open_orders_all["error"]) {
    print_r($open_orders_all);
}

$order_id = "37f550a2-2aa6-20f4-a3fe-e120f420637c";

$order_trades = $cobinhood->get_order_trades($order_id);
if (!$order_trades["error"]) {
    print_r($order_trades);
}

$limit = 2; // Optional. Defaults to 50 if not specified.

$orders_history = $cobinhood->get_orders_history("COB-BTC", $limit);
if (!$orders_history["error"]) {
    print_r($orders_history);
}

$limit = 2; // Optional. Defaults to 50 if not specified.

$orders_history_all = $cobinhood->get_orders_history_all($limit);
if (!$orders_history_all["error"]) {
    print_r($orders_history_all);
}

$balances = $cobinhood->get_balances();
if (!$balances["error"]) {
    print_r($balances);
}

$limit = 3; // Defaults to 20 if not specified, max 50.

$balance_history = $cobinhood->get_balance_history("ETH", $limit);
if (!$balance_history["error"]) {
    print_r($balance_history);
}

$limit = 3; // Defaults to 20 if not specified, max 50.

$balance_history_all = $cobinhood->get_balance_history_all($limit);
if (!$balance_history_all["error"]) {
    print_r($balance_history_all);
}

$deposit_addresses = $cobinhood->get_deposit_addresses("ETH");
if (!$deposit_addresses["error"]) {
    print_r($deposit_addresses);
}

$deposit_addresses_all = $cobinhood->get_deposit_addresses_all();
if (!$deposit_addresses_all["error"]) {
    print_r($deposit_addresses_all);
}

$deposit_id = "09619448-985d-4485-835e-b69096194482";

$deposit_status = $cobinhood->get_deposit_status($deposit_id);
if (!$deposit_status["error"]) {
    print_r($deposit_status);
}

$deposits = $cobinhood->get_deposits();
if (!$deposits["error"]) {
    print_r($deposits);
}

$withdrawal_addresses = $cobinhood->get_withdrawal_addresses("ETH");
if (!$withdrawal_addresses["error"]) {
    print_r($withdrawal_addresses);
}

$withdrawal_addresses_all = $cobinhood->get_withdrawal_addresses_all();
if (!$withdrawal_addresses_all["error"]) {
    print_r($withdrawal_addresses_all);
}

$withdrawal_id = "09619448-985d-4485-835e-b69096194482";

$withdrawal_status = $cobinhood->get_withdrawal_status($withdrawal_id);
if (!$withdrawal_status["error"]) {
    print_r($withdrawal_status);
}

$withdrawals = $cobinhood->get_withdrawals();
if (!$withdrawals["error"]) {
    print_r($withdrawals);
}
sh
composer