function place_order($have_amount_disp, $have_currency, $want_amount_disp, $want_currency) { global $is_logged_in; $have_currency = strtoupper($have_currency); $want_currency = strtoupper($want_currency); curr_supported_check($have_currency); curr_supported_check($want_currency); // convert for inclusion into database $have_amount = numstr_to_internal($have_amount_disp); $want_amount = numstr_to_internal($want_amount_disp); if ($have_currency == 'BTC') { order_worthwhile_check($have_amount, $have_amount_disp, $have_currency, MINIMUM_BTC_AMOUNT); order_worthwhile_check($want_amount, $want_amount_disp, $want_currency, MINIMUM_FIAT_AMOUNT); } else { order_worthwhile_check($have_amount, $have_amount_disp, $have_currency, MINIMUM_FIAT_AMOUNT); order_worthwhile_check($want_amount, $want_amount_disp, $want_currency, MINIMUM_BTC_AMOUNT); } enough_money_check($have_amount, $have_currency); do_query("START TRANSACTION"); // deduct money from their account deduct_funds($have_amount, $have_currency); // add the money to the order book $query = "\n INSERT INTO orderbook (\n uid,\n initial_amount,\n amount,\n type,\n initial_want_amount,\n want_amount,\n want_type)\n VALUES (\n '{$is_logged_in}',\n '{$have_amount}',\n '{$have_amount}',\n '{$have_currency}',\n '{$want_amount}',\n '{$want_amount}',\n '{$want_currency}');\n "; $result = do_query($query); $orderid = mysql_insert_id(); do_query("COMMIT"); return $orderid; }
function do_withdraw($amount_disp, $curr_type, &$voucher_code, &$reqid) { global $is_logged_in; if (!ENABLE_LOCAL_VOUCHERS && isset($_POST['voucher'])) { throw Error('Vouchers are not enabled on this site', 'Withdrawing to a voucher code is disabled.'); } $amount = numstr_to_internal($amount_disp); // dollar amounts should be truncated to cents, but Bitcoins are more divisible if ($curr_type == 'BTC') { $amount = truncate_num($amount, BTC_WITHDRAW_DECIMAL_PLACES); } else { $amount = truncate_num($amount, 2); } curr_supported_check($curr_type); order_worthwhile_check($amount, $amount_disp, $curr_type, MINIMUM_WITHDRAW); enough_money_check($amount, $curr_type); check_withdraw_limit($is_logged_in, $amount, $curr_type); if (!save_details($is_logged_in, $amount, $curr_type, $voucher_code, $reqid)) { throw Error('We had to admit it sometime...', 'Stop trading on thie site. Contact the admin FAST.'); } // actually take the money now deduct_funds($amount, $curr_type); // request is submitted to the queue for the cron job to actually execute (unless it's a voucher) }