Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify options order: #402

Open
M1NL1TE opened this issue Jun 6, 2023 · 5 comments
Open

Modify options order: #402

M1NL1TE opened this issue Jun 6, 2023 · 5 comments

Comments

@M1NL1TE
Copy link

M1NL1TE commented Jun 6, 2023

@michaelkkehoe @tedchou12 Have you been successful with a modify option order with the 'https://act.webullbroker.com/webull-paper-center/api/paper/v1/order/optionReplace' endpoint?

I keep getting this response: 2023-05-25 12:42:58,193 INFO b'{"msg":"orderId=null","traceId":"b7ef3d8e73a84dda9b3d8146e2024d20","code":"400","success":false}'

and this is the request: 2023-05-25 12:42:58,192 INFO b'{"oderId": 105353561, "orderType": "LMT", "accountId": 12345, "paperId": 1, "timeInForce": "GTC", "serialId": "XYZ", "orders": [{"quantity": 1, "action": "BUY", "tickerId": 1038356919, "tickerType": "OPTION", "orderId": 105353561}], "lmtPrice": 1.29}'

(intentionally omitted possibly sensitive info)

And here is how I implemented the modify order function in webull.py:
def modify_order_option(self, order=None, lmtPrice=None, stpPrice=None, enforce=None, quant=0):
'''
order: dict from get_current_orders
stpPrice: float
lmtPrice: float
enforce: GTC / DAY
quant: int
'''
headers = self.build_req_headers(include_trade_token=True, include_time=True)
data = {
'oderId': order[0]['orderId'],
'orderType': order[0]['orderType'],
'accountId': self._account_id,
'paperId': 1,
'timeInForce': enforce or order[0]['timeInForce'],
'serialId': str(uuid.uuid4()),
'orders': [{'quantity': quant or order[0]['totalQuantity'],
'action': order[0]['action'],
'tickerId': order[0]['ticker']['tickerId'],
'tickerType': 'OPTION',
'orderId': order[0]['orderId']}]
}

if order[0]['orderType'] == 'LMT' and (lmtPrice or order.get('lmtPrice')):
    data['lmtPrice'] = lmtPrice or order[0]['lmtPrice']
elif order[0]['orderType'] == 'STP' and (stpPrice or order.get('auxPrice')):
    data['auxPrice'] = stpPrice or order[0]['auxPrice']
elif order[0]['orderType'] == 'STP LMT' and (stpPrice or order.get('auxPrice')) and (lmtPrice or order.get('lmtPrice')):
    data['auxPrice'] = stpPrice or order[0]['auxPrice']
    data['lmtPrice'] = lmtPrice or order[0]['lmtPrice']

url = 'https://act.webullbroker.com/webull-paper-center/api/paper/v1/order/optionReplace'
response = requests.post(url, json=data, headers=headers, timeout=self.timeout)

logging.info(response.request.body)
logging.info(response.content)
if response.status_code != 200:
    raise Exception('replace_option_order failed', response.status_code, response.reason)
return True

The main change I made to the regular account modify_order_option was taking out the "'comboId': order['comboId']" line in the data dictionary as I don't see that in the list of "openOrders" for the paper account. It's somehow not accepting the orderId from the request and I'm not sure why.


Here are the API endpoints:

https://act.webullbroker.com/webull-paper-center/api/paper/v1/order/getOptionAccountDetailAndPosition
https://act.webullbroker.com/webull-paper-center/api/paper/v1/order/optionPlace
https://act.webullbroker.com/webull-paper-center/api/paper/v1/order/optionReplace

Here is an example function to place option orders:

    def place_order_option(self, optionId=None, lmtPrice=None, stpPrice=None, action=None, orderType='LMT', enforce='DAY', quant=0):
        '''
        create buy / sell order
        stock: string
        lmtPrice: float
        stpPrice: float
        action: string BUY / SELL
        optionId: string
        orderType: MKT / LMT / STP / STP LMT
        enforce: GTC / DAY
        quant: int
        '''
        headers = self.build_req_headers(include_trade_token=True, include_time=True)
        data = {
            'orderType': orderType,
            'serialId': str(uuid.uuid4()),
            'paperId': 1,
            'accountId': self._account_id,
            'tickerId': int(optionId),
            'quantity': int(quant),
            'action': "BUY",
            'timeInForce': enforce,
            'orders': [{'quantity': int(quant), 'action': action, 'tickerId': int(optionId), 'tickerType': 'OPTION'}],
        }

        if orderType == 'LMT' and lmtPrice :
            data['lmtPrice'] = float(lmtPrice)
        elif orderType == 'STP' and stpPrice :
            data['auxPrice'] = float(stpPrice)
        elif orderType == 'STP LMT' and lmtPrice and stpPrice :
            data['lmtPrice'] = float(lmtPrice)
            data['auxPrice'] = float(stpPrice)

        url = 'https://act.webullbroker.com/webull-paper-center/api/paper/v1/order/optionPlace'
        response = requests.post(url, json=data, headers=headers, timeout=self.timeout)
        if response.status_code != 200:
            raise Exception('place_option_order failed', response.status_code, response.reason)

Originally posted by @michaelkkehoe in #316 (comment)

@michaelkkehoe
Copy link

I haven't tried a modify order for paper options.

@M1NL1TE
Copy link
Author

M1NL1TE commented Jun 7, 2023

I haven't tried a modify order for paper options.

@michaelkkehoe May I ask how you found the endpoints for the modify options order and the other endpoints? Did you use something like wire shark or postman with the Webull desktop application? I've had difficulties with wire shark

@michaelkkehoe
Copy link

$ cd /usr/local/WebullDesktop
$ strings wbplugins/libtradestore.so | grep paper-center

@M1NL1TE
Copy link
Author

M1NL1TE commented Jun 29, 2023

$ cd /usr/local/WebullDesktop

$ strings wbplugins/libtradestore.so | grep paper-center

@michaelkkehoe
Sorry to bother you again but when I try that command in my visual studio code git bash command terminal on Windows 10, it doesn't recognize the command. I was wondering what OS are you running with what terminal and what packages or anything else I would need to make it work with that command. Here's an example of my terminal:
image

@michaelkkehoe
Copy link

@M1NL1TE It's a standard linux command. I found this using Webull Desktop application on my Ubuntu laptop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants