Home - dchrostowski/investopedia_simulator_api GitHub Wiki
Quickstart
Account Setup
- Create an Investopedia account if you don't already have one and join a simulator game
- Copy/rename
credentials_example.json
tocredentials.json
(credentials.json
should be listed in.gitignore
so you don't inadvertently share your password with the world ) - Edit credentials.json and replace the example username and password with your personal one.
Dependencies
Ubuntu/Debian
This may be helpful in solving pip installation issues:
sudo apt-get install python3 python3-lxml virtualenv python3-dev
sudo apt-get build-dep python3-lxml
Windows / Mac
Get everything in requirements.txt
installed. If you run into trouble, Google is your friend.
Setup environment and run project
git clone https://github.com/dchrostowski/investopedia_simulator_api.git
cd investopedia_simulator_api
pip install virtualenv
which python3
virtualenv -p /path/to/python3 ./venv
source venv/bin/activate
pip install -r requirements.txt
python exmaple.py
Get portfolio information
from investopedia_api import InvestopediaApi
client = InvestopediaApi({"username": "[email protected]", "password": "yourpassword"})
portfolio = client.portfolio
print("account value: %s" % portfolio.account_value)
print("cash: %s" % portfolio.cash)
print("buying power: %s" % portfolio.buying_power)
print("annual return pct: %s" % portfolio.annual_return_pct)
Get stock quote
quote = client.get_stock_quote('GOOGL')
print(quote.name)
print(quote.symbol)
print(quote.last)
Buy stock
trade = client.StockTrade('GOOGL',10,'buy')
trade_info = trade.validate()
if trade.validated:
print(trade_info)
trade.execute()
See StockTrade
Get option chain lookup
lookup = client.get_option_chain('MSFT')
print(lookup)
Search option chain
lookup = client.get_option_chain('MSFT')
# gets all MSFT options for May 2019
for chain in lookup.search_by_month_and_year(5,2019):
for call in chain.calls:
print(call)
for put in chain.puts:
print(put)
Buy an option
lookup = client.get_option_chain('MSFT')
option_contract = lookup.get('MSFT2115A120')
option_trade = client.OptionTrade(option_contract,10,trade_type='buy to open')
More examples
See example.py
for more examples.