Getting quotes

wetrade provides a few different types of quotes for different trading needs. A Quote can be used to track an individual stock, while DataFrameQuote and MultiQuote have additional functionality for performing complex calculations and tracking multiple securities at once.

See below for examples on getting quotes with wetrade:

Example usage

After creating a new Quote, you can get detailed quotes or access just the opening or latest price. You can also the price updated throughout the day so that Quote().last_price always stays current.

import time
from wetrade.api import APIClient
from wetrade.quote import Quote


def main():
  my_api_client = APIClient()
  my_quote = Quote(client=my_api_client, symbol='IBM')
  # Get the most recent quote details
  quote = my_quote.get_quote()
  print(f'Quote details: {quote}')
  # Get the opening price or the last price
  open = my_quote.get_open()
  last_price = my_quote.get_last_price()
  print(f'Opening price: {open}; Last price:{last_price}')
  # Keep my_quote.last_price up to date
  my_quote.monitor_in_background()
  for i in range(5):
    print(f'Price {i+1}: {my_quote.last_price}')
    time.sleep(2)


if __name__ == '__main__':
  main()

Detailed usage

class wetrade.quote.Quote(client: APIClient, symbol)

A simple Quote for tracking one security

Parameters:
get_last_price()

Gets the most recent price for your security

get_open()

Returns the opening price for your security during the current session

get_options_chain(expiry_date='%Y-%m-%d', near_price=0.0, include_weekly=False, skip_adjusted=True)

Gets the options chain for your security

get_quote()

Gets the most recent quote details for your security

monitor_in_background()

Monitors quote details in a new thread to keep Quote.last_price up to date

run_above_price(target_price, func, func_args=[], func_kwargs={})

Runs a callback when your security rises above a certain price without waiting

Parameters:
  • target_price (float) – your set target price

  • func – a function to run when price rises above target

  • func_args (list) – a list of args for your func

  • func_kwargs (dict) – a dict containing kwargs for your func

run_below_price(target_price, func, func_args=[], func_kwargs={})

Runs a callback when your security falls below a certain price without waiting

Parameters:
  • target_price (float) – your set target price

  • func – a function to run when price falls below target

  • func_args (list) – a list of args for your func

  • func_kwargs (dict) – a dict containing kwargs for your func

wait_for_price_fall(target_price, then=None, args=[], kwargs={})

Waits for your security to fall below a certain price then optionally runs a callback function

Parameters:
  • target_price (float) – your set target price

  • then – (optional) a callback function to run when price falls below target

  • args (list) – a list of args for your func

  • kwargs (dict) – a dict containing kwargs for your func

wait_for_price_rise(target_price, then=None, args=[], kwargs={})

Waits for your security to rise above a certain price then optionally runs a callback function

Parameters:
  • target_price (float) – your set target price

  • then – (optional) a callback function to run when price rises above target

  • args (list) – a list of args for your func

  • kwargs (dict) – a dict containing kwargs for your func

class wetrade.quote.DataFrameQuote(client: APIClient, symbol)

A Quote that uses a DataFrame to keep track of quote details and enable complex calculations

Parameters:
export_data()

Exports a DataFrame containing your quote data as a .pkl file saved to ./export/data

get_pd_data()

Returns a pandas DataFrame containing your quote data

upload_quote_data()

Uploads a DataFrame to a Google Cloud Storage bucket specified in settings.py

class wetrade.quote.MultiQuote(client: APIClient, symbols: tuple)

An expanded Quote for tracking multiple securities

Parameters:
  • client (APIClient) – your APIClient

  • symbols (tuple) – a tuple containing a list of symbols for up to 25 securities

get_last_price()

Gets the most recent prices for all of your securities

get_quote()

Gets the most recent quote details for your securities

monitor_in_background()

Monitors quote details in a new thread to keep Quote.last_price up to date

run_above_price(symbol, target_price, func, func_args=[], func_kwargs={})

Runs a callback when a specified security rises above a certain price without waiting

Parameters:
  • symbol (str) – the symbol of your specified security

  • target_price (float) – your set target price

  • func – (optional) a callback function to run when price rises above target

  • func_args (list) – a list of args for your func

  • func_kwargs (dict) – a dict containing kwargs for your func

run_below_price(symbol, target_price, func, func_args=[], func_kwargs={})

Runs a callback when a specified security falls below a certain price without waiting

Parameters:
  • symbol (str) – the symbol of your specified security

  • target_price (float) – your set target price

  • func – (optional) a callback function to run when price falls below target

  • func_args (list) – a list of args for your func

  • func_kwargs (dict) – a dict containing kwargs for your func

wait_for_price_fall(symbol, target_price, then=None, args=[], kwargs={})

Waits for a specified security to fall below a certain price then optionally runs a callback function

Parameters:
  • symbol (str) – the symbol of your specified security

  • target_price (float) – your set target price

  • then – (optional) a callback function to run when price falls below target

  • args (list) – a list of args for your func

  • kwargs (dict) – a dict containing kwargs for your func

wait_for_price_rise(symbol, target_price, then=None, args=[], kwargs={})

Waits for a specified security to rise above a certain price then optionally runs a callback function

Parameters:
  • symbol (str) – the symbol of your specified security

  • target_price (float) – your set target price

  • then – (optional) a callback function to run when price rises above target

  • args (list) – a list of args for your func

  • kwargs (dict) – a dict containing kwargs for your func