webull icon indicating copy to clipboard operation
webull copied to clipboard

Modifying Existing STP Order

Open dubleigh opened this issue 4 years ago • 8 comments

Hello,

When modifying a STP order, by adjusting the price input, I get an error. Below is the print out of my variables along with the response from webull:

WEBULL: Modifying order_id: 525616357736200192, stock: EPM, price: 4.5, action: SELL, orderType: STP, enforce: GTC, quant: 14, outsideRegularTradingHour: True { 'code': 'trade.webull.SYSTEM_INTERNAL_ERROR', 'data': {}, 'msg': 'Inner server error', 'success': False, 'traceId': '3GHU1LBISTP32PDBREVMJTVRDB'}

Below is the corresponding code:

order_id = 525616357736200192 stock = 'EPM' price = 4.600 action = 'SELL' orderType = 'STP' enforce = 'GTC' quant = 14 outsideRegularTradingHour = True

print(f'WEBULL: Modifying order_id: {order_id}, stock: {stock}, price: {price}, action: {action}, orderType: {orderType}, enforce: {enforce}, quant: {quant}, outsideRegularTradingHour: {outsideRegularTradingHour}')

result = wb.modify_order(order_id=order_id, stock=stock, price=price, action=action,
                        orderType=orderType, enforce=enforce, quant=quant, outsideRegularTradingHour=outsideRegularTradingHour)
pp.pprint(result)

Would you mind taking a look to see what I am doing wrong? Thank you!

dubleigh avatar Jan 04 '22 16:01 dubleigh

Hello TedChou12

Some background on the issue:

  • I place an OTOCO stop-loss/take-profit order -> the order is accepted/position entered
  • I then attempt to modify the price of the stop-loss during trading hours using 'modify order' and get the previous 'inner server error'

The code works if 'STP' is changed to 'LMT', however this converts the stop-loss into a limit order

Thank you!

dubleigh avatar Jan 05 '22 06:01 dubleigh

Hello,

Looks like the error might be related to needing a new function for modifying combo orders?

Screenshot from 2022-01-05 22-50-33

Screenshot from 2022-01-05 22-51-38

dubleigh avatar Jan 06 '22 06:01 dubleigh

thanks! Let me take a look! 🙏🙏🙏

tedchou12 avatar Jan 06 '22 09:01 tedchou12

@dubleigh Sorry for the delay, did you use the modify_order_otoco ? Does it not work?

tedchou12 avatar Feb 01 '22 13:02 tedchou12

Hello Ted, I will need to check that function again. Last time I remember using it, it worked for open orders that had not yet been placed as I was able to provide all of the information for the function. For placed orders, how would I handle the "order_id1" and "price" fields? Would I only provide information for the one order that will be modified? Thank you!

modify_order_otoco(self, order_id1='', order_id2='', order_id3='', stock='', price='', stop_loss_price='', limit_profit_price='', time_in_force='DAY', quant=0)

dubleigh avatar Feb 05 '22 18:02 dubleigh

Hello Ted,

I am testing out using the modify_order_otoco command for an OTOCO order that has already been executed (the master order has turned into a position) and i am still getting errors. I am uncertain what to enter for the master order, as this is not really an order anymore, but a position where I cannot control the price.

Code:

  # Stock Info:
  stock = 'ATEN'
  time_in_force = 'GTC'
  quant = 16
  # Master Order:
  order_id1 = 548446791318669312
  price = 13.02
  # Stop loss:
  order_id2 = 548446789645137920
  stop_loss_price = 12.15
  # Take Profit:
  order_id3 = 548446789649332224
  limit_profit_price = 15.00

  result = wb.modify_order_otoco(order_id1=order_id1, order_id2=order_id2, order_id3=order_id3, stock=stock, price=price,
                           stop_loss_price=stop_loss_price, limit_profit_price=limit_profit_price, time_in_force=time_in_force, quant=quant)
  pp.pprint(result)

Results in:

{ 'code': '500', 'msg': '', 'success': False, 'traceId': '7e99abff01304ec2b0cb5205610d16c2'}

When substituting the comboId (RVHG1M8H8JH668VE2SOJ228V4A) for any of the orderId's I get the following error:

{ 'code': '400', 'msg': 'JSON parse error: Cannot deserialize value of type ' 'java.lang.Long from String "RVHG1M8H8JH668VE2SOJ228V4A": not a ' 'valid Long value; nested exception is ' 'com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot ' 'deserialize value of type java.lang.Long from String ' '"RVHG1M8H8JH668VE2SOJ228V4A": not a valid Long value\n' ' at [Source: (PushbackInputStream); line: 1, column: 619] (through ' 'reference chain: ' 'com.webull.trade.api.v2.model.order.ComboOrderRequest["modifyOrders"]->java.util.ArrayList[2]->com.webull.trade.api.model.order.ReqPlaceOrder["orderId"])', 'success': False, 'traceId': 'a7025ff8b60c402a94e6811835b1bb66'}

Do you think this modify_order_otoco command is supposed to work for open orders only? (where all three orders are open and not when the master order has been exercised and is now a position)

Thank you!

dubleigh avatar Mar 05 '22 20:03 dubleigh

It seems as if the modify_order_otoco from the API requires three groups of data under 'modifyOrders' (master order, stop loss, take profit) whereas the screen capture from the webull website above only requires two fields (stop loss, take profit). My initial thought is that an additional command is needed for managing the existing open orders once the original master order is executed and turned into a position. This additional command only has fields for the remaining open orders and omits the original master order details.

image

dubleigh avatar Mar 05 '22 20:03 dubleigh

It seems as if the modify_order_otoco from the API requires three groups of data under 'modifyOrders' (master order, stop loss, take profit) whereas the screen capture from the webull website above only requires two fields (stop loss, take profit). My initial thought is that an additional command is needed for managing the existing open orders once the original master order is executed and turned into a position. This additional command only has fields for the remaining open orders and omits the original master order details.

image

cc: @tedchou12 @dubleigh , were you able to get to the bottom of this?

Essentially what i'm trying to do is -

  1. split up an existing otoco order into 2 from the same position
  2. or cancel otoco order on an existing position entirely.

Biletnikoff avatar May 06 '23 20:05 Biletnikoff