I'm shopping for real time data API provider for treasury futures. Can anyone share any good ones?



A couple of Python libraries can help you accomplish this. This script was originally posted by Theodor Perisvolris on his blog. I have made some minor changes to it for my use case.

from googlefinance import getQuotes
import json
import pandas as pd
import datetime
import requests

def get_intraday_data(symbol, interval_seconds=301, num_days=10):
    # Specify URL string based on function inputs.
    url_string = 'http://www.google.com/finance/getprices?q={0}'.format(symbol.upper())
    url_string += "&i={0}&p={1}d&f=d,o,h,l,c,v".format(interval_seconds,num_days)

    # Request the text, and split by each line
    r = requests.get(url_string).text.split()

    # Split each line by a comma, starting at the 8th line
    r = [line.split(',') for line in r[7:]]

    # Save data in Pandas DataFrame
    df = pd.DataFrame(r, columns=['Datetime','Close','High','Low','Open','Volume'])

    # Convert UNIX to Datetime format
    df['Datetime'] = df['Datetime'].apply(lambda x: datetime.datetime.fromtimestamp(int(x[1:])))

    #Convert 'Close','High','Low','Open', deleting 'Volume'

    df['Close'] = df['Close'].astype('float64')
    df['High'] = df['High'].astype('float64')
    df['Low'] = df['Low'].astype('float64')
    df['Open'] = df['Open'].astype('float64')
    del df['Volume']

   # Calculating %Change and Range

    df['%pct'] = (df['Close'] - df['Open'])/df['Open']
    df['Range'] = df['High'] - df['Low']

    return df

The function is run by finding the google symbol for the financial instrument you wish to track .

For example,S&P US Treasury Bond Futures Index TR (Symbol = SPUSTBTR),

UST = get_intraday_data('SPUSTBTR', interval_seconds=301, num_days= 100)
  • $\begingroup$ This doesn't suggest a data provider but merely suggests one without giving insight on why to choose this one. Your script can be useful but I don't believe it answers this particular question very well. Downvoted. $\endgroup$ – Bob Jansen Oct 8 '16 at 20:14

Your Answer

