Skip to content

Commit

Permalink
added multiple currency support for all currencies available through
Browse files Browse the repository at this point in the history
bitcoin average. changed colors to use ui-variable defaults and only go
red or green when rising and remain neutral when stable.
  • Loading branch information
Lbatson committed Mar 14, 2014
1 parent 08344bb commit 954d48c
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 23 deletions.
36 changes: 27 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,41 @@
[atom-bitcoin](https://atom.io/packages/atom-bitcoin)
============

Watch the latest selling price for bitcoin while you code!
####Watch the latest selling price for bitcoin while you code!

![](https://dl.dropboxusercontent.com/s/4lvxmytpicoz9o1/screenshot.png?dl=1&token_hash=AAEBoVYT77ey684_qqX5ltFAhUOfRdqmxjMUcnuUNxnFTA)


To install
####To install

`` cd /Users/your_username/.atom/packages ``
`` apm install atom-bitcoin `` or search for ``atom-bitcoin`` in Settings > Packages

`` git clone git@github.com:ahmetabdi/atom-bitcoin.git ``
This uses the [BitcoinAverage API](https://bitcoinaverage.com/api.htm), an open source project designed to provide weighted average bitcoin price calculation. It utilises all exchanges where price and volume data is available.

then restart atom
####Features

Update interval fixed to 5 seconds
- Update interval defaults to 5 seconds but any second-based interval can be entered in the settings

Has colour updates to show increase/decrease in price in USD
- Has colour updates to show increase/decrease/stable in price

This uses the [BitcoinAverage API](https://bitcoinaverage.com/api.htm)
- Currency defaults to USD but any currency from the list below can be entered in the settings

It's an open source project designed to provide weighted average bitcoin price calculation. It utilises all exchanges where price and volume data is available.
- AUD
- BRL
- CAD
- CHF
- CNY
- EUR
- GBP
- HKD
- ILS
- JPY
- NOK
- NZD
- PLN
- RUB
- SEK
- SGD
- TRY
- USD
- ZAR
34 changes: 22 additions & 12 deletions lib/atom-bitcoin-status-bar-view.coffee
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
{View} = require 'atom'
jQuery = require 'jquery'
valid_currencies = require './currencies'

module.exports =
class AtomBitcoinStatusBarView extends View
default_interval: 5000
default_currency: 'USD'
load_text: 'Retreiving price...'

@content: ->
@div class: 'inline-block', =>
@span outlet: "bitcoinInfo", class: 'atom-bitcoin-status', tabindex: '-1', ""
@div class: 'inline-block atom-bitcoin', =>
@span outlet: "bitcoinInfo", tabindex: '-1', ""

initialize: ->
# We wait until all the other packages have been loaded,
Expand All @@ -27,32 +29,40 @@ class AtomBitcoinStatusBarView extends View
interval = atom.config.get('atom-bitcoin.interval')
interval = if not isNaN(interval) then (interval.toFixed() * 1000) else @default_interval

# Get user settings for currency
# Insure currency is in the supported list or use default
currency = atom.config.get('atom-bitcoin.currency')
currency = if currency of valid_currencies then currency else @default_currency

# Display loading text
@display(null)

output = undefined
last_output = undefined
setInterval =>
jQuery ($) ->
json = $.getJSON "https://api.bitcoinaverage.com/ticker/USD/last", '', (data, resp) ->
json = $.getJSON 'https://api.bitcoinaverage.com/ticker/'+currency+'/last', '', (data, resp) ->
if resp = "success"
output = parseFloat(data).toFixed(2)
if output > last_output
$(".atom-bitcoin-status").css "color", "green"
else if output < last_output
$(".atom-bitcoin-status").css "color", "red"
else

else
#Handle failed response?

# Set color for ticker
@bitcoinInfo.removeClass('status-stable status-rise status-fall')
if output > last_output
@bitcoinInfo.addClass('status-rise')
else if output < last_output
@bitcoinInfo.addClass('status-fall')
else
@bitcoinInfo.addClass('status-stable')

# Update price
@display(output)
@display(output, valid_currencies[currency])
last_output = output

, interval # config or default interval


display: (price) ->
display: (price, symbol) ->
# Display loading text or current price
@bitcoinInfo.text(if not price then @load_text else "$#{price}")
@bitcoinInfo.text(if not price then @load_text else symbol+price)
1 change: 1 addition & 0 deletions lib/atom-bitcoin.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ module.exports =
@atomBitcoinStatusBarView = new AtomBitcoinStatusBarView()

configDefaults:
currency: 'USD'
interval: 5
21 changes: 21 additions & 0 deletions lib/currencies.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
"AUD": "\u0024",
"BRL": "\u0052\u0024",
"CAD": "\u0024",
"CHF": "\u0043\u0048\u0046",
"CNY": "\u00a5",
"EUR": "\u20ac",
"GBP": "\u00a3",
"HKD": "\u0024",
"ILS": "\u20aa",
"JPY": "\u00a5",
"NOK": "\u006b\u0072",
"NZD": "\u0024",
"PLN": "\u007a\u0142",
"RUB": "\u0440\u0443\u0431",
"SEK": "\u006b\u0072",
"SGD": "\u0024",
"TRY": "\u20ba",
"USD": "\u0024",
"ZAR": "\u0052"
}
14 changes: 12 additions & 2 deletions stylesheets/atom-spotify.less → stylesheets/atom-bitcoin.less
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
// for a full listing of what's available.
@import "ui-variables";

.atom-bitcoin-status {
color: @text-color;
.atom-bitcoin {
.status-stable {
color: @text-color;
}

.status-rise {
color: @text-color-success;
}

.status-fall {
color: @text-color-error;
}
}

0 comments on commit 954d48c

Please sign in to comment.