Coder Social home page Coder Social logo

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.