-
Notifications
You must be signed in to change notification settings - Fork 14
Home
Dan Chrostowski edited this page Dec 3, 2020
·
6 revisions
- 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.
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
Get everything in requirements.txt
installed. If you run into trouble, Google is your friend.
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
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)
quote = client.get_stock_quote('GOOGL')
print(quote.name)
print(quote.symbol)
print(quote.last)
trade = client.StockTrade('GOOGL',10,'buy')
trade_info = trade.validate()
if trade.validated:
print(trade_info)
trade.execute()
See StockTrade
lookup = client.get_option_chain('MSFT')
print(lookup)
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)
lookup = client.get_option_chain('MSFT')
option_contract = lookup.get('MSFT2115A120')
option_trade = client.OptionTrade(option_contract,10,trade_type='buy to open')
See example.py
for more examples.