Quotes

class ally.Ally(params=None, timeout: float = 1.0)

The ally.Ally.Ally class.

This is the main class for this library.

quote(symbols: list = [], fields: list = [], dataframe=True, block: bool = True)

Gets the most current market data on the price of a symbol.

Args:

symbols:

string or list of strings, each string a symbol to be queried. Notice symbols=[‘spy’], symbols=’spy both work

fields:

string or list of strings, each string a field to be grabbed. By default, get all fields

dataframe:

flag, specifies whether to return data in pandas dataframe or flat list of dictionaries.

block:

Specify whether to block thread if request exceeds rate limit

Returns:

Depends on dataframe flag. Will return pandas dataframe, or possibly list of dictionaries, each one a single quote.

Raises:

RateLimitException: If block=False, rate limit problems will be raised

Examples:

# Get the quotes in dataframe format
#  Each row will only have elements bid, ask, and last
quotes = a.quote(
        symbols=['spy','gLD','F','Ibm'], # not case sensitive
        fields=['bid','ask,'last'],
)
# Access a specific symbol by the dataframe
print(quotes.loc['SPY'])
# Get the quotes in dataframe format
quotes = a.quote(
        'AAPL',
        dataframe=False
)
# Access a specific symbol in the dict
print(quotes['AAPL'])
stream(symbols: list = [])

Live-streams market quotes for up to 256 stock and options.

The stream generator that yields dictionaries. Specify one or more symbols, and the stream object establishes a connection with the API servers, then starts returning symbol-keyed quote objects in real-time.

Args:
symbols:

string or list of strings, each string a symbol to be queried. Notice symbols=[‘spy’], symbols=’spy both work.

Returns:

A generator

Example:

for quote in a.stream('tsla'):
        print(quote)
timesales(symbols: str, startdate: str, enddate: str, interval: str = '5min', dataframe=True, block: bool = True)

Gets the most current market data on the price of a symbol.

Gets a dataset of price points and other information for a symbol. Option symbols unfortunately are not accessible from this interface, so only stocks can be used.

Must specify the start and end date on the range requested. The API can only return 5 days of intraday prices, the 5 most recent trading days, the current day included. Partial data will be returned for the current day, if the query occurs during the trading hours of a trading day.

Start and end date should take the form “2019-12-31”. This interface will be preserved, but datetime instances may be accepted in the future as well.

Args:
symbols:

single symbol to query historical quotes on

startdate:

string, the start date of interval

enddate:

string, end date of the interval

interval:

string, specify the size of each time interval. Must be one of (‘1min’,’5min’,’15min’)

dataframe:

flag, specifies whether to return data in pandas dataframe or flat list of dictionaries.

block: Specify whether to block thread if request exceeds rate limit

Returns:

Depends on dataframe flag. Will return pandas dataframe, or possibly list of dictionaries, each one a single quote.

Raises:

RateLimitException: If block=False, rate limit problems will be raised

Examples:

gld_history = a.timesales (
        symbols = 'gld',
        startdate = '2020-08-21',
        enddate = '2020-08-19',
)
print(gld_history.loc[0])
toplists(whichList: str, exchange: str = 'Q', dataframe: bool = True, block: bool = True)

Gets the most recent toplists for a given exchange.

Args:

whichList:

Must be one of {‘toplosers’, ‘toppctlosers’, ‘topvolume’, ‘topactive’, ‘topgainers’, ‘toppctgainers’}

exchange:

string, one of ‘A’ (American Stock Exchange) ‘N’ (NYSE) ‘Q’ (NASDAQ) ‘U’ (NASDAQ Bulletin Board) ‘V’ (NASDAQ OTC Other)

dataframe:

flag, specifies whether to return data in pandas dataframe or flat list of dictionaries.

block:

Specify whether to block thread if request exceeds rate limit

Returns:

Depends on dataframe flag. Will return pandas dataframe, or possibly list of dictionaries, each one a single quote.

Raises:

RateLimitException:

If block=False, rate limit problems will be raised

Example:

a.toplists('tpopctgainers')

                     chg  chg_sign       last                            name    pchg       pcls  rank        vl
symbol
BFRA     21.3700     u        41.6900                  BIOFRONTERA AG  105.17    20.3200     1    279216
CBMG      5.0100     u        19.2800  CELLULAR BIOMEDICINE GROUP INC   35.11    14.2700     2    793186