Skip to content

Instantly share code, notes, and snippets.

@jjrh
Created November 29, 2013 02:10
Show Gist options
  • Select an option

  • Save jjrh/7700667 to your computer and use it in GitHub Desktop.

Select an option

Save jjrh/7700667 to your computer and use it in GitHub Desktop.
wrapper around the the telnet output from api.bitcoincharts.com
import telnetlib
import json
import datetime
from termcolor import colored
print ""
print "opening telnet connection to api.bitcoincharts.com:27007"
print ""
stream = telnetlib.Telnet("api.bitcoincharts.com",27007)
def unix_to_datetime(inp):
return(datetime.datetime.fromtimestamp(int(inp)))
"""
4+10 |14 + 8 | 22
5+10 |15 + 8 | 23
6+10 |16 + 10 | 26
8+10 |18 + 12 | 30
2+10 |12 + 9 | 21
"""
def print_title():
title = "%-22s | %-23s | %-26s | %-30s | %-21s " % (colored("date","white"),
colored("price","white"),
colored("volume","white"),
colored("exchange","white"),
colored("id","white"))
print title
print "%-22s + %-23s + %-26s + %-30s + %-21s " % (colored("-------------","yellow"),
colored("--------------","yellow"),
colored("-----------------","yellow"),
colored("---------------------","yellow"),
colored("---------","yellow"))
reprint_count = 80
count = 0
print_title()
while 1:
data = json.loads(stream.read_until("\n"))
formatted_string = "%-22s | %-23s | %-26s | %-30s | %-21s " % (colored(unix_to_datetime(data['timestamp']).strftime('%H:%M:%S'),"red"),
colored(data['price'],'yellow'),
colored(data['volume'],"magenta"),
colored(data['symbol'],"blue"),
colored(data['id'],"cyan"))
print formatted_string
if(count >= reprint_count):
print_title()
count = 0
else:
count +=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment