Fortex 6 and AlgoX Community

Fortex Product Support and Trader Community Forums

Problem with AlgoX

Technical support and trader community for AlgoX

Problem with AlgoX

Postby pradafx » Thu Jun 18, 2015 4:13 am

WE ONLY SENT MARKET ORDERS TODAY. WE HAVE NOT SENT ANY LIMIT ORDERS.

All the ORDERS – all going in as limit orders which means that they could linger. If a position should be closed and it is not it will try and try again. This could be generating Limit orders that are just hanging around for the next time the market passes through. ( I am guessing that this is the cause of the open/close open/close but I am certain of the fact that they are limits and not all being processed as I actually manually cancelled one so my guess may be correct.). I am using the proper api calls and even getting the response back that I sent a market or position close so there is not an issue with me sending the wrong type of order.
pradafx
 
Posts: 3
Joined: Thu Jun 18, 2015 4:06 am

Re: Problem with AlgoX

Postby Fortex_Henry » Thu Jun 18, 2015 4:17 am

The Sell order is entered as Market Order and the Buy order was entered as Limit order.
Fortex_Henry
 
Posts: 3
Joined: Thu Jun 18, 2015 4:16 am

Re: Problem with AlgoX

Postby pradafx » Thu Jun 18, 2015 4:18 am

I am actually a bit more perplexed as I did not have any orders that showed filled that were of the type market. Every fill I received via api query (I literally just used the sample code) had the type of limit and while all the quantities were positive (which in a cash account would imply a buy).

So something does not add up or something is not being processed properly as that would meant that somehow the position closes are being turned into limit orders without a limit price, as well as the BuyMarket() call is not being handled properly.



Since we all agree that we should not be 4.2Mil long with only opening orders then in some cases the filled orders were sell orders (either position closes for long positions or position establishing/additive sell orders - (I only differentiate as I use the separate api call for closing a position). I am only going through this because via Order Manager query in the api I only got back positive quantity Limit orders for any type of order I sent when queried– which would hopefully help troubleshoot.



Also, I do not pass a price in an of the api calls so somehow you are accepting a limit order without a limit price which suggests that there would hopefully be a setting default somewhere (i.e. to offset a price from the Bid/Ask for those cases when there was no price provided for a price dependent order).
pradafx
 
Posts: 3
Joined: Thu Jun 18, 2015 4:06 am

Re: Problem with AlgoX

Postby Fortex_Henry » Thu Jun 18, 2015 4:20 am

1- Reformatting your script:



private OrderRequest request = new OrderRequest();

private Asset asset;



-- open



if(processSignals== true){

request.BuyMarket(QuantityPerSignal);

}

API.Sleep(30000);

if(processSignals == true ){

request.SellMarket(QuantityPerSignal);

}



-- Close



asset.ClosePosition();

API.Sleep(60000);





2- From the script you sent, you use BuyMarket or SellMarket to open and use asset.ClosePosition() to close.



It is true that when you call BuyMarket and SellMarket, the order is sent as market order.

However, when you call Asset.ClosePosition(), the system sends a limit order.



3- Re your confusion of order type for executions:



When a order is filled (executed), the order Type is irrelevant since an execution does not have an order type.

The reason you see from the API print out as you sent below is due to the AlgoX engine assigns a default value of “Limit” to any order object.

Please ignore the order type value for FilledOrders for now.
Fortex_Henry
 
Posts: 3
Joined: Thu Jun 18, 2015 4:16 am

Re: Problem with AlgoX

Postby pradafx » Thu Jun 18, 2015 4:21 am

Just to clarify the suggestion ... you suggested to reformat to using buy and sell market to open and asset.close to close but since that is exactly what i sent i would assume you mean to NOT use the asset.close call???? The reason is that the closeposition () method as it sends a limit order. Instead specify the opposite call directly i.e. to close a short use BuyMarket () and to close a Long use SellMarket (). Is that correct?





It is a peculiar issue that any closing call would default to a limit order, however assuming that is the case then would closing a long issue a sell limit?



On a side note sine your api docs are a bit limited. If that sends a limit without any paras then: How do you set defaults for the TIF? Specify the decay time, since there is no price is passed how is the limit price determined? Is there a way to set the benchmark price and a slippage?
pradafx
 
Posts: 3
Joined: Thu Jun 18, 2015 4:06 am

Re: Problem with AlgoX

Postby Fortex_Henry » Thu Jun 18, 2015 4:22 am

RE asset.ClosePosition():



1- ClosePosition() API only sends out Limit Order using the prevailing quote as the limit price. If the position is long, it sells at the bid and vice versa.

You can set TIF before calling asset.ClosePosition by using setDefaultExpiry(sExpiry). This is a global setting, you may want to change it back to GTC before you call SellMarket() or BuyMarket(). We don’t recommend using FOK or IOC for market orders. It is possible that the xBook Matching Engine rejects a market order after the LP rejects some attempts. GTC market order will keep trying until the order gets filled.


2- Alternatively, if you don’t want to use limit order to close a position, you can use buymarket() or sellmarket() to close a position. Some sample code is as follows, please test thoroughly and use your own discretion if you want to use market orders:



--- to close a position using market order



var isSend = false;



function OnInit() {

EnableTrading();

}

function OnTick(){

if (! isSend) {

if (! isHistoryBar()) {

var objAcc = getCurrentAccount();

var objAsset = objAcc.getAssetBySymbolName(“EUR/USD");

var qty = objAsset.getPosition();



if(qty == 0){

isSend = false;

}

else{

if(qty > 0){

sellMarket(qty);

}else if (qty < 0){

buyMarket(-qty);

}

isSend = true;

}

}

}

}
Fortex_Henry
 
Posts: 3
Joined: Thu Jun 18, 2015 4:16 am


Return to “%s” AlgoX

cron