Last active
March 10, 2020 00:00
-
-
Save henryrossiter/010283dd45e24517004041ff24a3c69d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import time | |
from fairlay_public_api import FairlayPythonPublic | |
fairlay = FairlayPythonPublic() | |
# Dictionary to store up-to-date market asks and bids | |
order_dict = {} | |
while True: | |
markets = fairlay.get_markets_and_odds({ | |
"OnlyActive": True, | |
"NoZombie": False, | |
}) | |
for market in markets: | |
if 'OrdBJSON' in market and len(market['OrdBJSON']): | |
# Save ask, bid, title, and unique market ID | |
ask = market['OrdBJSON'][0]['Asks'] | |
bid = market['OrdBJSON'][0]['Bids'] | |
title = market['Title'] | |
marketId = market['ID'] | |
if marketId in order_dict: | |
if 'ask' in order_dict[marketId] and order_dict[marketId]['ask'] != ask: | |
print('Ask for market #{} changed.\n\tMarket title: {}\n\t\tOld ask: {}\n\t\tNew ask:{}\n'.format( | |
marketId, | |
title, | |
order_dict[marketId]['ask'], | |
ask) | |
) | |
order_dict[marketId]['ask'] = ask | |
if 'bid' in order_dict[marketId] and order_dict[marketId]['bid'] != bid: | |
print('Bid for market #{} changed.\n\tMarket title: {}\n\t\tOld bid: {}\n\t\tNew bid:{}\n'.format( | |
marketId, | |
title, | |
order_dict[marketId]['bid'], | |
bid) | |
) | |
order_dict[marketId]['bid'] = bid | |
else: | |
order_dict[marketId] = { | |
'ask': ask, | |
'bid': bid | |
} | |
# Sleep for 5 seconds | |
time.sleep(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment