Ejemplo n.º 1
0
Archivo: btc1.php Proyecto: KriiV/fxalg
function print_balance($response = false)
{
    if (!$response) {
        $response = btce_query('getInfo');
    }
    $str = "";
    foreach ($response['return']['funds'] as $key => $val) {
        if ($val > 0) {
            if (strlen($str) > 0) {
                $str .= ",";
            }
            $str .= " " . $val . " " . strtoupper($key);
        }
    }
    echo date("H:i:s") . ' Balance:' . $str . "\n";
}
	function cancelOrders( $type = NULL ) //modified to only cancel buy orders.
	{
		global $GOX;
		global $BTCE;
		global $exchangeBuySell;
		global $sleepCancel;
		global $engineAmount;
		global $simulate;
		global $maxPendingOrders;
		global $countCancelled;
		global $ordersPlaced;
		
		if (@$GLOBALS['BTCE']) $return = json_decode(btce_query("OrderList"), TRUE);
		if (@$GOX){
			$return = json_decode(mtgox_query('BTCUSD/money/orders'), TRUE);
			( $return['result'] == "success" ? $return['success'] = 1 : $return['success'] = 0);
			$return['return'] = $return['data'];

		}
		if($return['success'] > 0){
			$countCancel=0;
			$tmp2 = 0; print "Canceling Orders\n";
			foreach ($return['return'] as $key => $value){
				$order_id = $key;
				if (@$GOX){
					$tmp1 = $value['amount']['value'];
					$value['amount'] = NULL;
					$value['amount'] = $tmp1;
					$value['rate'] = $value['price']['value'];
					$order_id = $value['oid'];
				}
				if ( $value['type'] == $type && (@$value['pair'] == "btc_usd" || @$value['item'] == "BTC") ){ //$value['amount'] != $engineAmount &&
					if (!$simulate && $countCancel >= $maxPendingOrders ) {
						if ( $tmp2 == 50 ) {print "\nCanceling";$tmp2=0;} else {print ".";$tmp2++;};
						if (@$BTCE) $trade = json_decode(btce_query("CancelOrder", array("order_id" => $order_id)), TRUE);
						if (@$GOX) $trade = json_decode(mtgox_query("BTCUSD/money/order/cancel", array("oid" => $order_id)), TRUE);
						if (@$GOX) ( $trade['result'] == "success" ? $trade['success'] = 1 : $trade['success'] = 0);
					}
					if ($trade['success'] == 1){
						$countCancel++;
						$countCancelled++;
						unset($ordersPlaced[$order_id]); //remove this order from our orders placed list
					}
					time_nanosleep(0,$sleepCancel);
				}
			}
			print "\nCancelled {$countCancel} {$type} Orders \n";
		}
		while ( empty($return) ){
			if (@$GLOBALS['BTCE']) $GLOBALS['return'] = json_decode(btce_query('getInfo'), TRUE);
			if (@$GLOBALS['GOX'])  $GLOBALS['return'] = json_decode(mtgox_query('BTCUSD/money/info'), TRUE);
			time_nanosleep(0,$sleepCancel);
		}
	}