8000 Added support for a brazilian exchange trader MercadoBitcoin by arianpasquali · Pull Request #3 · jawerty/btcl · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Added support for a brazilian exchange trader MercadoBitcoin #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 38 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,60 +1,63 @@
# btcl
Follow Bitcoin markets from your terminal.

<img src="http://bitcoin.org/img/opengraph.png" width="100" height="100"></img>

btcl is a cli for retrieving Bitcoin prices from your command-line instantly. You can choose to get the top market or retrieve a single price quote with the exchange symbol from bitcoincharts.
This fork adds support for brazilian exchange trader MercadoBitcoin.

```
$ btcl mtgoxUSD
847.0
```

# Install
Install via rubygems
```
$ gem install btcl
```

Install via Docker
```
$ docker build -t btcl github.com/jawerty/btcl
$ docker run btcl
$ ruby btcl.rb mercadobitcoin -v
---------------------
| high | 2622.0 |
| low | 2300.60031 |
| last | 2549.0 |
| buy | 2531.0 |
| sell | 2548.0 |
```

# Usage

Retrieve the prices from the top exchanges.

```
$ btcl
$ ruby btcl.rb

------------------------------------------
| Exchange | Price |
------------------------------------------
| Mercado Bitcoin (Reais) | 2545.0 |
| BTC CHINA | 5900.0 |
| Mt. Gox USA | 1022.0 |
| BitStamp | 964.87 |
| btc-e | 949.0 |
| Mt.Gox EUROPE | 739.0 |
| Mt.Gox JAPAN | 101829.414 |
| bitcoin.de | 683.4 |
| Bitcurex | 2969.85 |
| Canadian Virtual Exchange | 954.0 |
| Mt.Gox UK | 624.994 |
------------------------------------------
```
![Alt text](/public/1.png)

Quickly retrieve the ask price from a single exchange. The first argument is the symbol used on bitcoincharts.com (see all market symbols at bitcoincharts.com/markets/).
```
$ btcl mtgoxUSD
847.0
$ ruby btcl.rb mercadobitcoin
2531.0
```
![Alt text](/public/2.png)

Get more prices.
```
$ btcl mtgoxUSD --verbose
$ ruby btcl.rb mercadobitcoin --verbose
```

or

```
$ btcl mtgoxUSD -v
$ ruby btcl.rb mercadobitcoin -v
---------------------
| high | 2622.0 |
| low | 2300.60031 |
| last | 2549.0 |
| buy | 2531.0 |
| sell | 2548.0 |
```
![Alt text](/public/3.png)

# Contact
If you would like to contact me for further information on the project, see the info below.

Email: jawerty210@gmail.com

Github: jawerty

Twitter: @jawerty

Blog: <http://jawerty.github.io>
This is a fork based on jawerty's work (https://github.com/jawerty/btcl).
10 changes: 5 additions & 5 deletions btcl.gemspec
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Gem::Specification.new do |s|
s.name = "btcl"
s.version = "0.0.1"
s.version = "0.0.1.1"
s.summary = "A cli for retrieving prices from Bitcoin exchanges."
s.description = "Follow Bitcoin markets from your terminal. btcl is a Bitcoin Market Price Client that uses bitcoin markets api to retrieve real-time data."
s.author = "Jared Wright"
s.email = 'jawerty210@gmail.com'
s.homepage = 'https://github.com/jawerty/btcl'
s.description = "Follow Bitcoin markets from your terminal. btcl is a Bitcoin Market Price Client that uses bitcoin markets api to retrieve real-time data. This is a fork from https://github.com/jawerty/btcl project. It add support to a brazilian exchange called MercadoBitcoin."
s.author = "Arian Pasquali, Jared Wright"
s.email = 'github@arianpasquali.com'
s.homepage = 'https://github.com/arianpasquali/btcl'
s.rubyforge_project = 'btcl'
s.license = 'MIT'
s.executables = ["btcl"]
Expand Down
52 changes: 48 additions & 4 deletions lib/btcl.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require 'text-table'

$top = {
"Mercado Bitcoin - Brasil" => "mercadobitcoin",
"BTC CHINA" => "btcnCNY",
"Mt. Gox USA" => "mtgoxUSD",
"BitStamp" => "bitstampUSD",
Expand All @@ -23,6 +24,19 @@
:horizontal_boundary => '|',
:boundary_intersection => '-'

def getMercadoBitcoin()
url = "https://www.mercadobitcoin.com.br/api/ticker/"

begin
open(url) do |d|
json = JSON.parse(d.read)
return true, json["ticker"]
end
end
rescue SocketError => e
return false, "bity Error: Could not connect to MercadoBitcoin API."
end

def getTop(url)
exchanges = []
names = []
Expand Down Expand Up @@ -74,6 +88,7 @@ def getEx(url, symbol)
opt.separator "\tView all symbols at http://bitcoincharts.com/markets/"
opt.separator "\t*Popular markets below*"
opt.separator ""
opt.separator "\tmercadobitcoin - Mercado Bitcoin - Brasil"
opt.separator "\tmtgoxUSD - Mt.Gox USA"
opt.separator "\tbtcnCHY - BTC CHINA"
opt.separator "\tbitstampUSD - BitStamp USA"
Expand All @@ -95,6 +110,7 @@ def getEx(url, symbol)
end.parse!

case ARGV[0]

when nil
info = getTop("http://api.bitcoincharts.com/v1/markets.json")
if options[:verbose]
Expand All @@ -106,14 +122,42 @@ def getEx(url, symbol)
puts info[1]
else
table.head = ["Exchange", "Price"]
info[1].each_with_index do |quote, i|
message = "%s" % quote["ask"]
verbose_message = "high :: %s\t\tlow :: %s\nask :: %s\t\tbid :: %s\nclose :: %s\t\t\tavg :: %s" % [quote["high"], quote["low"], quote["ask"], quote["bid"], quote["close"], quote["avg"]]
table.rows << [info[2][i], message]
mercadobitcoin_info = getMercadoBitcoin()
if mercadobitcoin_info[0] == false
puts mercadobitcoin_info[1]
else
table.rows << ["Mercado Bitcoin (Reais)", mercadobitcoin_info[1]["buy"]]

info[1].each_with_index do |quote, i|
message = "%s" % quote["ask"]
verbose_message = "high :: %s\t\tlow :: %s\nask :: %s\t\tbid :: %s\nclose :: %s\t\t\tavg :: %s" % [quote["high"], quote["low"], quote["ask"], quote["bid"], quote["close"], quote["avg"]]
table.rows << [info[2][i], message]
end
end

puts table.to_s
end

when "mercadobitcoin"
info = getMercadoBitcoin()

if info[0] == false
puts info[1]

elsif info[0] == true

quote = info[1]
message = "%s" % quote["buy"]
table.rows = [["high", quote["high"].to_s],["low", quote["low"]], ["last", quote["last"]],["buy", quote["buy"]], ["sell", quote["sell"]]]

if options[:verbose]
puts table.to_s
else
puts message
end
end


else
info = getEx("http://api.bitcoincharts.com/v1/markets.json", ARGV[0])
if info[0] == false
Expand Down
0