ExchangeList() - Eoddata.com web service blog series

Sat 25 March 2017 by Adrian Torrie

This post is part 3 of the "Using Python with Eoddata.com web service" series:

  1. Master post - Eoddata.com web service blog series
  2. Login() - Eoddata.com web service blog series
  3. ExchangeList() - Eoddata.com web service blog series
  4. CountryList() - Eoddata.com web service blog series
  5. SymbolList() - Eoddata.com web service blog series
  6. FundamentalList() - Eoddata.com web service blog series

Summary

Part of the blog series related to making web service calls to Eoddata.com. Overview of the web service can be found here.

Version Control

In [1]:
%run ../../code/version_check.py
Python: 3.5.3 |Continuum Analytics, Inc.| (default, Feb 22 2017, 21:13:27) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]

matplotlib:	2.0.0
numpy:		1.12.0
pandas:		0.19.2
quandl:		3.0.1
sklearn:	0.18.1
scipy:		0.18.1
statsmodels:	0.8.0
tensorflow:	1.0.1

Change Log

Date Created: 2017-03-25

Date of Change    Change Notes
--------------    ----------------------------------------------------------------
2017-03-25        Initial draft
2017-04-02        - Changed any references for `get_exchange_list()` to `exchange_list()`
                  - Client class function returns data in fixed order now

Setup

In [10]:
%run ../../code/eoddata.py

import pandas as pd
import requests as r

ws = 'http://ws.eoddata.com/data.asmx'
ns='http://ws.eoddata.com/Data'

with (Client()) as eoddata:
    token = eoddata.get_token()

ExchangeList()

Web service call

In [3]:
session = r.Session()

call = 'ExchangeList'
kwargs = {'Token': token,}
pattern = ".//{%s}EXCHANGE"

url = '/'.join((ws, call))
response = session.get(url, params=kwargs, stream=True)

if response.status_code == 200:
    root = etree.parse(response.raw).getroot()
    
session.close()

Gather elements

In [4]:
elements = root.findall(pattern %(ns))

Get data

In [5]:
exchanges = sorted(element.get('Code') for element in elements)
exchanges
Out[5]:
['AMEX',
 'AMS',
 'ASX',
 'BRU',
 'BSE',
 'CBOT',
 'CFE',
 'CME',
 'COMEX',
 'EUREX',
 'FOREX',
 'HKEX',
 'INDEX',
 'KCBT',
 'LIFFE',
 'LIS',
 'LSE',
 'MGEX',
 'MLSE',
 'NASDAQ',
 'NSE',
 'NYBOT',
 'NYMEX',
 'NYSE',
 'NZX',
 'OTCBB',
 'PAR',
 'SGX',
 'TSX',
 'TSXV',
 'USMF',
 'WCE']

Save to file

In [6]:
with open('../../data/exchanges.csv', 'w') as f:
    for element in elements:
        f.write('"%s"\n' % '","'.join(element.attrib.values()))

Data inspection

In [7]:
for item in root.items():
    print (item)
('Message', 'Success')
('Source', 'Data.ExchangeList')
('Date', '2017-04-02T01:24:40.658625-05:00')
In [8]:
for element in root.iter():
    print(element.attrib)
{'Message': 'Success', 'Source': 'Data.ExchangeList', 'Date': '2017-04-02T01:24:40.658625-05:00'}
{}
{'Currency': 'USD', 'IsIntraday': 'true', 'Declines': '897', 'Name': 'American Stock Exchange', 'Suffix': '', 'LastTradeDateTime': '2017-03-31T16:59:58', 'Advances': '3196', 'IntradayStartDate': '2008-01-01T00:00:00', 'HasIntradayProduct': 'true', 'Code': 'AMEX', 'Country': 'US', 'TimeZone': 'Eastern Standard Time'}
{'Currency': 'AUD', 'IsIntraday': 'false', 'Declines': '494', 'Name': 'Australian Securities Exchange', 'Suffix': 'AX', 'LastTradeDateTime': '2017-03-31T00:00:00', 'Advances': '14867', 'IntradayStartDate': '0001-01-01T00:00:00', 'HasIntradayProduct': 'false', 'Code': 'ASX', 'Country': 'AU', 'TimeZone': 'AUS Eastern Standard Time'}
{'Currency': 'INR', 'IsIntraday': 'false', 'Declines': '0', 'Name': 'Bombay Stock Exchange', 'Suffix': 'I', 'LastTradeDateTime': '2017-03-31T00:00:00', 'Advances': '4673', 'IntradayStartDate': '0001-01-01T00:00:00', 'HasIntradayProduct': 'false', 'Code': 'BSE', 'Country': 'IN', 'TimeZone': 'India Standard Time'}
{'Currency': 'USD', 'IsIntraday': 'true', 'Declines': '234', 'Name': 'Chicago Board of Trade', 'Suffix': '', 'LastTradeDateTime': '2017-03-31T00:00:00', 'Advances': '101766', 'IntradayStartDate': '2009-01-01T00:00:00', 'HasIntradayProduct': 'true', 'Code': 'CBOT', 'Country': 'US', 'TimeZone': 'Central Standard Time'}
{'Currency': 'USD', 'IsIntraday': 'true', 'Declines': '0', 'Name': 'Chicago Futures Exchange', 'Suffix': '', 'LastTradeDateTime': '2017-03-31T00:00:00', 'Advances': '207', 'IntradayStartDate': '2009-01-01T00:00:00', 'HasIntradayProduct': 'true', 'Code': 'CFE', 'Country': 'US', 'TimeZone': 'Central Standard Time'}
{'Currency': 'USD', 'IsIntraday': 'true', 'Declines': '569', 'Name': 'Chicago Merchantile Exchange', 'Suffix': '', 'LastTradeDateTime': '2017-03-31T00:00:00', 'Advances': '211381', 'IntradayStartDate': '2009-01-01T00:00:00', 'HasIntradayProduct': 'true', 'Code': 'CME', 'Country': 'US', 'TimeZone': 'Eastern Standard Time'}
{'Currency': 'EUR', 'IsIntraday': 'false', 'Declines': '0', 'Name': 'EUREX Futures Exchange', 'Suffix': '', 'LastTradeDateTime': '2017-03-31T00:00:00', 'Advances': '1754', 'IntradayStartDate': '0001-01-01T00:00:00', 'HasIntradayProduct': 'false', 'Code': 'EUREX', 'Country': 'CH', 'TimeZone': 'GMT Standard Time'}
{'Currency': 'EUR', 'IsIntraday': 'false', 'Declines': '0', 'Name': 'Euronext Amsterdam', 'Suffix': 'AS', 'LastTradeDateTime': '2017-03-31T00:00:00', 'Advances': '151', 'IntradayStartDate': '0001-01-01T00:00:00', 'HasIntradayProduct': 'false', 'Code': 'AMS', 'Country': 'NL', 'TimeZone': 'GMT Standard Time'}
{'Currency': 'EUR', 'IsIntraday': 'false', 'Declines': '0', 'Name': 'Euronext Brussels', 'Suffix': 'BR', 'LastTradeDateTime': '2017-03-31T00:00:00', 'Advances': '217', 'IntradayStartDate': '0001-01-01T00:00:00', 'HasIntradayProduct': 'false', 'Code': 'BRU', 'Country': 'BE', 'TimeZone': 'GMT Standard Time'}
{'Currency': 'EUR', 'IsIntraday': 'false', 'Declines': '0', 'Name': 'Euronext Lisbon', 'Suffix': 'LS', 'LastTradeDateTime': '2017-03-31T00:00:00', 'Advances': '48', 'IntradayStartDate': '0001-01-01T00:00:00', 'HasIntradayProduct': 'false', 'Code': 'LIS', 'Country': 'PT', 'TimeZone': 'GMT Standard Time'}
{'Currency': 'EUR', 'IsIntraday': 'false', 'Declines': '0', 'Name': 'Euronext Paris', 'Suffix': 'PA', 'LastTradeDateTime': '2017-03-31T09:04:00', 'Advances': '1865', 'IntradayStartDate': '0001-01-01T00:00:00', 'HasIntradayProduct': 'false', 'Code': 'PAR', 'Country': 'FR', 'TimeZone': 'GMT Standard Time'}
{'Currency': '', 'IsIntraday': 'false', 'Declines': '57', 'Name': 'Foreign Exchange', 'Suffix': '', 'LastTradeDateTime': '2017-04-01T04:58:59', 'Advances': '1345', 'IntradayStartDate': '0001-01-01T00:00:00', 'HasIntradayProduct': 'false', 'Code': 'FOREX', 'Country': 'US', 'TimeZone': 'Eastern Standard Time'}
{'Currency': '', 'IsIntraday': 'false', 'Declines': '4', 'Name': 'Global Indices', 'Suffix': 'IDX', 'LastTradeDateTime': '2017-03-31T16:54:00', 'Advances': '2790', 'IntradayStartDate': '0001-01-01T00:00:00', 'HasIntradayProduct': 'false', 'Code': 'INDEX', 'Country': 'US', 'TimeZone': 'Eastern Standard Time'}
{'Currency': 'HKD', 'IsIntraday': 'false', 'Declines': '700', 'Name': 'Hong Kong Stock Exchange', 'Suffix': 'HK', 'LastTradeDateTime': '2017-03-31T00:00:00', 'Advances': '2107', 'IntradayStartDate': '0001-01-01T00:00:00', 'HasIntradayProduct': 'false', 'Code': 'HKEX', 'Country': 'HK', 'TimeZone': 'Singapore Standard Time'}
{'Currency': 'USD', 'IsIntraday': 'true', 'Declines': '21', 'Name': 'Kansas City Board of Trade', 'Suffix': '', 'LastTradeDateTime': '2017-03-31T00:00:00', 'Advances': '2095', 'IntradayStartDate': '2009-01-01T00:00:00', 'HasIntradayProduct': 'true', 'Code': 'KCBT', 'Country': 'US', 'TimeZone': 'Central Standard Time'}
{'Currency': 'USD', 'IsIntraday': 'false', 'Declines': '0', 'Name': 'LIFFE Futures and Options', 'Suffix': '', 'LastTradeDateTime': '2017-03-31T00:00:00', 'Advances': '2087', 'IntradayStartDate': '0001-01-01T00:00:00', 'HasIntradayProduct': 'false', 'Code': 'LIFFE', 'Country': 'US', 'TimeZone': 'GMT Standard Time'}
{'Currency': 'GBP', 'IsIntraday': 'false', 'Declines': '2622', 'Name': 'London Stock Exchange', 'Suffix': 'L', 'LastTradeDateTime': '2017-03-31T00:00:00', 'Advances': '37832', 'IntradayStartDate': '0001-01-01T00:00:00', 'HasIntradayProduct': 'false', 'Code': 'LSE', 'Country': 'UK', 'TimeZone': 'GMT Standard Time'}
{'Currency': 'EUR', 'IsIntraday': 'false', 'Declines': '112', 'Name': 'Milan Stock Exchange', 'Suffix': 'MI', 'LastTradeDateTime': '2017-03-31T00:00:00', 'Advances': '176', 'IntradayStartDate': '0001-01-01T00:00:00', 'HasIntradayProduct': 'false', 'Code': 'MLSE', 'Country': 'IT', 'TimeZone': 'Central European Standard Time'}
{'Currency': 'USD', 'IsIntraday': 'true', 'Declines': '96', 'Name': 'Minneapolis Grain Exchange', 'Suffix': '', 'LastTradeDateTime': '2017-03-31T00:00:00', 'Advances': '14990', 'IntradayStartDate': '2009-01-01T00:00:00', 'HasIntradayProduct': 'true', 'Code': 'MGEX', 'Country': 'US', 'TimeZone': 'Central Standard Time'}
{'Currency': 'USD', 'IsIntraday': 'false', 'Declines': '16958', 'Name': 'Mutual Funds', 'Suffix': '', 'LastTradeDateTime': '2017-03-30T00:00:00', 'Advances': '30240', 'IntradayStartDate': '0001-01-01T00:00:00', 'HasIntradayProduct': 'false', 'Code': 'USMF', 'Country': 'US', 'TimeZone': 'Eastern Standard Time'}
{'Currency': 'USD', 'IsIntraday': 'true', 'Declines': '1837', 'Name': 'NASDAQ Stock Exchange', 'Suffix': '', 'LastTradeDateTime': '2017-03-31T16:59:59', 'Advances': '5519', 'IntradayStartDate': '2008-01-01T00:00:00', 'HasIntradayProduct': 'true', 'Code': 'NASDAQ', 'Country': 'US', 'TimeZone': 'Eastern Standard Time'}
{'Currency': 'INR', 'IsIntraday': 'false', 'Declines': '0', 'Name': 'National Stock Exchange of India', 'Suffix': 'I', 'LastTradeDateTime': '2017-03-31T09:23:00', 'Advances': '1391', 'IntradayStartDate': '0001-01-01T00:00:00', 'HasIntradayProduct': 'false', 'Code': 'NSE', 'Country': 'IN', 'TimeZone': 'GMT Standard Time'}
{'Currency': 'USD', 'IsIntraday': 'true', 'Declines': '207', 'Name': 'New York Board of Trade', 'Suffix': '', 'LastTradeDateTime': '2017-03-31T00:00:00', 'Advances': '88214', 'IntradayStartDate': '2009-01-01T00:00:00', 'HasIntradayProduct': 'true', 'Code': 'NYBOT', 'Country': 'US', 'TimeZone': 'Eastern Standard Time'}
{'Currency': 'USD', 'IsIntraday': 'true', 'Declines': '150', 'Name': 'New York Commodity Exchange', 'Suffix': '', 'LastTradeDateTime': '2017-03-31T00:00:00', 'Advances': '33435', 'IntradayStartDate': '2009-01-01T00:00:00', 'HasIntradayProduct': 'true', 'Code': 'COMEX', 'Country': 'US', 'TimeZone': 'Eastern Standard Time'}
{'Currency': 'USD', 'IsIntraday': 'true', 'Declines': '237', 'Name': 'New York Merchantile Exchange', 'Suffix': '', 'LastTradeDateTime': '2017-03-31T00:00:00', 'Advances': '17081', 'IntradayStartDate': '2009-01-01T00:00:00', 'HasIntradayProduct': 'true', 'Code': 'NYMEX', 'Country': 'US', 'TimeZone': 'Eastern Standard Time'}
{'Currency': 'USD', 'IsIntraday': 'true', 'Declines': '1880', 'Name': 'New York Stock Exchange', 'Suffix': '', 'LastTradeDateTime': '2017-03-31T16:46:31', 'Advances': '4895', 'IntradayStartDate': '2008-01-01T00:00:00', 'HasIntradayProduct': 'true', 'Code': 'NYSE', 'Country': 'US', 'TimeZone': 'Eastern Standard Time'}
{'Currency': 'NZD', 'IsIntraday': 'false', 'Declines': '44', 'Name': 'New Zealand Exchange', 'Suffix': 'NZ', 'LastTradeDateTime': '2017-03-31T00:00:00', 'Advances': '1077', 'IntradayStartDate': '0001-01-01T00:00:00', 'HasIntradayProduct': 'false', 'Code': 'NZX', 'Country': 'NZ', 'TimeZone': 'New Zealand Standard Time'}
{'Currency': 'USD', 'IsIntraday': 'true', 'Declines': '2112', 'Name': 'OTC Bulletin Board', 'Suffix': 'OB', 'LastTradeDateTime': '2017-03-31T16:59:59', 'Advances': '34732', 'IntradayStartDate': '2009-01-01T00:00:00', 'HasIntradayProduct': 'true', 'Code': 'OTCBB', 'Country': 'US', 'TimeZone': 'Eastern Standard Time'}
{'Currency': 'SGD', 'IsIntraday': 'false', 'Declines': '499', 'Name': 'Singapore Stock Exchange', 'Suffix': 'SI', 'LastTradeDateTime': '2017-03-31T00:00:00', 'Advances': '12390', 'IntradayStartDate': '0001-01-01T00:00:00', 'HasIntradayProduct': 'false', 'Code': 'SGX', 'Country': 'SG', 'TimeZone': 'Singapore Standard Time'}
{'Currency': 'CAD', 'IsIntraday': 'false', 'Declines': '882', 'Name': 'Toronto Stock Exchange', 'Suffix': 'TO', 'LastTradeDateTime': '2017-03-31T00:00:00', 'Advances': '5710', 'IntradayStartDate': '0001-01-01T00:00:00', 'HasIntradayProduct': 'false', 'Code': 'TSX', 'Country': 'CA', 'TimeZone': 'Mountain Standard Time'}
{'Currency': 'CAD', 'IsIntraday': 'false', 'Declines': '562', 'Name': 'Toronto Venture Exchange', 'Suffix': 'V', 'LastTradeDateTime': '2017-03-31T00:00:00', 'Advances': '5056', 'IntradayStartDate': '0001-01-01T00:00:00', 'HasIntradayProduct': 'false', 'Code': 'TSXV', 'Country': 'CA', 'TimeZone': 'Mountain Standard Time'}
{'Currency': 'USD', 'IsIntraday': 'true', 'Declines': '1', 'Name': 'Winnipeg Commodity Exchange', 'Suffix': '', 'LastTradeDateTime': '2017-03-31T00:00:00', 'Advances': '9968', 'IntradayStartDate': '2009-01-01T00:00:00', 'HasIntradayProduct': 'true', 'Code': 'WCE', 'Country': 'US', 'TimeZone': 'Central Standard Time'}

Helper function

In [9]:
def ExchangeList(session, token):
    call = 'ExchangeList'
    kwargs = {'Token': token,}
    pattern = ".//{%s}EXCHANGE"

    url = '/'.join((ws, call))
    response = session.get(url, params=kwargs, stream=True)

    if response.status_code == 200:
        root = etree.parse(response.raw).getroot()
        
    return sorted(element.get('Code') for element in elements)

Usage

In [10]:
session = r.session()

exchanges = ExchangeList(session, token)
exchanges

session.close()

Client function

In [11]:
# pandas dataframe is returned
df = eoddata.exchange_list()

df.head()
Out[11]:
Code Name LastTradeDateTime Country Currency Advances Declines Suffix TimeZone IsIntraday cntradayStartDate HasIntradayProduct
0 AMEX American Stock Exchange 2017-03-31T16:59:58 US USD 3196 897 Eastern Standard Time true NaN true
1 ASX Australian Securities Exchange 2017-03-31T00:00:00 AU AUD 14867 494 AX AUS Eastern Standard Time false NaN false
2 BSE Bombay Stock Exchange 2017-03-31T00:00:00 IN INR 4673 0 I India Standard Time false NaN false
3 CBOT Chicago Board of Trade 2017-03-31T00:00:00 US USD 101766 234 Central Standard Time true NaN true
4 CFE Chicago Futures Exchange 2017-03-31T00:00:00 US USD 207 0 Central Standard Time true NaN true

Comments

Fork me on GitHub