Skip to content

Instantly share code, notes, and snippets.

@DrMartiner
Created December 12, 2017 02:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DrMartiner/24c73274b3b7d80fc7996124e5425887 to your computer and use it in GitHub Desktop.
Save DrMartiner/24c73274b3b7d80fc7996124e5425887 to your computer and use it in GitHub Desktop.
Poloniex profit monitor
from datetime import datetime
from time import sleep
from colorclass import Color
from poloniex import Poloniex
from terminaltables import AsciiTable
API_KEY = ""
API_SECRET = ''
polo = Poloniex(API_KEY, API_SECRET)
fee = 0.0025
interval = 2
lots = [1.0, 0.1, 0.01]
def get_profit(ticker: dict, currency: str, lot_btc: float) -> float:
currency_amount = lot_btc / ticker['BTC_' + currency]['last']
currency_amount -= currency_amount * fee
amount_usdt = currency_amount * ticker['USDT_' + currency]['last']
amount_usdt -= amount_usdt * fee
amount_btc = amount_usdt / ticker['USDT_BTC']['last']
amount_btc -= amount_btc * fee
return amount_btc - lot_btc
def display_profit() -> None:
currencies = ['DASH', 'LTC', 'NXT', 'STR', 'XMR', 'XRP', 'ETH', 'ETC', 'REP', 'ZEC', 'BCH']
table_data = [['Currency'] + lots]
ticker = polo.returnTicker() # type: dict
for currency in currencies:
row = [currency]
for lot in lots:
profit = get_profit(ticker, currency, lot)
color_name = 'red'
if profit > 0:
color_name = 'green'
color = Color('{auto' + color_name + '}' + '{:10.9f}'.format(profit) + '{/auto' + color_name + '}')
row.append(color)
table_data.append(row)
print('\033c')
print(AsciiTable([
['Name', 'Value'],
['way', 'BTC -> USDT -> BTC'],
['fee', fee],
['interval', interval],
['updated', datetime.now().time()],
]).table)
print(AsciiTable(table_data).table)
sleep(interval)
try:
while True:
display_profit()
except KeyboardInterrupt:
pass
colorclass==2.2.0
poloniex==0.0.11
terminaltables==3.1.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment