빙산 위탁 - 구매

저자:제로, 날짜: 2014-07-24 14:39
태그:무역 지원빙산

아이스산 위탁은 투자자가 대규모 거래를 할 때 시장에 과도한 충격을 피하기 위해 큰 주문을 자동으로 여러 주문으로 분할하여 현재 최신 구매/판매 가격과 고객이 설정한 가격 전략에 따라 자동으로 소액 주문을 수행하고, 이전 주문이 완전히 거래되거나 최신 가격이 현재 주문 가격에서 크게 벗어나면 자동으로 다시 주문을 수행하는 것을 의미합니다. 예를 들어: 만약 단일 평균값의 부동 소수점이 10으로 설정되면: 각 위탁의 수는 단일 위탁 평균의 90%~110%에 해당하며, 위탁 가격은 최신 구매 가격* ((1-위탁 깊숙이) 에 1이며, 이전 위탁이 모두 거래된 후 새로운 위탁을 수행하고, 최신 거래 가격이 위탁에서 위탁 깊숙이*2를 초과하면 자동으로 취소되고 재중개됩니다. 전략 전체 거래량이 전체 위탁량과 같을 때 위탁을 중단합니다. 시장에서 최신 거래 가격이 최고 구매 가격보다 높을 때 위탁을 중단하고, 최신 거래 가격이 최고 구매 가격보다 낮을 때 위탁을 다시 시작합니다.




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));
}


관련

더 많은