Created
February 18, 2016 03:28
-
-
Save pcdinh/07aad57cd1dd1bb99ffb 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
2016-02-17 19:37:30 Sell 0.00184800 44.77426917 0.08274284 | |
2016-02-17 19:37:19 Sell 0.00184800 80.38702381 0.14855522 | |
2016-02-17 19:37:07 Sell 0.00184800 106.83870702 0.19743793 | |
2016-02-13 16:00:53 Sell 0.00189389 23.23260419 0.04399999 | |
2016-02-13 15:56:31 Buy 0.00181500 56.16175099 0.10193357 | |
2016-02-13 15:55:00 Buy 0.00188365 464.53499696 0.87502134 | |
2016-02-13 15:55:00 Buy 0.00185000 540.54054054 0.99999999 | |
2016-02-13 15:51:08 Buy 0.00188365 66.34919065 0.12497865 | |
2016-02-13 15:42:00 Buy 0.00189460 3.79048474 0.00718145 | |
2016-02-13 15:37:04 Buy 0.00190027 526.24100785 0.99999999 | |
2016-02-13 15:30:18 Sell 0.00209300 513.00000000 1.07370900 | |
2016-02-13 14:56:19 Buy 0.00194733 513.52364519 0.99999999 | |
2016-02-12 08:30:43 Buy 0.00138888 150.00000000 0.20833200 |
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
''' | |
Created on Feb 17, 2016 | |
@author: dinh.pham | |
''' | |
import StringIO | |
import csv | |
# Special notes: | |
# + Big dump on 17/2/2016 on Poloniex | |
# + Someone continues to manipulate this market with big sell walls as I reported on #xmr channel | |
# 18/2/2016 9:41 AM: | |
# 0.00170000 105283.40218006 178.98178371 180.80737179 | |
# 0.00171469 8.00000000 0.01371752 180.82108931 | |
# 0.00171499 0.05993850 0.00010279 180.82119210 | |
# This kind of wall (58 -60k XMR) appeared at 0.0020, 0.00185, 0.0080) | |
currency_name = "XMR" | |
currency_value_in_btc = 0.00173000 | |
headers = 'day hour order_type price total_xmr total_btc' | |
# Same directory for convenience | |
data_file_path = './market_data_xmr1.txt' # leave it empty or assign it a value: e.x ./market_data_xmr1.txt | |
data = ''' | |
2016-02-17 19:37:30 Sell 0.00184800 44.77426917 0.08274284 | |
2016-02-17 19:37:19 Sell 0.00184800 80.38702381 0.14855522 | |
2016-02-17 19:37:07 Sell 0.00184800 106.83870702 0.19743793 | |
2016-02-13 16:00:53 Sell 0.00189389 23.23260419 0.04399999 | |
2016-02-13 15:56:31 Buy 0.00181500 56.16175099 0.10193357 | |
2016-02-13 15:55:00 Buy 0.00188365 464.53499696 0.87502134 | |
2016-02-13 15:55:00 Buy 0.00185000 540.54054054 0.99999999 | |
2016-02-13 15:51:08 Buy 0.00188365 66.34919065 0.12497865 | |
2016-02-13 15:42:00 Buy 0.00189460 3.79048474 0.00718145 | |
2016-02-13 15:37:04 Buy 0.00190027 526.24100785 0.99999999 | |
2016-02-13 15:30:18 Sell 0.00209300 513.00000000 1.07370900 | |
2016-02-13 14:56:19 Buy 0.00194733 513.52364519 0.99999999 | |
2016-02-12 08:30:43 Buy 0.00138888 150.00000000 0.20833200 | |
''' | |
def create_plain_text_reader(data, headers): | |
f = StringIO.StringIO(headers + data) # add headers and remove the first empty row | |
return f, csv.DictReader(f, delimiter=' ', quotechar='"', dialect=csv.excel) | |
def create_file_reader(file_path, headers): | |
'''Create a data reader which parses data stored in the provided file | |
:param file_path: See `data_file_path` | |
''' | |
f = open(file_path, 'rb') | |
return f, csv.DictReader( | |
f, | |
fieldnames=tuple([item.strip() for item in headers.split(' ')]), | |
delimiter=' ', | |
quotechar='"' | |
) | |
def calc_metrics(data_reader, xmr_market_price): | |
buy_count = 0 | |
bought_xmr = 0.0 | |
bought_btc = 0.0 | |
sell_count = 0 | |
sold_xmr = 0.0 | |
sold_btc = 0.0 | |
for row in data_reader: | |
if row["order_type"] == "Buy": | |
buy_count += 1 | |
bought_xmr += float(row["total_xmr"]) | |
sold_btc += float(row["total_btc"]) | |
else: | |
sell_count += 1 | |
sold_xmr += float(row["total_xmr"]) | |
bought_btc += float(row["total_btc"]) | |
return buy_count, sell_count, bought_xmr, sold_xmr, bought_btc, sold_btc | |
# Start the calculator | |
# - Create reader | |
if data_file_path: | |
data_object, reader = create_file_reader(data_file_path, headers) | |
else: | |
data_object, reader = create_plain_text_reader(data, headers) | |
# - Calculate | |
buy_count, sell_count, bought_xmr, sold_xmr, bought_btc, sold_btc = calc_metrics( | |
reader, | |
currency_value_in_btc | |
) | |
data_object.close() | |
xmr_balance = bought_xmr - sold_xmr | |
xmr_balance_value = currency_value_in_btc * xmr_balance | |
cost_diff = xmr_balance_value - (sold_btc - bought_btc) | |
# Display the result | |
print("{:11s} {:<15d} {:<11s} {:<5d}".format( | |
"Total buy:", buy_count, "Total sell:", sell_count)) | |
print("---------------------------------------------------------------------") | |
print("{:11s} {:<15.8f} ({:3s}) {:<11s} {:<15.8f} (BTC)".format( | |
"Bought:", bought_xmr, currency_name, "Cost:", sold_btc)) | |
print("{:11s} {:<15.8f} ({:3s}) {:<11s} {:<15.8f} (BTC)".format( | |
"Sold:", sold_xmr, currency_name, "Revenue:", bought_btc)) | |
print("_____________________________________________________________________") | |
print("{:11s} {:<15.8f} ({:3s}) {:<11s} {:<15.8f} (BTC)".format( | |
"Balance:", xmr_balance, currency_name, "Cost:", sold_btc - bought_btc)) | |
print("{:11s} {:<15.8f} (BTC)".format("Mar. value:", xmr_balance_value)) | |
print("{:11s} {:<15.8f} (BTC) {:<11s} {:<15.8f}".format( | |
"Loss/Gain:", cost_diff, "{}/BTC:".format(currency_name), currency_value_in_btc)) | |
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
Total buy: 58 Total sell: 93 | |
--------------------------------------------------------------------- | |
Bought: 6770.05927208 (XMR) Cost: 12.84599526 (BTC) | |
Sold: 4943.28183770 (XMR) Revenue: 9.99547379 (BTC) | |
_____________________________________________________________________ | |
Balance: 1826.77743438 (XMR) Cost: 2.85052147 (BTC) | |
Mar. value: 3.16032496 (BTC) | |
Loss/Gain: 0.30980349 (BTC) XMR/BTC: 0.00173000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment