pyredictit's Issues
Is there a reason for scraping the HTML?
I'm wondering if the point is to better emulate the browser as opposed to reverse engineering their API endpoints.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.