An api, written in Python, for Investopedia's paper trading stock simulator.

Overview

investopedia-trading-api

An API, written in Python, for Investopedia's paper trading stock simulator. Pull requests welcome.

This library is now Python 3 compatible!

Installation

For this API to be useful you need an Investopedia trading account, which you can make here.

You can install the library with pip:

pip install InvestopediaApi

Documentation and examples:

Importing everything:

from InvestopediaApi import ita

ita is the name of the file that contains everything of relevance for interacting with Investopedia.

The main class is Account, which logs you into the simulator upon instantiation.

Log into the simulator:

from InvestopediaApi import ita
client = ita.Account("emailaddress", "password")

Currently, Investopedia Api has 4 "meta" functions:

  1. ita.Account.get_portfolio_status
  2. ita.Account.get_current_securities
  3. ita.Account.get_open_trades
  4. ita.get_quote

get_portfolio_status returns a named tuple with 4 elements: account_val, buying_power, cash, and annual_return.

from InvestopediaApi import ita

client = ita.Account("email", "password")

status = client.get_portfolio_status()
print(status.account_val)
print(status.buying_power)
print(status.cash)
print(status.annual_return)

get_current_securities returns a Portfolio object with 3 attributes: bought, shorted, and options. Each of those is a list of Security objects with the following attributes: symbol, description, quantity, purchase_price, current_price, current_value, and gain_loss

from Investopedia import ita

client = ita.Account("email", "password")

portfolio = client.get_current_securities()

# Portfolio is not a list, it is a namedtuple object with 3 attributes: bought, shorted, options.
# Each of bought, shorted, and options is a list of Security objects, which have attributes
# symbol, description, quantity, purchase_price, current_price, current_value, and gain_loss

bought_securities = portfolio.bought
shorted_securities = portfolio.shorted
options = portfolio.options

for bought in bought_securities:
    print(bought.symbol)
    print(bought.description)
    print(bought.purchase_price)
    # etc.

# Repeat above loop for shorted securities and options

get_open_trades returns a list of "open" trades - that is, trades that have been made but not yet executed by the Investopedia platform. It returns a list of Trade namedtuple objects which have the following elements: date_time, description, symbol, and quantity.

from InvestopediaApi import ita

client = ita.Account("email", "password")

open_trades = client.get_open_trades()

for open_trade in open_trades:
    print(open_trade.date_time)
    print(open_trade.description)
    print(open_trade.symbol)
    print(open_trade.quantity)

get_quote returns the price of a security given its symbol. Unlike the other 3 meta functions, this is not part of the Account class. Returns false if the security is not found or another error occurs.

from InvestopediaApi import ita

client = ita.Account("email", "password")
print(ita.get_quote("GOOG"))

Making trades

Of course, the most important function in this API is the trade function. This takes, at minimum, a security symbol (string), an orderType (Action class), and a quantity (integer).

The trade function is best illustrated with examples:

Buying 10 shares of Google (GOOG) at market price:

client.trade("GOOG", ita.Action.buy, 10)

Selling 10 shares of Google at market price:

client.trade("GOOG", ita.Action.sell, 10)

Shorting 10 shares of Google:

client.trade("GOOG", ita.Action.short, 10)

Buying 10 shares of Google with a limit order at $500

client.trade("GOOG", ita.Action.buy, 10, "Limit", 500)

You can browse through the code (it's only in one file) to get a more thorough understanding of the possibilities.

Testing

All Tests: python -m unittest discover

Feature Tests

Feature tests require a config file to be set up InvestopediaApi/tests/config.py. Instructions are in InvestopediaApi/tests/config.example.py.

Owner
Kirk Thaker
Kirk Thaker
A Powerful Discord Webhook spammer

RocketHook | The discord spammer Some links: Telegram | Github FEATURES ๐Ÿค– Hide your ass and be a good robot ! Full proxies support HTTP/S, SOCKS4/5 S

Or 2 Feb 27, 2022
Python powered spreadsheets

Marmir is powerful and fun Marmir takes Python data structures and turns them into spreadsheets. It is xlwt and google spreadsheets on steroids. It al

Brian Ray 170 Dec 14, 2022
๐ŸŽฅ Stream your favorite movie from the terminal!

Stream-Cli stream-cli is a Python scrapping CLI that combine scrapy and webtorrent in one command for streaming movies from your terminal. Installatio

R E D O N E 379 Dec 24, 2022
The Most advanced and User-Friendly Google Collab NoteBook to download Torrent directly to Google Drive with File or Magnet Link support and with added protection of Timeout Preventer.

Torrent To Google Drive (UI Added! ๐Ÿ˜Š ) A Simple and User-Friendly Google Collab Notebook with UI to download Torrent to Google Drive using (.Torrent)

Dr.Caduceus 33 Aug 16, 2022
A bot i made for a dead com server lol it gets updated daily etc

6ix-Bot-Source A bot i made for a dead com server lol it gets updated daily etc For The UserAgent CMD https://developers.whatismybrowser.com/ thats a

Swiper 9 Mar 10, 2022
An anime themed telegram bot that can convert telegram media.

ShoukoKomiRobot โ€ข ๐•Ž๐•ฃ๐•š๐•ฅ๐•ฅ๐•–๐•Ÿ ๐•€๐•Ÿ Python3 โ€ข ๐•ƒ๐•š๐•“๐•ฃ๐•’๐•ฃ๐•ช ๐•Œ๐•ค๐•–๐•• Pyrogram โ€ข ๐•Š๐• ๐•—๐•ฅ๐•จ๐•’๐•ฃ๐•– ๐•Œ๐•ค๐•–๐•• Ebook-convert Deploy ๐”ฝ๐• ๐•ฃ๐•œ ๐•ฅ๐•™๐•š๐•ค ๐•ฃ

25 Aug 14, 2022
A minimal open source mtg-like tcg game made in python that can be played on a terminal emulator using a keyboard.

TCG-TERM Project state: ๐Ÿ”ง ๐Ÿšง ๐Ÿšง ๐Ÿšง Incomplete, In development ๐Ÿšง ๐Ÿšง ๐Ÿšง ๐Ÿ‘ท (Keep in mind that at the moment, This project is currently undone, and wil

Amos 3 Aug 29, 2021
Pdisk Link Converter Telegram Bot, Convert link in a single click

Pdisk Converter Bot Make short link by using Pdisk API key Installation The Easy Way Required Variables BOT_TOKEN: Create a bot using @BotFather, and

Ayush Kumar Jaiswal 6 Jul 28, 2022
A media upload to telegraph module

A media upload to telegraph module

Fayas Noushad 5 Dec 01, 2021
Python client library for Google Maps API Web Services

Python Client for Google Maps Services Description Use Python? Want to geocode something? Looking for directions? Maybe matrices of directions? This l

Google Maps 3.8k Jan 01, 2023
Webservice that notifies users on Slack when a change in GitLab concern them.

Gitlab Slack Notifier Webservice that notifies users on Slack when a change in GitLab concern them. Setup Slack Create a Slack app, go to "OAuth & Per

Heuritech 2 Nov 04, 2021
A telegram photos or videos background remover bot

Remove BG Bot A telegram photos or videos background remover bot Variables API_HASH Your API Hash from my.telegram.org API_ID Your API ID from my.tele

ALBY 7 Dec 13, 2022
A Telegram Bot That Provides Permanent Download Links For Sent Files.

FileStreamBot A Telegram bot to all media and documents files to web link . Report a Bug | Request Feature Demo Bot: ๐Ÿ About This Bot : This bot will

Flux Inc. 1 Nov 02, 2021
gBasic - The easy multiplatform bot

gBasic The easy multiplatform bot gBasic is the module at the core of @GianpiertoldaBot, maintained with 3 for the entire community by the Stockdroid

Stockdroid Fans 5 Nov 03, 2021
Andrei 1.4k Dec 24, 2022
Discord Rpc With Python And 2 Buttons

Discord-RPC-With-Python- Discord Rpc With Python And 2 Buttons Packages pypresence time Required Programs Python Latest Version Random IDE Discord :P

Kaz 4 Dec 12, 2021
Sends notifications when Pokemon Center products are in stock

Sends notifications when Pokemon Center products are in stock! If you use this for scalping, I will break your kneecaps

2 Jan 20, 2022
A python library created to make life easier for Telegram API Developers.

opentele A python library created to make life easier for Telegram API Developers. Read the documentation Features Convert Telegram Desktop tdata sess

103 Jan 02, 2023
The AWS Lambda Serverless Blind XSS App

Ass The AWS Lambda Serverless Blind XSS App ๅˆฉ็”จVPS้…็ฝฎXSSๅนณๅฐๅคช้บป็ƒฆไบ†๏ผŒๅฆ‚ๆžœๅˆฉ็”จAWS็š„Lambda้‚ฃไธๅฐฑๆ˜ฏไธ€ไธชๅŸŸๅ็š„ไบ‹ๆƒ…ไนˆ๏ผŸๅ‰ฉไธ‹็š„็Žฏๅขƒ้…็ฝฎใ€HTTPS่ฏไนฆใ€้š็งๆ€งใ€VPS็ปญ่ดน้ƒฝไธ็”จ็ฎกไบ†๏ผŒ ๆ‰€ไปฅๆ นๆฎxless้‡ๅ†™ไบ†Lambdaๅนณๅฐ็š„XSS๏ผŒๅˆฉ็”จsla

cocokey 2 Dec 27, 2021
A free and open-source SMS/Call bombing application

TBOMB V0.1 A free and open-source SMS/Call bombing application NOTE: For Termux To use the bomber type the following commands in Termux: pkg install g

แด€ษดแด‹ษชแด› แด‹แดœแดแด€ส€ 2 Dec 07, 2021