Feathercoin daemon and wallet production version 0.17.0.1

Simple real time FTC price ticker python script


  • | Tip sp495

    This isn’t the best script out there and most-likely someone out there has a better way of doing it, but in case others were interest, I wrote this quick python script to get the real time FTC price and convert to fiat currencies.

    It’s pretty self explanatory when you look at the code, but basically it looks for the exchange rates via json.load and then compares to the previous iteration. If it’s different it prints the prices in BTC, USD, GBP, EUR, and AUD; as well as trading volumes in FTC and BTC. I’ve attached a screen shot as an example.

    code is available here, as well as http://uploaded.net/file/oczk626c

    Known Issues:
    sometimes the connection times out and you get some red error message about being unable to establish a connection to the api feeds. Just restart the script and all is well. (I need a better solution to this, most-likely some sort of error handling)

    For those feeling uneasy about downloading a script from a stranger (I get it, nothing personal) here is the code to copy and paste 8):

    import json
    import urllib2
    from pprint import pprint
    import time
    from time import strftime
    #get initial prices and exchange rates & trading volume on script start
    initial_scan = json.load(urllib2.urlopen(“https://btc-e.com/api/2/ftc_btc/ticker”))
    initial_ftcprice = initial_scan[‘ticker’][‘last’]
    initial_btcusdscan = json.load(urllib2.urlopen(“https://btc-e.com/api/2/btc_usd/ticker”))
    initial_btcusd = initial_btcusdscan[‘ticker’][‘last’]
    initial_btceurscan = json.load(urllib2.urlopen(“https://btc-e.com/api/2/btc_eur/ticker”))
    initial_btceur = initial_btceurscan[‘ticker’][‘last’]
    initial_usdgbpscan = json.load(urllib2.urlopen(“http://rate-exchange.appspot.com/currency?from=USD&to=GBP&q=1”))
    initial_usdgbp = initial_usdgbpscan[“rate”]
    initial_usdaudscan = json.load(urllib2.urlopen(“http://rate-exchange.appspot.com/currency?from=USD&to=AUD&q=1”))
    initial_usdaud = initial_usdaudscan[“rate”]
    initial_volinftc = initial_scan[‘ticker’][‘vol_cur’]
    initial_volinbtc = initial_scan[‘ticker’][‘vol’]
    currenttime = strftime("%Y-%m-%d %H:%M:%S")
    #do currency conversions from ftc-btc & btc-usd prices
    initial_ftcusd = initial_ftcprice*initial_btcusd
    initial_ftceur = initial_ftcprice*initial_btceur
    initial_ftcgbp = initial_ftcprice*initial_btcusd*initial_usdgbp
    initial_ftcaud = initial_ftcprice*initial_btcusd*initial_usdaud
    #print initial prices & trading volume
    print (str(initial_ftcprice) + " BTC")
    print(str(initial_ftcusd) + " USD")
    print(str(initial_ftceur) + " EUR")
    print(str(initial_ftcgbp) + " GBP")
    print(str(initial_ftcaud) + " AUD")
    print(“Trading Volume: " + str(initial_volinftc) + " FTC / " + str(initial_volinbtc) + " BTC”)
    print currenttime
    print("================================================")
    time.sleep(1)
    while True:
    #scan for prices & trading volume again
    data = json.load(urllib2.urlopen(“https://btc-e.com/api/2/ftc_btc/ticker”))
    data2 = json.load(urllib2.urlopen(“https://btc-e.com/api/2/btc_usd/ticker”))
    data3 = json.load(urllib2.urlopen(“https://btc-e.com/api/2/btc_eur/ticker”))
    data4 = json.load(urllib2.urlopen(“http://rate-exchange.appspot.com/currency?from=USD&to=GBP&q=1”))
    data5 = json.load(urllib2.urlopen(“http://rate-exchange.appspot.com/currency?from=USD&to=AUD&q=1”))
    btcEUR = data3[‘ticker’][‘last’]
    btcUSD = data2[‘ticker’][‘last’]
    usdGBP = data4[“rate”]
    usdAUD = data5[“rate”]
    volFTC = data[‘ticker’][‘vol_cur’]
    volBTC = data[‘ticker’][‘vol’]
    #new prices
    ftcBTC = data[‘ticker’][‘last’]
    ftcUSD = ftcBTC*btcUSD
    ftcEUR = ftcBTC*btcEUR
    ftcGBP = ftcUSD*usdGBP
    ftcAUD = ftcUSD*usdAUD
    newtime = strftime("%Y-%m-%d %H:%M:%S")
    #percent change in price
    diff = initial_ftcprice - ftcBTC
    a = abs(diff)
    change = 100*a/initial_ftcprice
    #are the new prices different from the old ones?
    if ftcBTC != initial_ftcprice:
    print (str(ftcBTC) + " BTC")
    print (str(ftcUSD) + " USD")
    print (str(ftcEUR) + " EUR")
    print (str(ftcGBP) + " GBP")
    print (str(ftcAUD) + " AUD")
    print(“Trading Volume: " + str(volFTC) + " FTC / " + str(volBTC) + " BTC”)
    if diff < 0:
    print(“Price Change: -” + str(change) + “%”)
    elif diff > 0:
    print(“Price Change: +” + str(change) + “%”)
    print newtime
    print("================================================")
    initial_ftcprice = ftcBTC
    time.sleep(1)

    [attachment deleted by admin]


  • | Tip sp495

    Currently adding in CAD conversion and working on error handling so that you don’t have to restart the script on timeout. Fixed price percent change as in the current state a positive price change is displayed as a negative!


  • | Tip BatesResearch

    Excellent this seems like an ace script, we are not educated in running and sampling the script can you provide a link to show it working


  • | Tip BatesResearch

    We messed with the script a little and got it working, it’s ace learnt something new aswell.


  • | Tip sp495

    [quote name=“BatesResearch” post=“21398” timestamp=“1373655299”]
    We messed with the script a little and got it working, it’s ace learnt something new aswell.
    [/quote]
    Run it in python, does what the screenshot shows. I need to work around a timeout error and figured I should round fiat prices to while Pennies. What changes have you made? I’d like to see other peoples’ tweeks and improvements. Also (going out on a limb) if you like/use/appreciate my work a donation is always appreciated 😉 see signature


  • | Tip sp495

    If I can find a PXC and WDC API feed I’ll put them in as well.FYI you can get the latest version of python at www.python.org


  • | Tip BatesResearch

    We need only display the FTC/GBP value so we edited the script to just show that. We are building a FTC website including prices, mining information etc so if we use this script we will definitely send a donation to you.

    Thank you


  • | Tip sp495

    [quote name=“BatesResearch” post=“21445” timestamp=“1373717558”]
    We need only display the FTC/GBP value so we edited the script to just show that. We are building a FTC website including prices, mining information etc so if we use this script we will definitely send a donation to you.

    Thank you
    [/quote]

    Anything not involved in the currency converting you don’t need just comment out with #. I’ve added CAD conversion, fixed the percent change to be correct, and rounded fiat prices to whole pennies. Will post updated script tomorrow after a couple more tweeks. I need to learn php so I can port it for websites, right now this only works on your desktop/laptop.


  • | Tip sp495

    Latest version now converts ftc price to usd/gbp/eur/aud/cad to whole value pennies (0.01), percent price diff now displays correct sign(i.e. up or down), and some timeout errors are handled. Note some server errors may still occur due to an inability to contact the host site for the prices - I am currently trying to work around these but I hope you enjoy this version 😃

    download:
    http://uploaded.net/file/durqk8pa

    copy & paste code:
    import json
    import urllib2
    from pprint import pprint
    import time
    from time import strftime
    import math
    import httplib
    #get initial prices and exchange rates & trading volume on script start
    initial_scan = json.load(urllib2.urlopen(“https://btc-e.com/api/2/ftc_btc/ticker”))
    initial_ftcprice = initial_scan[‘ticker’][‘last’]
    initial_btcusdscan = json.load(urllib2.urlopen(“https://btc-e.com/api/2/btc_usd/ticker”))
    initial_btcusd = initial_btcusdscan[‘ticker’][‘last’]
    initial_btceurscan = json.load(urllib2.urlopen(“https://btc-e.com/api/2/btc_eur/ticker”))
    initial_btceur = initial_btceurscan[‘ticker’][‘last’]
    initial_usdgbpscan = json.load(urllib2.urlopen(“http://rate-exchange.appspot.com/currency?from=USD&to=GBP&q=1”))
    initial_usdgbp = initial_usdgbpscan[“rate”]
    initial_usdaudscan = json.load(urllib2.urlopen(“http://rate-exchange.appspot.com/currency?from=USD&to=AUD&q=1”))
    initial_usdaud = initial_usdaudscan[“rate”]
    initial_usdcadscan = json.load(urllib2.urlopen(“http://rate-exchange.appspot.com/currency?from=USD&to=CAD&q=1”))
    initial_usdcad = initial_usdcadscan[“rate”]
    initial_volinftc = initial_scan[‘ticker’][‘vol_cur’]
    initial_volinbtc = initial_scan[‘ticker’][‘vol’]
    currenttime = strftime("%Y-%m-%d %H:%M:%S")
    #do currency conversions from ftc-btc & btc-usd prices
    initial_ftcusd = math.ceil(initial_ftcprice*initial_btcusd*100)/100
    initial_ftceur = math.ceil(initial_ftcprice*initial_btceur*100)/100
    initial_ftcgbp = math.ceil(initial_ftcprice*initial_btcusd*initial_usdgbp*100)/100
    initial_ftcaud = math.ceil(initial_ftcprice*initial_btcusd*initial_usdaud*100)/100
    initial_ftccad = math.ceil(initial_ftcprice*initial_btcusd*initial_usdcad*100)/100
    #print initial prices & trading volume
    print (str(initial_ftcprice) + " BTC")
    print (str(initial_ftcusd) + " USD")
    print (str(initial_ftceur) + " EUR")
    print (str(initial_ftcgbp) + " GBP")
    print (str(initial_ftcaud) + " AUD")
    print (str(initial_ftccad) + " CAD")
    print (“Trading Volume: " + str(initial_volinftc) + " FTC / " + str(initial_volinbtc) + " BTC”)
    print currenttime
    print ("==================================================")
    while True:
    #scan for prices & trading volume again
    try:
    data = json.load(urllib2.urlopen(“https://btc-e.com/api/2/ftc_btc/ticker”, timeout = 3))
    data2 = json.load(urllib2.urlopen(“https://btc-e.com/api/2/btc_usd/ticker”, timeout = 3))
    data3 = json.load(urllib2.urlopen(“https://btc-e.com/api/2/btc_eur/ticker”, timeout = 3))
    data4 = json.load(urllib2.urlopen(“http://rate-exchange.appspot.com/currency?from=USD&to=GBP&q=1”, timeout = 3))
    data5 = json.load(urllib2.urlopen(“http://rate-exchange.appspot.com/currency?from=USD&to=AUD&q=1”, timeout = 3))
    data6 = json.load(urllib2.urlopen(“http://rate-exchange.appspot.com/currency?from=USD&to=CAD&q=1”, timeout = 3))
    except (urllib2.HTTPError, urllib2.URLError, httplib.BadStatusLine, SSLError) as err:
    print (“Unable to load source for ticker!”)
    time.sleep(1)
    else:
    btcEUR = data3[‘ticker’][‘last’]
    btcUSD = data2[‘ticker’][‘last’]
    usdGBP = data4[“rate”]
    usdAUD = data5[“rate”]
    usdCAD = data6[“rate”]
    volFTC = data[‘ticker’][‘vol_cur’]
    volBTC = data[‘ticker’][‘vol’]
    #new prices
    ftcBTC = data[‘ticker’][‘last’]
    ftcUSD = math.ceil(ftcBTC*btcUSD*100)/100
    ftcEUR = math.ceil(ftcBTC*btcEUR*100)/100
    ftcGBP = math.ceil(ftcUSD*usdGBP*100)/100
    ftcAUD = math.ceil(ftcUSD*usdAUD*100)/100
    ftcCAD = math.ceil(ftcUSD*usdCAD*100)/100
    newtime = strftime("%Y-%m-%d %H:%M:%S")
    #percent change in price
    diff = initial_ftcprice - ftcBTC
    a = abs(diff)
    change = math.ceil(100*100*a/initial_ftcprice)/100
    #are the new prices different from the old ones?
    if ftcBTC != initial_ftcprice:
    print (str(ftcBTC) + " BTC")
    print (str(ftcUSD) + " USD")
    print (str(ftcEUR) + " EUR")
    print (str(ftcGBP) + " GBP")
    print (str(ftcAUD) + " AUD")
    print (str(ftcCAD) + " CAD")
    print(“Trading Volume: " + str(volFTC) + " FTC / " + str(volBTC) + " BTC”)
    if diff < 0:
    print(“Price Change: +” + str(change) + “%”)
    elif diff > 0:
    print(“Price Change: -” + str(change) + “%”)
    print newtime
    print("==================================================")
    initial_ftcprice = ftcBTC
    time.sleep(1)

    [attachment deleted by admin]


  • | Tip BatesResearch

    Excellent script, currently working with it and trying to figure out how to host on my project website.

    Thanks Again. Once all is working ill send a donation your way.


  • | Tip sp495

    [quote name=“BatesResearch” post=“22561” timestamp=“1374451722”]
    Excellent script, currently working with it and trying to figure out how to host on my project website.

    Thanks Again. Once all is working ill send a donation your way.
    [/quote]
    I’m still working on the SSLError as I’m not handling it properly. Also I’ve noticed if you change the sleep times to at least 1 minute the servers the script calls are less likely to reject the communication - which results in the timeout errors


  • | Tip BatesResearch

    Any update on the SSLError.


  • Regular Member | Tip d2

    [quote name=“BatesResearch” post=“26975” timestamp=“1378067151”]
    Any update on the SSLError.
    [/quote]

    If you’re still interested: https://www.crypto-trade.com/api/1/ticker/ftc_usd


  • | Tip BatesResearch

    Thanks d2, but I’m looking for a system to show FTC/GBP.

    Sp495 has already created an amazing script which when cut down just shows FTC/GBP but I’m trying to work how to get it displayed on a website


  • | Tip UKMark

    [quote name=“BatesResearch” post=“27024” timestamp=“1378119815”]
    Thanks d2, but I’m looking for a system to show FTC/GBP.

    Sp495 has already created an amazing script which when cut down just shows FTC/GBP but I’m trying to work how to get it displayed on a website
    [/quote]

    To parse and display:
    [url=http://api.feathercoin.com?amount=1&output=json]api.feathercoin.com?amount=1&output=json[/url]

    To simply display:
    [url=http://api.feathercoin.com?amount=1&output=gbp]api.feathercoin.com?amount=1&output=gbp[/url]


  • | Tip BatesResearch

    WOW. Who made this or was I that blind that I totally missed it.

    That is exactly what am I looking for.

    With the name UKMark I guessed your based in the UK, if your ever near Manchester let me know Ill buy you a few drinks


  • | Tip UKMark

    [quote name=“BatesResearch” post=“27035” timestamp=“1378129467”]
    WOW. Who made this or was I that blind that I totally missed it.

    That is exactly what am I looking for.

    With the name UKMark I guessed your based in the UK, if your ever near Manchester let me know Ill buy you a few drinks
    [/quote]

    Yes you missed it :’(
    I’m near Liverpool so you may not want to buy me that pint. 😃

    BTW more info on the API and its uses can be found here:

    [url=http://api.feathercoin.com/?output=info]http://api.feathercoin.com/?output=info[/url]


  • | Tip BatesResearch

    Thanks.

    If you ever visit Manchester let me know 😃

    Thank you