资源加载中... loading...

累进法

Author: 量价时空, Date: 2020-07-14 16:11:37
Tags: C++


void main() {
    Sleep(10000);
    Log(exchange.GetAccount());
    int i=0;
    auto s=s1;
    while (1) {
        if (exchange.IO("status") == 1) {
            exchange.SetContractType(Symbol);
            auto ticker = exchange.GetTicker();
            auto position = exchange.GetPosition();
             auto orders = exchange.GetOrders();
            if (position.size() > 0 && !(orders.size() > 0)) {
                if (!position[0].Type) {
                 if(position[0].Profit > l*s || position[0].Profit < (20-l)*s){
                        exchange.SetContractType(Symbol);
                        exchange.SetDirection("closebuy_today");
                        exchange.Sell(ticker.Buy - 1000, s);
                     if (position[0].Profit > 0){
                     s=s-1;
                     }else{
                     s=s+1;
                    } 
                 }

                }
                if (position[0].Type) {
                  if(position[0].Profit > l*s || position[0].Profit < (20-l)*s){                      
                       exchange.SetContractType(Symbol);
                        exchange.SetDirection("closesell_today");
                        exchange.Buy(ticker.Buy + 1000, s);
                       if (position[0].Profit > 0){
                     s=s-1;
                     }else{
                     s=s+1;
                    } 
                }
                 
                }



            } else if( !(orders.size() > 0)) {
                auto position1 = exchange.GetPosition();
                if (!(position1.size() > 0)){
                if (i==0) {
                    exchange.SetContractType(Symbol);
                    exchange.SetDirection("sell");
                  exchange.Sell(ticker.Sell - 1000, s);
                    i=1;
                    continue;
                } else if (i==1) {
                    exchange.SetContractType(Symbol);
                    exchange.SetDirection("buy");
                  exchange.Buy(ticker.Buy + 1000, s);
                   i=0;
                    continue;
                }
                }
            }
        } else {
            LogStatus(_D(), "未连接CTP !");
            Sleep(1000);
        }
      
    }
}

相关内容

更多内容