Giter VIP home page Giter VIP logo

pyredictit's Introduction

pyredictit

MY DEVELOPMENT ON THIS LIBRARY IS CURRENTLY CLOSED

This repo gets a healthy amount of traffic but unfortunately PredictIt disabled my account because I refused to remove this repository. Update as of 4/16/19: my attempt to find a way around PredictIt disabling my account didn't work, and I don't really desire to spend a lot more effort on trying to find new ways in to PredictIt, but a couple of people have forked this repo and I figure it may be interesting/a nice starting point for some other intrepid developers so I'm going to leave it public.

pyredictit is a wrapper for the public PredictIt API (https://predictit.freshdesk.com/support/solutions/articles/12000001878-does-predictit-make-market-data-available-via-an-api-). Running this module requires mechanicalsoup and Python 3.6. Check out the Examples directory for some ideas on how to use this!

**this can buy or sell shares using the money currently in your account. i am not responsible for any awful (or brilliant) trades you may accidentally or purposefully make with this wrapper. don't risk more than you can afford to lose. **

Things you can do with this currently are:

  • Buy or sell shares of contracts that you already own.
  • Check your current balance
  • Find out how much you'd make if you sold all of your shares in a market
  • Find out what you would make (or lose) depending on how the contract resolves
  • Summarize all of your current contracts.
  • Look up & purchase shares of contracts you don't currently own
  • Check latest volume of any contract.

COMING SOON:

  • Adding a method where, given a gmail address and a phone number, receive text alerts on any triggers you want to set up!

HOW YOU CAN HELP:

report all exceptions! Liberally open issues and let me know what's not working or what looks wonky! Include as much info as possible and please check to make sure that you are using valid login info and whatnot if you're copying over from the examples. Also, any feedback is useful!

UPDATE - the number 1 question I've been getting about this is "will it steal my login and password," and the answer is of course not, but don't take my word for it! Lines 226-235 are the parts where authentication is handled specifically, and I suspect that even people who don't fully understand Python's syntax will be able to see and verify for themselves that this information isn't transmitted anywhere beyond PI's server.

INSTALLATION:

  1. Go to https://www.python.org/downloads/

  2. Click "Download Python 3.6.0"

  3. Install it and check "Add Python to PATH" box in setup options.

  4. Open up Powershell/Terminal and type: python -m pip install mechanicalsoup

  5. Clone this repo

  6. CD into the directory where you cloned the repo and type: python setup.py install

  7. Use it like a Python module!

TODO:

  • C O M M E N T S
  • UNIT TESTS
  • DOC TESTS
  • Custom Exception classes
  • Adding to pip
  • stop loss and buy-at functionality - this is a priority!
  • setup.py script
  • Look up & purchase shares of contracts you don't currently own

pyredictit's People

Contributors

kcinnick avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pyredictit's Issues

Changed PredictIt API / authentication issues

Thank you for writing this tool! I was trying to set up the repo and get it to work, but it appears that PredictIt has nontrivially changed its API. I tried updating your code to use the new API endpoints, but I ran into some trouble. I don't know much about web development, but it looks like as a prerequisite to putting in a buy order, the browser makes a GET request to https://www.predictit.org/api/Trade//OrderBook. Python returns a 401 when I try to hit this URL; and even when I try to hit it directly in the browser, on a session where I'm logged in, I get a 401. Don't know why that's happening, but presumably there's some sort of authentication that happens on the contracts page where you can only proceed if you're on that page? Would appreciate if you could take a look and see if you can tell what's going on.

Here's my updated function that attempts to use the new API:

def buy_shares(self, api, number_of_shares, buy_price):
    # this URL is wrong, it's not self.cid, it's some other id, not sure what it's an id for. but it doesn't
    # work with the correct id either (I tried it directly in the browser)
    order_book_page = api.browser.get(f'https://www.predictit.org/api/Trade/{self.cid}/OrderBook')
    all_bids_and_offers = order_book_page.json()

    confirm = api.browser.post(f'https://www.predictit.org/api/Trade/ConfirmTrade', {
        'quantity': number_of_shares,
        'pricePerShare': buy_price,
        'contractId': self.cid,
        'tradeType': 1,
    })
    if str(confirm.status_code) != '200':
        print(f"Request returned an invalid {confirm.status_code} code. Please make sure you're using valid login credentials.")

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.