Create position but rejected

5 posts / 0 new
Last post
Marvin
Create position but rejected

I am using Java to create an "buy" position purposely with lower price than current bid price.

then it is “rejected" with
reason:"LIMIT_ORDER_WRONG_SIDE_OF_MARKET".

If I put higher price for buy , then it is ok.

Could someone advise ?

thank you !

ElephantFlea
Limit Order Rejected

Can you give more details? What specific values were you using, endpoint, Symbol, date/time etc. Does it happen all the time, or just sometimes etc.

Marvin
I modified the java example

I modified the java example program provided by IG. take below for example: Some message is printed from my Java program.

1> got the current Market price for HANGSENG, print

IX.D.HANGSENG.IGT.IP Market Price offer is 27637.5 and Bid is 27642.5

2> I end "BUY" order at such price 27637.5 with size 2 ( for below case, printing)

>>> Creating long position epic=IX.D.HANGSENG.IGT.IP, expiry=- size=2 orderType=LIMIT level=27637.5 currency=HKD

3> the "TradeUpdate" will inform the error as below:

Trade confirm update i 1 s TRADE:XX9ZF data [ {"direction":"BUY","epic":"IX.D.HANGSENG.IGT.IP","stopLevel":null,"limitLevel":null,"dealReference":"ETGVPZVH7GH44TP","dealId":"DIAAAAC3PGZEGBD","limitDistance":null,"stopDistance":null,"expiry":null,"affectedDeals":[],"dealStatus":"REJECTED","guaranteedStop":false,"trailingStop":false,"level":null,"reason":"LIMIT_ORDER_WRONG_SIDE_OF_MARKET","status":null,"size":null,"profit":null,"profitCurrency":null,"date":"2019-11-05T07:22:20.34","channel":"PublicRestOTC"} ]
Trade confirm order update i 1 s TRADE:XX9ZF data [ {"direction":"BUY","epic":"IX.D.HANGSENG.IGT.IP","stopLevel":null,"limitLevel":null,"dealReference":"ETGVPZVH7GH44TP","dealId":"DIAAAAC3PGZEGBD","limitDistance":null,"stopDistance":null,"expiry":null,"affectedDeals":[],"dealStatus":"REJECTED","guaranteedStop":false,"trailingStop":false,"level":null,"reason":"LIMIT_ORDER_WRONG_SIDE_OF_MARKET","status":null,"size":null,"profit":null,"profitCurrency":null,"date":"2019-11-05T07:22:20.34","channel":"PublicRestOTC"} ]

5> if I "Buy" at purposely very high price , like 2770, shown as below:

>>> Creating long position epic=IX.D.HANGSENG.IGT.IP, expiry=- size=2 orderType=LIMIT level=27700 currency=HKD

then it will be successful

Trade confirm update i 1 s TRADE:XX9ZF data [ {"direction":"BUY","epic":"IX.D.HANGSENG.IGT.IP","stopLevel":null,"limitLevel":null,"dealReference":"RA5EMXFP2V744TD","dealId":"DIAAAAC3PHH7KAW","limitDistance":null,"stopDistance":null,"expiry":"-","affectedDeals":[{"dealId":"DIAAAAC3PHH7KAW","status":"OPENED"}],"dealStatus":"ACCEPTED","guaranteedStop":false,"trailingStop":false,"level":27669.5,"reason":"SUCCESS","status":"OPEN","size":2,"profit":null,"profitCurrency":null,"date":"2019-11-05T07:31:42.11","channel":"PublicRestOTC"} ]
Trade confirm order update i 1 s TRADE:XX9ZF data [ {"direction":"BUY","epic":"IX.D.HANGSENG.IGT.IP","stopLevel":null,"limitLevel":null,"dealReference":"RA5EMXFP2V744TD","dealId":"DIAAAAC3PHH7KAW","limitDistance":null,"stopDistance":null,"expiry":"-","affectedDeals":[{"dealId":"DIAAAAC3PHH7KAW","status":"OPENED"}],"dealStatus":"ACCEPTED","guaranteedStop":false,"trailingStop":false,"level":27669.5,"reason":"SUCCESS","status":"OPEN","size":2,"profit":null,"profitCurrency":null,"date":"2019-11-05T07:31:42.11","channel":"PublicRestOTC"} ]

Position update i 1 s TRADE:XX9ZF data [ {"dealReference":"RA5EMXFP2V744TD","dealId":"DIAAAAC3PHH7KAW","direction":"BUY","epic":"IX.D.HANGSENG.IGT.IP","status":"OPEN","dealStatus":"ACCEPTED","level":27669.5,"size":2,"timestamp":"2019-11-05T07:31:42.000","channel":"PublicRestOTC","dealIdOrigin":"DIAAAAC3PHH7KAW","expiry":"-","stopLevel":null,"limitLevel":null,"guaranteedStop":false} ]
Position update i 1 s TRADE:XX9ZF data [ {"dealReference":"RA5EMXFP2V744TD","dealId":"DIAAAAC3PHH7KAW","direction":"BUY","epic":"IX.D.HANGSENG.IGT.IP","status":"OPEN","dealStatus":"ACCEPTED","level":27669.5,"size":2,"timestamp":"2019-11-05T07:31:42.000","channel":"PublicRestOTC","dealIdOrigin":"DIAAAAC3PHH7KAW","expiry":"-","stopLevel":null,"limitLevel":null,"guaranteedStop":false} ]

-----------------------------------------------------------------------------------

What I expect : I should be able to put a "BUY" position with Lower price and wait for the "lucky" to get trade. but It will show the error of above unexpected. ("LIMIT_ORDER_WRONG_SIDE_OF_MARKET")

--------------------------------------------------------------------------------------------
Below are the java program for "CreatePostion", which I modified from origianl IG example.

public void createPosition(String epic,Direction action, double level, double size ) throws Exception {
if (epic != null) {
GetMarketDetailsV2Response marketDetails = restApi.getMarketDetailsV2(authenticationContext.getConversationContext(), epic);
CreateOTCPositionV1Request createPositionRequest = new CreateOTCPositionV1Request();
createPositionRequest.setEpic(epic);
createPositionRequest.setExpiry(marketDetails.getInstrument().getExpiry());
// createPositionRequest.setDirection(Direction.BUY);
createPositionRequest.setDirection(action);
LOG.info("--HX> Epic={} Direction={}",epic, action) ;
LOG.info("--HX> test marketDetails.getSnapshot().getOffer()={} getBid={}",marketDetails.getSnapshot().getOffer(),marketDetails.getSnapshot().getBid()) ;
LOG.info("--HX> createPosition>it usess LIMIT Order") ;
createPositionRequest.setOrderType(OrderType.LIMIT);
// createPositionRequest.setLevel(marketDetails.getSnapshot().getOffer());
createPositionRequest.setLevel( BigDecimal.valueOf(level));
LOG.info("--HX> createPosition>LIMIT Order done");
/*
if(marketDetails.getDealingRules().getMarketOrderPreference() != MarketOrderPreference.NOT_AVAILABLE) {
LOG.info("--HX> createPosition>it uses MARKET Order") ;
createPositionRequest.setOrderType(OrderType.MARKET);
} else {
LOG.info("--HX> createPosition>it usess LIMIT Order") ;
createPositionRequest.setOrderType(OrderType.LIMIT);
createPositionRequest.setLevel(marketDetails.getSnapshot().getOffer());
LOG.info("--HX> createPosition>LIMIT Order done");
}
*/
List currencies = marketDetails.getInstrument().getCurrencies();
createPositionRequest.setCurrencyCode(currencies.size() > 0 ? currencies.get(0).getCode() : "GBP");
// createPositionRequest.setSize(BigDecimal.valueOf(marketDetails.getDealingRules().getMinDealSize().getValue()));
createPositionRequest.setSize(BigDecimal.valueOf(size));
createPositionRequest.setGuaranteedStop(false);
createPositionRequest.setForceOpen(true);

//LOG.info(">>> Creating long position epic={}, expiry={} size={} orderType={} level={} currency={}", tradeableEpic, createPositionRequest.getExpiry(),
// createPositionRequest.getSize(), createPositionRequest.getOrderType(), createPositionRequest.getLevel(), createPositionRequest.getCurrencyCode());
LOG.info(">>> Creating long position epic={}, expiry={} size={} orderType={} level={} currency={}", epic, createPositionRequest.getExpiry(),
createPositionRequest.getSize(), createPositionRequest.getOrderType(), createPositionRequest.getLevel(), createPositionRequest.getCurrencyCode());
restApi.createOTCPositionV1(authenticationContext.getConversationContext(), createPositionRequest);
// LOG.info("--HX> createPosition> createOTCPositionV1 done !") ;
}

Could you take a look and help

thank you !

ElephantFlea
Limit Order Rejected

I'm sorry this is a quick-fire response as I'm on a small screen and I've only got a few seconds. I've not studied in depth your program.

Is it possible that you're getting confused between resting orders and immediate orders? Take a look at this page and see if that clarifies it for you...
https://labs.ig.com/apiorders

Flea

Marvin
1> Thanks ElephantFlea, think

1> Thanks ElephantFlea, think you catch my problem.

2> Likely I have been using a "Immediate order types" , which given by the example.
( "createPositionRequest.setOrderType(OrderType.LIMIT);" , looks using the LIMIT type under "Immediate order types")

3> But I do want to use the "Resting orders" , just put a price and waiting, as most people do , what should I do in java ?

thank you !

Log in or register to post comments