Jump to content
  • 0

Java REST API close postion problem


Guest Sideshow

Question

Guest Sideshow

Hi,

 

I am using the Java REST API, and have created an application using your ig-webapi-java-sample application as the basis of it. I am having trouble with closing an open position, so I hope someone can point out what I am doing wrong please!

 

I have created a working order as per the following code. It creates ok, and then as the price moves, becomes an open position:

 

GetMarketDetailsV2Response marketDetails = restApi.getMarketDetailsV2(authenticationContext.getConversationContext(), getTradeableEpic());

CreateOTCWorkingOrderV2Request createWorkingOrderRequest = new CreateOTCWorkingOrderV2Request();

createWorkingOrderRequest.setEpic(getTradeableEpic());

createWorkingOrderRequest.setExpiry(marketDetails.getInstrument().getExpiry());

createWorkingOrderRequest.setDirection(direction);

List<CurrenciesItem> currencies = marketDetails.getInstrument().getCurrencies();

createWorkingOrderRequest.setCurrencyCode(currencies.size() > 0 ? currencies.get(0).getCode() : "GBP");

createWorkingOrderRequest.setSize(BigDecimal.valueOf(event.getForexPair().getMinimumSize()));

createWorkingOrderRequest.setGuaranteedStop(false);

createWorkingOrderRequest.setForceOpen(true);

createWorkingOrderRequest.setTimeInForce(TimeInForce.GOOD_TILL_CANCELLED);

createWorkingOrderRequest.setGoodTillDate(null);

// createWorkingOrderRequest.setStopLevel(stopLevel);

createWorkingOrderRequest.setStopDistance(null);

createWorkingOrderRequest.setLimitLevel(null);

createWorkingOrderRequest.setLimitDistance(null);

createWorkingOrderRequest.setType(Type.STOP);

createWorkingOrderRequest.setLevel(level);

restApi.createOTCWorkingOrderV2(authenticationContext.getConversationContext(), createWorkingOrderRequest);

 

 

Now when I try to close this open position, it fails. Here is my code:

 

GetMarketDetailsV2Response marketDetails = restApi.getMarketDetailsV2(authenticationContext.getConversationContext(), getTradeableEpic());

CloseOTCPositionV1Request closePositionRequest = new CloseOTCPositionV1Request();

closePositionRequest.setDealId(position.getDealId());

closePositionRequest.setEpic(getTradeableEpic());

closePositionRequest.setExpiry(marketDetails.getInstrument().getExpiry());

if(position.getDirection() == Direction.SELL) {

closePositionRequest.setDirection(com.iggroup.webapi.samples.client.rest.dto.positions.otc.closeOTCPositionV1.Direction.BUY);

}else {

closePositionRequest.setDirection(com.iggroup.webapi.samples.client.rest.dto.positions.otc.closeOTCPositionV1.Direction.SELL);

}

closePositionRequest.setSize(position.getSize());

closePositionRequest.setLevel(null);

closePositionRequest.setOrderType(OrderType.MARKET);

closePositionRequest.setTimeInForce(TimeInForce.EXECUTE_AND_ELIMINATE);

restApi.closeOTCPositionV1(authenticationContext.getConversationContext(), closePositionRequest);

 

 

This fails with

Delete failed: HTTP/1.1 400 Bad Request
java.lang.RuntimeException: Delete failed: HTTP/1.1 400 Bad Request
at com.iggroup.webapi.samples.client.RestAPI.closeOTCPositionV1(RestAPI.java:263)
at com.me.myapp.closePosition(Blah.java:93)

...

at com.me.myapp.closePositions(Foo.java:193)

at com.lightstreamer.ls_client.FullTableManager.processUpdate(FullTableManager.java:161)
at com.lightstreamer.ls_client.FullTableManager.doUpdate(FullTableManager.java:78)
at com.lightstreamer.ls_client.MyServerListener.onUpdate(MyServerListener.java:142)
at com.lightstreamer.ls_client.ServerManager.tableUpdate(ServerManager.java:1229)
at com.lightstreamer.ls_client.ServerManager.waitEvent(ServerManager.java:1298)
at com.lightstreamer.ls_client.ServerManager$SessionActivityManager.runEvent(ServerManager.java:238)
at com.lightstreamer.ls_client.ServerManager$SessionActivityManager.runSession(ServerManager.java:338)
at com.lightstreamer.ls_client.ServerManager$SessionActivityManager.access$300(ServerManager.java:194)
at com.lightstreamer.ls_client.ServerManager$SessionActivityManager$1.run(ServerManager.java:212)

 

 

Link to comment

1 answer to this question

Recommended Posts

Guest Sideshow

Problem solved, here's the answer:

 

GetMarketDetailsV2Response marketDetails = restApi.getMarketDetailsV2(authenticationContext.getConversationContext(), getTradeableEpic());
CloseOTCPositionV1Request closePositionRequest = new CloseOTCPositionV1Request();
closePositionRequest.setDealId(position.getDealId());
closePositionRequest.setExpiry(marketDetails.getInstrument().getExpiry());
if(position.getDirection() == Direction.SELL) {
closePositionRequest.setDirection(com.iggroup.webapi.samples.client.rest.dto.positions.otc.closeOTCPositionV1.Direction.BUY);
}else {
closePositionRequest.setDirection(com.iggroup.webapi.samples.client.rest.dto.positions.otc.closeOTCPositionV1.Direction.SELL);
}
closePositionRequest.setSize(position.getSize());
closePositionRequest.setOrderType(OrderType.MARKET);
CloseOTCPositionV1Response response = restApi.closeOTCPositionV1(authenticationContext.getConversationContext(), closePositionRequest);
closingDealReference = response.getDealReference();

Link to comment

Archived

This topic is now archived and is closed to further replies.

  • image.png

  • Posts

    • ARTFI's mission to make high-value art accessible through fractional ownership and NFTs is a fascinating concept. Let's explore other projects breaking down barriers in the art world and bringing ownership to the masses. ARTFI offers some unique features beyond just fractionalization: Focus on Blue-Chip Art, their concentration on established artists attracts high-net-worth collectors and increases investment potential. Industry Endorsements, supports from prominent figures adds credibility to the platform. So, is ARTFI your one-stop shop for owning a piece of an iconic painting because they are listed on Bitget? Maybe or maybe not. There are other options, and the art market itself is evolving alongside NFTs. What do you think? Is ARTFI a revolutionary force in art ownership, or just a trendy gimmick? Have you explored any other fractional ownership or art-related NFT projects? Share your thoughts in the comments!
    • Mystiko Network like competitors like Omni are promoting interoperability and scalability in the crypto landscape. However, Mystiko is standing out with seamless compatibility with various L1 and L2 blockchains which they have extended to cross-chain bridges, wallets, DEXs, and other dApps. By eliminating blockchain barriers, Mystiko Network allows users to transfer assets and interact with various dApps more easily. This focus on interoperability goes hand-in-hand with scalability. Plus, their ZK SDK allows developers to build secure and private dApps while reducing costs and simplifying cross-chain transactions. It has successfully raised $29.25 million and have forge backing from industry giants like Samsung Next, Coinlist, Hashkey Capital etc... emphasizes it potential and gives it a firm foothold in the interoperability niche. Mystiko is about to hit another milestone as their token XZK is about to be listed on a Tier1 CEX like Bitget further exposing it to investors! Overall, they are ticking the right boxes and I believe they are a project to watch!
×
×
  • Create New...
us