Git Product home page Git Product logo

investopedia_simulator_api's Introduction

Description

A simple Python API for Investopedia's stock simulator games.

Features

Currently you can:

  • Read all positions in your option, stock, and short portfolios
  • Buy/Sell long positions
  • Short sell/cover short positions
  • Perform option chain lookups
  • Buy/sell options
  • Read pending/open trades

Todo:

  • Setting the default game, changing games
  • Whatever else I can think of

Authentication

Investopedia put a recaptcha puzzle thing on their login page. This was easily circumvented by getting a human being to solve the captcha. After clicking on traffic lights 0-67 times, you will finally see the cookie. Just copy the value and pass it to the InvestopediaSimulatorAPI constructor. The cookie name is UI4. Simply copy its value but DO NOT PUBLISH IT unless you don't care about someone potentially gaining access to your Investopedia account

Security considerations

Don't fork this repo and publish your cookie for the whole world to see. Anyone with that string can access your account. For your convenience I added auth_cooke.json to .gitignore. If you plan on forking this to a publicly accessible repository then you should probably put your cookie in that untracked file and read from it.

Environment

Python 3.6.7. I just use a virtualenv and install using pip from requirements.txt. If you don't know how to do that:

git clone https://github.com/dchrostowski/investopedia_simulator_api.git
cd investopedia_simulator_api
pip install virtualenv
virtualenv -p /path/to/python3 ./venv
source venv/bin/activate
pip install -r requirements.txt
python exmaple.py

Example

code

from investopedia_api import InvestopediaApi
import json

cookies = {}
with open('auth_cookie.json') as ifh:
    cookies = json.load(ifh)
auth_cookie = cookies['account_cookie']
# pass the value of the UI4 cookie after logging in to the site.
client = InvestopediaApi(auth_cookie)

p = client.portfolio
print("account value: %s" % p.account_value)
print("cash: %s" % p.cash)
print("buying power: %s" % p.buying_power)
print("annual return pct: %s" % p.annual_return_pct)

# get a quote
quote = client.get_stock_quote('GOOG')
print(quote.__dict__)

# Read your portfolio
long_positions = client.portfolio.stock_portfolio
short_positions = client.portfolio.short_portfolio
my_options = client.portfolio.option_portfolio

# Place a buy order for 10 shares of Google with a limit of $1000/share

# shorthand for client.TradeProperties.TradeType.BUY()
trade_type = 'buy'

#shorthand for client.TradeProperties.OrderType.LIMIT(1000)
limit_1000 = 'limit 1000'

trade = client.StockTrade('GOOG',10,trade_type,order_type=limit_1000)
trade_info = trade.validate()
if trade.validated:
    print(trade_info)
    trade.execute()

# See example.py for more examples.

More Info / Documentation

This is a work in progress. I'll add more documentation as I continue developing. I also plan on making this a module and publishing to pip.

investopedia_simulator_api's People

Contributors

dchrostowski avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.