tedchou12 / webull

Unofficial APIs for Webull.
MIT License
597 stars 181 forks source link

Option Ask/Bid and Mid Price. #376

Open bigredkacy opened 1 year ago

bigredkacy commented 1 year ago

If you're looking to get the prices per contract for a particular derivative ID, you can use the endpoint.py file and add the following code:

def options_prices(self, derivativeIds): return f'{self.base_options_gw_url}/quote/option/quotes/queryBatch?derivativeIds={derivativeIds}'

Then, in your Webull.py file, add the following to call the function:

def get_options_prices(self, derivativeIds=None):
    if not derivativeIds:
        raise ValueError('Must provide a derivativeIds')
    headers = self.build_req_headers()
    response = requests.get(self._urls.options_prices(derivativeIds), headers=headers, timeout=self.timeout)

    if response.status_code != 200:
        raise Exception('get_options_prices failed', response.status_code, response.reason)
    return response.json()

To get the prices per contract, you can call the function by passing in the derivative ID, such as: wb.get_options_prices(ticker_id). The output will be a list of prices and other information related to the derivative ID.