Iceberg commissioned - bought

Author: Zero, Date: 2014-07-24 14:39:00
Tags: Trade-aidedIceberg

Ice Mountain order refers to the investor when making a large transaction, in order to avoid causing too much shock to the market, to commission the large order automatically split into several orders, according to the current latest buy/sell price and the price strategy set by the customer, automatically re-commission the order when the previous order is fully completed or the latest price deviates significantly from the current order price. Examples: If the floating point number of a single mean is set to 10, then: The number of orders is 90%-110% of the average of their single orders, the price of the order is the latest purchase price of 1* (deepness of the order 1), a new order is placed after the last order has been fully completed, and the order is automatically withdrawn and re-commissioned when the latest transaction price is more than the depth of the order 2. The order is stopped when the total amount of transactions in the strategy is equal to its total number of orders. The order is stopped when the latest transaction price in the market is higher than its highest purchase price, and the order is resumed when the latest transaction price is lower than the highest purchase price.




function CancelPendingOrders() {
    while (true) {
        var orders = _C(exchange.GetOrders);
        if (orders.length == 0) {
            return;
        }

        for (var j = 0; j < orders.length; j++) {
            exchange.CancelOrder(orders[j].Id);
            if (j < (orders.length-1)) {
                Sleep(Interval);
            }
        }
    }
}

var LastBuyPrice = 0;
var InitAccount = null;

function dispatch() {
    var account = null;
    var ticker = _C(exchange.GetTicker);
    // 在最新成交价格距离该笔委托超过委托深度*2时自动撤单并重新进行委托
    if (LastBuyPrice > 0) {
        // 订单没有完成
        if (_C(exchange.GetOrders).length > 0) {
            if (ticker.Last > LastBuyPrice && ((ticker.Last - LastBuyPrice) / LastBuyPrice) > (2*(EntrustDepth/100))) {
                Log('偏离过多, 最新成交价:', ticker.Last, '委托价', LastBuyPrice);
                CancelPendingOrders();
            } else {
                return true;
            }
        } else {
            account = _C(exchange.GetAccount);
            Log("买单完成, 累计花费:", _N(InitAccount.Balance - account.Balance), "平均买入价:", _N((InitAccount.Balance - account.Balance) / (account.Stocks - InitAccount.Stocks)));
        }
        LastBuyPrice = 0;
    }
    
    
    // 委托价格为最新买1价*(1-委托深度)
    var BuyPrice = _N(ticker.Buy * (1 - EntrustDepth/100));
    if (BuyPrice > MaxBuyPrice) {
        return true;
    }
    
    if (!account) {
        account = _C(exchange.GetAccount);
    }


    if ((InitAccount.Balance - account.Balance) >= TotalBuyNet) {
        return false;
    }
    
    var RandomAvgBuyOnce = (AvgBuyOnce * ((100 - FloatPoint) / 100)) + (((FloatPoint * 2) / 100) * AvgBuyOnce * Math.random());
    var UsedMoney = Math.min(account.Balance, RandomAvgBuyOnce, TotalBuyNet - (InitAccount.Balance - account.Balance));
    
    var BuyAmount = _N(UsedMoney / BuyPrice);
    if (BuyAmount < MinStock) {
        return false;
    }
    LastBuyPrice = BuyPrice;
    exchange.Buy(BuyPrice, BuyAmount, '花费: ', _N(UsedMoney), '上次成交价', ticker.Last);
    return true;
}

function main() {
    if (exchange.GetName().indexOf('Futures_') != -1) {
        throw "只支持现货";
    }
    CancelPendingOrders();
    InitAccount = _C(exchange.GetAccount);
    Log(InitAccount);
    if (InitAccount.Balance < TotalBuyNet) {
        throw "账户余额不足";
    }
    LoopInterval = Math.max(LoopInterval, 1);
    while (dispatch()) {
        Sleep(LoopInterval * 1000);
    }
    Log("委托全部完成", _C(exchange.GetAccount));
}


Related

More