Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. public void sendOrder(String orderSide, int parentOrderId) {
  2. new Thread(() -> {
  3.  
  4. System.out.print("before getting ids, nextOrderID = " + nextOrderID + ", nextValidId_prev = " + nextValidId_prev);
  5. while (nextOrderID == nextValidId_prev) {
  6. System.out.print("waiting for next valid id...");
  7. client.reqIds(1);
  8. System.out.print("waiting for next valid id done");
  9. try {
  10. Thread.sleep(1000);
  11. } catch (InterruptedException e) {
  12. e.printStackTrace();
  13. }
  14. }
  15.  
  16. System.out.print("new nextOrderID = " + nextOrderID);
  17. nextValidId_prev = nextOrderID;
  18.  
  19. System.out.print("sendOrder is called");
  20.  
  21. Order order = new Order();
  22. order.action(orderSide);
  23. order.totalQuantity(20000);
  24.  
  25. //log.info("sendOrder, this.high = " + this.high);
  26.  
  27.  
  28. DecimalFormat df = new DecimalFormat("0.0000"); // TODO get digit according
  29. df.setDecimalSeparatorAlwaysShown(true);
  30. String formatedEntryPrice = df.format(this.high);
  31. formatedEntryPrice = formatedEntryPrice.replace(",", ".");
  32.  
  33. System.out.print("formatedEntryPrice = " + formatedEntryPrice);
  34. order.lmtPrice(Double.valueOf(formatedEntryPrice)); // TODO stop limit at prior day high
  35. order.orderType("LMT");
  36.  
  37. order.account(twsAccountNumber);
  38. //int randomNum = ThreadLocalRandom.current().nextInt(1, 5564 + 1);
  39. //log.info("after creating order");
  40.  
  41. String trailingOrderSide = "";
  42. if(orderSide.equals("SELL")){
  43. trailingOrderSide = "BUY";
  44. }else if(orderSide.equals("BUY")){
  45. trailingOrderSide = "SELL";
  46. }
  47.  
  48. Order trailOrder = new Order();
  49. trailOrder.action(trailingOrderSide);
  50. //trailOrder.auxPrice(Double.valueOf("1.07000"));
  51. trailOrder.trailingPercent(1);
  52. trailOrder.orderType("TRAIL");
  53. trailOrder.totalQuantity(20000);
  54. trailOrder.parentId(nextOrderID);
  55. trailOrder.transmit(true);
  56. ///
  57. // order.orderType("TRAIL");
  58. // order.totalQuantity(20000);
  59. // order.trailingPercent(1);
  60. // order.trailStopPrice(low);
  61. // stopLoss.parentId(nextOrderID);
  62. // order.transmit(true);
  63.  
  64. //client.reqIds(1);
  65.  
  66.  
  67. client.placeOrder(nextOrderID, contract, order);
  68. client.placeOrder(nextOrderID + 1, contract, trailOrder);
  69.  
  70. //attachOrder();
  71. }).start();
  72. System.out.print("sendOrder is finished");
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement