コード例 #1
0
    //don't use the entire balance
    //    $tradeAmt = 0.16;
}
//echo ' '.$marginUSD/$latestPrice .' ';
if ($ma_7 > $ma_30) {
    //uptrend signal
    $output .= '[ uptrend ][ tradeAmt: ' . $tradeAmt . ' ][ ' . $currency . ' ]';
    //data recorded for api_trade_data table
    $last_action_data = array('last_action' => 'buy', 'last_price' => $latestPrice, 'trade_signal' => 'uptrend', 'currency' => $currency);
    $data = array('symbol' => $symbol, 'price' => $latestPrice, 'amount' => "{$tradeAmt}", 'side' => 'buy', 'type' => 'limit', 'exchange' => 'bitfinex');
    //if trading is turned on
    if ($debug != 1 && $bitfinex_trading == 1) {
        //do not trade in debug mode
        if ($marginUSD > $acctUSD) {
            //if margin is available
            $newTrade = $bitfinexAPI->new_order($data);
            //new long position
            if ($newTrade['is_live'] == 1) {
                //if trade is live
                sendMail('[Bitfinex] Buy ' . $tradeAmt . ' ' . $currency . ' at ' . $latestPrice);
                update_last_action($last_action_data);
                //update the last action
                $output .= '[ buy ]' . $newline;
                $output .= array_debug($newTrade) . $newline;
            }
        } else {
            //no balance left to trade
            $output .= ' no balance to trade ';
        }
        //if active postion - claim short/long margin position
        if ($position['amount'] < 0 && $position['status'] == 'ACTIVE') {