How to modify Market Order and Entry Order?

Moderator: admin

How to modify Market Order and Entry Order?

Postby 215607364@qq.com » Mon Oct 11, 2010 11:13 pm

how to modify Market Order's Stop price and Limit price more than two times?
how to modify Entry Order's Open price and Stop price and Limit price more than two times?

"Create a Limit Order" can change a Market Order's or Entry Order's Limit price for first times only,but I want to usd "Create a Limit Order" change the Limit price again failed。

"Edit Order" can change a Entry Order's Open price,but it also clear the Order's QTXT.It's very bad!
215607364@qq.com
 
Posts: 13
Joined: Mon Oct 11, 2010 9:56 pm

Re: How to modify Market Order and Entry Order?

Postby Nikolay.Gekht » Mon Oct 11, 2010 11:45 pm

This problem is in the server part of the system, so it is common for almost all APIs, for example for Order2Go. When "editorder" command is sent to the server, the server sends an update of the order changed with QTXT field which isn't filled. However, QTXT remains on the server side and is populated to trades and closed trades, as well as is sent correctly when the orders table is refreshed.

I notified the server side team and do all my best to have it fixed. Unfortunately I'm not in charge of this team (unlike O2GO or Marketscope teams), so I just cannot provide any estimation yet.
Nikolay.Gekht
FXCodeBase: Site Admin
 
Posts: 1235
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Re: How to modify Market Order and Entry Order?

Postby 215607364@qq.com » Tue Oct 12, 2010 2:06 am

thank you!
215607364@qq.com
 
Posts: 13
Joined: Mon Oct 11, 2010 9:56 pm

Re: How to modify Market Order and Entry Order?

Postby Nikolay.Gekht » Wed Oct 20, 2010 7:35 am

The problem is reported as fixed. AFAIK on demo servers the update is installed. So, we can expect it on real servers in a couple of weeks.
Nikolay.Gekht
FXCodeBase: Site Admin
 
Posts: 1235
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Re: How to modify Market Order and Entry Order?

Postby Nikolay.Gekht » Mon Dec 20, 2010 5:56 pm

Just for reference:

Please find the code of the strategies which can be used as "pattern" how to change order and which demonstrates that the current production release (1.09.101210) and the current servers works properly:

Create entry order 100 pips far from the market and then change it 20 times by 10 pips
Code: Select all
function Init()
    strategy:name("TEST EDIT 1");
    strategy:description("");

    strategy.parameters:addString("ACCOUNT", "Account", "", "");
    strategy.parameters:setFlag("ACCOUNT", core.FLAG_ACCOUNT);
end

local offer, amount;
local step = 0;
local tradid;
local rate = nil;
local orderid = nil;
local requestid = nil;
local ti;

function Prepare(onlyName)
    instance:name(profile:id());

    offer = core.host:findTable("offers"):find("Instrument", instance.bid:instrument()).OfferID;
    amount = core.host:execute("getTradingProperty", "baseUnitSize", instance.bid:instrument(), instance.parameters.ACCOUNT);
    canclose = core.host:execute("getTradingProperty", "canCreateMarketClose", instance.bid:instrument(), instance.parameters.ACCOUNT);
    ti = core.host:execute("setTimer", 1, 1);
end

function Update()
    local valuemap, success, msg;
    if step == 0 then
        -- create order initially
        valuemap = core.valuemap();
        valuemap.Command = "CreateOrder";
        valuemap.OrderType = "LE";
        valuemap.OfferID = offer;
        valuemap.AcctID = instance.parameters.ACCOUNT;
        valuemap.Quantity = amount;
        valuemap.BuySell = "S";
        valuemap.Rate = instance.bid[NOW] + 100 * instance.bid:pipSize();
        rate = instance.bid[NOW] + 100 * instance.bid:pipSize();
        valuemap.CustomID = "MYID";
        success, msg = terminal:execute(100, valuemap);
        assert(success, msg);
        step = 1;
        core.host:trace("order request id " .. msg);
        return ;
    end

    if step > 0 and step <= 20 then
        local enum, row, found;
        enum = core.host:findTable("orders"):enumerator();
        found = false;
        while not found do
            row = enum:next();
            if row == nil then
                break;
            end
            if row.QTXT == "MYID" then
                if orderid == nil then
                    orderid = row.OrderID;
                    core.host:trace("order id " .. orderid);
                end
                found = true;
                if math.abs(row.Rate - rate) < 0.00001 then
                    rate = rate + 10 * instance.bid:pipSize();

                    valuemap = core.valuemap();
                    valuemap.Command = "EditOrder";
                    valuemap.OfferID = offer;
                    valuemap.AcctID = instance.parameters.ACCOUNT;
                    valuemap.OrderID = row.OrderID;
                    valuemap.Rate = rate;
                    success, msg = terminal:execute(100, valuemap);
                    assert(success, msg);
                    core.host:trace("change rate to " .. rate);
                    step = step + 1;
                end
            end
        end

        if not found and orderid ~= nil then
            enum:reset();
            while not found do
                row = enum:next();
                if row == nil then
                    break;
                end
                if row.OrderID == orderid then
                    if row.QTXT ~= nil then
                        core.host:trace("order custom id is " .. row.QTXT);
                    else
                        core.host:trace("order custom id is nil");
                    end
                    step = 21;
                end
            end
        end
        return ;
    end
    if step > 20 then
        if ti ~= nil then
            core.host:execute("killTimer", ti);
            ti = nil;
        end
    end
end

function AsyncOperationFinished(cookie, successful, message)
    if (cookie == 1) then
        Update();
    elseif cookie == 100 then
        if not successful then
            assert(successful, message);
            return;
        end
    end
end


Create entry order 100 pips far from the market with +/-50 pips stop/limit and then change all three orders 20 times by 10 pips
Code: Select all
function Init()
    strategy:name("TEST EDIT 1");
    strategy:description("");

    strategy.parameters:addString("ACCOUNT", "Account", "", "");
    strategy.parameters:setFlag("ACCOUNT", core.FLAG_ACCOUNT);
end

local offer, amount;
local step = 0;
local tradid;
local rate = nil;
local orderid = nil;
local stopid = nil;
local limitid = nil;
local requestid = nil;
local ti;

function Prepare(onlyName)
    instance:name(profile:id());

    offer = core.host:findTable("offers"):find("Instrument", instance.bid:instrument()).OfferID;
    amount = core.host:execute("getTradingProperty", "baseUnitSize", instance.bid:instrument(), instance.parameters.ACCOUNT);
    canclose = core.host:execute("getTradingProperty", "canCreateMarketClose", instance.bid:instrument(), instance.parameters.ACCOUNT);
    ti = core.host:execute("setTimer", 1, 1);
end

function Update()
    local valuemap, success, msg;
    if step == 0 then
        -- create order initially
        valuemap = core.valuemap();
        valuemap.Command = "CreateOrder";
        valuemap.OrderType = "LE";
        valuemap.OfferID = offer;
        valuemap.AcctID = instance.parameters.ACCOUNT;
        valuemap.Quantity = amount;
        valuemap.BuySell = "S";
        valuemap.Rate = instance.bid[NOW] + 100 * instance.bid:pipSize();
        rate = instance.bid[NOW] + 100 * instance.bid:pipSize();
        valuemap.RateStop = rate + 50 * instance.bid:pipSize();
        valuemap.RateLimit = rate - 50 * instance.bid:pipSize();
        valuemap.CustomID = "MYID";
        success, msg = terminal:execute(100, valuemap);
        assert(success, msg);
        step = 1;
        core.host:trace("order request id " .. msg);
        return ;
    end

    if step > 0 and step <= 20 then
        local enum, row, found;
        enum = core.host:findTable("orders"):enumerator();
        found = false;
        while true do
            row = enum:next();
            if row == nil then
                break;
            end
            if row.QTXT == "MYID" then
                if orderid == nil then
                    orderid = row.OrderID;
                    stopid = row.StopOrderID;
                    limitid = row.LimitOrderID;
                    core.host:trace("order id " .. orderid);
                end
                found = true;
                if math.abs(row.Rate - rate) < 0.00001 then
                    rate = rate + 10 * instance.bid:pipSize();

                    valuemap = core.valuemap();
                    valuemap.Command = "EditOrder";
                    valuemap.OfferID = offer;
                    valuemap.AcctID = instance.parameters.ACCOUNT;
                    valuemap.OrderID = row.OrderID;
                    valuemap.Rate = rate;
                    success, msg = terminal:execute(100, valuemap);
                    assert(success, msg);
                   
                    core.host:trace("change rate to " .. rate);
                    valuemap = core.valuemap();
                    valuemap.Command = "EditOrder";
                    valuemap.OfferID = offer;
                    valuemap.AcctID = instance.parameters.ACCOUNT;
                    valuemap.OrderID = row.StopOrderID;
                    valuemap.Rate = rate + 50 * instance.bid:pipSize();
                    success, msg = terminal:execute(100, valuemap);
                    assert(success, msg);
               
                    valuemap = core.valuemap();
                    valuemap.Command = "EditOrder";
                    valuemap.OfferID = offer;
                    valuemap.AcctID = instance.parameters.ACCOUNT;
                    valuemap.OrderID = row.LimitOrderID;
                    valuemap.Rate = rate - 50 * instance.bid:pipSize();
                    success, msg = terminal:execute(100, valuemap);
                    assert(success, msg);
                    step = step + 1;
                end
            end

            if row.OrderID == stopid and row.QTXT ~= "MYID" then   
                core.host:trace("Lost stop custom id");
            end
            if row.OrderID == limitid and row.QTXT ~= "MYID" then   
                core.host:trace("Lost limit custom id");
            end
        end

        if not found and orderid ~= nil then
            enum:reset();
            while not found do
                row = enum:next();
                if row == nil then
                    break;
                end
                if row.OrderID == orderid then
                    if row.QTXT ~= nil then
                        core.host:trace("order custom id is " .. row.QTXT);
                    else
                        core.host:trace("order custom id is nil");
                    end
                    step = 21;
                end
            end
        end
        return ;
    end
    if step > 20 then
        if ti ~= nil then
            core.host:execute("killTimer", ti);
            ti = nil;
        end
    end
end

function AsyncOperationFinished(cookie, successful, message)
    if (cookie == 1) then
        Update();
    elseif cookie == 100 then
        if not successful then
            assert(successful, message);
            return;
        end
    end
end


Nikolay.Gekht
FXCodeBase: Site Admin
 
Posts: 1235
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC


Return to Indicator Development

Who is online

Users browsing this forum: No registered users and 43 guests