add_order($pid, $order_type, $symbol, $shares);
    } elseif ($_GET['action'] == 'delete') {
        $pid = 1;
        delete_order($pid, 'BUY', 'AAPL');
    } elseif ($_GET['action'] == 'update') {
        $pid = 1;
        update_order($pid, 'BUY', 'AAPL', 500);
    } elseif ($_GET['action'] == 'get_order') {
        $pid = 1;
        get_open_order($pid);
    } elseif ($_GET['action'] == 'get_quote') {
        $pid = 1;
        get_yahoo_quote("AAPL+IBM+GS+BAC+FB+WYNN+SZYM+DANG+TSLA+JCP+BIDU+CMG+V+LVS");
    } elseif ($_GET['action'] == 'refresh_realtime_quotes') {
        $pid = 1;
        refresh_realtime_quotes($a);
    }
}
function add_order($pid, $order_type, $symbol, $shares)
{
    global $order_queue;
    $query = "insert into {$order_queue} (portfolio_id, order_date, order_type, symbol, shares) values ({$pid}, now(), '{$order_type}', '{$symbol}', {$shares}) \n\t\t\t  on duplicate key update shares = shares + {$shares}, order_date = now() ";
    try {
        $result = queryMysql($query);
    } catch (Exception $e) {
        echo "Problem Query: {$query} \n";
        echo 'Caught exception: ', $e->getMessage(), "\n";
    }
}
function delete_order($pid, $order_type, $symbol)
{
        $pid = 1;
        update_order($pid, 'BUY', 'AAPL', 500);
    } elseif ($_GET['action'] == 'get_order') {
        $pid = 1;
        get_open_order($pid);
    } elseif ($_GET['action'] == 'get_quote') {
        $pid = 1;
        #$result = get_yahoo_quote("AAPL+IBM+GS+BAC+FB+WYNN+SZYM+DANG+TSLA+JCP+BIDU+CMG+V+LVS");
        $result = get_yahoo_quote("AAPL+NU+IBM+GS+BAC+FB+CFN+WYNN+SZYM+DANG+TSLA+JCP+BIDU+CMG+V+LVS");
        echo $result, PHP_EOL;
    } elseif ($_GET['action'] == 'refresh_realtime_quotes') {
        $pid = 1;
        $symbol = $_GET['symbol'];
        $a = "";
        #echo "symbol: $symbol ", PHP_EOL;
        refresh_realtime_quotes($symbol);
    } elseif ($_GET['action'] == 'execute_all_orders') {
        execute_all_orders();
    }
}
function add_order($pid, $order_type, $symbol, $shares)
{
    global $order_queue;
    $query = "insert into {$order_queue} (portfolio_id, order_date, order_type, symbol, shares) values ({$pid}, now(), '{$order_type}', '{$symbol}', {$shares}) \n\t\t\t  on duplicate key update shares = shares + {$shares}, order_date = now() ";
    #echo $query, PHP_EOL;
    try {
        $result = queryMysql($query);
    } catch (Exception $e) {
        echo "Problem Query: {$query} \n";
        echo 'Caught exception: ', $e->getMessage(), "\n";
    }