Analyzer now finds spread, perc and prints a sorted list; core is now able to start and stop the bot

This commit is contained in:
Dennis Thiessen
2017-10-19 13:03:27 +02:00
parent ccd1d53715
commit 95bdeee9e2
3 changed files with 34 additions and 66 deletions

View File

@@ -7,7 +7,9 @@ import sys
import operator
import pprint
def calculate_arbitrage_opportunities(exchanges):
start_time = time.time()
market_data = market_data_crawler.update_market_data_for_symbol_and_exchange(exchanges)
sorted_market_data = {}
@@ -32,11 +34,6 @@ def calculate_arbitrage_opportunities(exchanges):
highest_bid = None
market_opport.update({symbol: {}})
for exchange_name, order_book in exchanges.items():
"""""""""
TODO: This is wrong - you have to calculate the biggest spread!!!
"""""""""
if lowest_ask is None or lowest_ask['value'] < order_book['asks'][0]:
lowest_ask = {"exchange_name":exchange_name,
"value":order_book['asks'][0],
@@ -51,41 +48,23 @@ def calculate_arbitrage_opportunities(exchanges):
market_opport[symbol].update({"highest_bid": highest_bid,
"lowest_ask": lowest_ask,
"spread": spread})
"spread": spread,
"spread_perc": round((spread / float(highest_bid['value'][0])) * 100, 2),
"symbol": symbol})
if spread > 0:
with open("market_opportunity_found.txt", "a") as file:
file.write("\n+n--- Arbitrage oppportunity found! ---\n\n")
pprint.pprint(market_opport[symbol], stream=file)
sorted_list = sorted(market_opport.values(), key=operator.itemgetter("spread_perc"), reverse=True)
with open("market_analyzation.txt", "w") as file:
pprint.pprint(market_opport, stream=file)
return
start_time = time.time()
for pair in market_data:
if len(market_data[pair]) > 1:
price_list = {}
for price in market_data[pair]:
key, value = price.popitem()
price_list[key] = float(value)
sorted_x = sorted(price_list.items(), key=operator.itemgetter(1), reverse=True)
spread = sorted_x[0][1] - sorted_x[-1][1]
spread_perc = round((spread / sorted_x[0][1]) * 100, 2)
market_opport[pair] = {"highest_market": sorted_x[0][0],
"highest_price": sorted_x[0][1],
"lowest_market": sorted_x[-1][0],
"lowest_price": sorted_x[-1][1],
"spread": spread,
"spread_perc": spread_perc,
"pair": pair}
market_opport = sorted(market_opport.values(), key=operator.itemgetter("spread_perc"), reverse=True)
pprint.pprint(sorted_list, stream=file)
print("--- Arbitrage oportunities calculated in {0:.3f}ms ---".format((time.time() - start_time)*100))
return market_opport
if __name__ == '__main__':
calculate_arbitrage_opportunities(sys.argv[1:])
calculate_arbitrage_opportunities(sys.argv[1:])