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
An Simple Advance Auto Filter Bot Complete Rewritten Version Of Adv-Filter-Bot

Adv Auto Filter Bot V2 This Is Just An Simple Advance Auto Filter Bot Complete Rewritten Version Of Adv-Filter-Bot.. Just Sent Any Text As Query It Wi

0 Dec 18, 2021
Build a better understanding of your data in PostgreSQL.

Data Fluent for PostgreSQL Build a better understanding of your data in PostgreSQL. The following shows an example report generated by this tool. It g

Mark Litwintschik 28 Aug 30, 2022
Neko: An Anime themed advance Telegram group management bot

π‘ͺπ’–π’•π’Šπ’†π’‘π’Šπ’Š 𝑹𝒐𝒃𝒐𝒕 A modular telegram Python bot running on python3 wit

γ€Œ Rajkumarβ„’ 」 39 Jan 08, 2023
An instagram bot developed in Python with Selenium that helps you get more Instagram followers.

instabot An instagram bot developed in Python with Selenium that helps you get more Instagram followers. Install You’ll need to have: Python Selenium

65 Nov 22, 2022
use python script to fix vmp dump api in ida

FixVmpDump use python script to fix vmp dump api in ida. support x86 and x64. details in my blog: https://blog.csdn.net/yan_star/article/details/11279

97 Nov 02, 2022
EzilaX Music ❀ is the best and only Telegram VC player with playlists, Multi Playback, Channel play and more POWERD By SDBOTs

EzilaX-Music 🎡 A bot that can play music on Telegram Group and Channel Voice Chats Available on telegram as @EzilaXMBot Features πŸ”₯ Thumbnail Support

Sadew Jayasekara 9 Oct 24, 2021
A Discord bot that automatically saves SHSH blobs for all of your iOS devices.

AutoTSS AutoTSS is a Discord bot that automatically saves SHSH blobs for all of your iOS devices. Want a CLI automatic blob saver? Check out AutoTSS-c

adam 79 Dec 13, 2022
A python library for creating Slack slash commands using AWS Lambda Functions

slashbot Slashbot makes it easy to create slash commands using AWS Lambda functions. These can be handy for creating a secure way to execute automated

Eric Brassell 17 Oct 21, 2022
Python SDK for interacting with the Frame.io API.

python-frameio-client Frame.io Frame.io is a cloud-based collaboration hub that allows video professionals to share files, comment on clips real-time,

Frame.io 37 Dec 21, 2022
Simple Telegram webscrap bot

webscrap-bot Simple Telegram webscrap bot Configs TOKEN - Get bot token from @BotFather API_ID - From my.telegram.org API_HASH - From my.telegram.org

lokaman chendekar 10 Oct 21, 2022
Cleiton Leonel 4 Apr 22, 2022
The purpose of this bot is to take soundcloud track requests, that are posted in the stream-requests channel, and add them to a playlist, to make the process of scrolling through the requests easier for Root

Discord Song Collector Dont know if anyone is actually going to read this, but the purpose of this bot is to check every message in the stream-request

2 Mar 01, 2022
LavaAPI - A simple library for accepting payments and using the LAVA Wallet

This library was created to simplify the LAVA api provided on the official websi

Vlad Baccara 8 Dec 18, 2022
A simple Python API wrapper for Cloudflare Stream's API.

python-cloudflare-stream A basic Python API wrapper for working with Cloudflare Stream. Arbington.com started off using Cloudflare Stream. We used the

Arbington 3 Sep 08, 2022
Rbx-mass-send - mass sends trades to item owners

mass sends trades to item owners proxies should be in ip:port format itemsToSend

0 Feb 20, 2022
Bot interpretation of the carbon.now.sh site

πŸ“’ Source code of the @PicodeBot 🧸 Developer: @hoosnick Run $ git clone https://github.com/hoosnick/picodebot.git $ pip install -r requirements.txt P

Husniddin Murodov 13 Oct 02, 2022
Automate coin farming for dankmemer. Unlimited accounts at once. Uses a proxy

dankmemer-farm Simple script to farm Dankmemer coins with multiple accounts at once. Requires: Proxies, Discord Tokens Disclaimer I don't take respons

Scobra 12 Dec 20, 2022
Module to use some statistics from Spotify API

statify Module to use some statistics from Spotify API To use it you have to import the functions into your own project. You have also to authenticate

Miguel CΓ³zar 2 Jun 02, 2022
Discord bot to display private leaderboards for Advent of Code.

Advent Of Code Discord Bot Discord bot for displaying Advent of Code private leardboards, as well as custom leaderboards where participants can set th

The Future Gadgets Lab 6 Nov 29, 2022
Discord music bot using discord.py, slash commands, and yt-dlp.

bop Discord music bot using discord.py, slash commands, and yt-dlp. Features Play music from YouTube videos and playlists Queue system with shuffle Sk

Hizkia Felix 3 Aug 11, 2022