mbtc 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3f9630d945ddccd2c485443c6eaa0e4a84ea18ef
4
+ data.tar.gz: a5edd9e9e44ff352e659561adea98876d4c314b0
5
+ SHA512:
6
+ metadata.gz: 6d74dde7224e302fe678f68537b35ad3ec1ae3918812f77d68f3d67efeee13e4f7761efda4fe89aab532916b34e9485fe91e3439227f4d3b0a65b6551c6fc8b1
7
+ data.tar.gz: 27d81a87d930a3e074d675a76a334c0aefe9354af46f2082223a62e28358ad7a313b8ec5019765bc63155a47f3ef0017481d8ee12d44b6c5ecceff5b4fed60e1
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ lib/bundler/man
9
+ pkg
10
+ rdoc
11
+ spec/reports
12
+ test/tmp
13
+ test/version_tmp
14
+ tmp
15
+
16
+ # YARD artifacts
17
+ .yardoc
18
+ _yardoc
19
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mbtc.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Marcos Trovilho
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ mbtc
2
+ ====
3
+
4
+ CLI para [Mercado Bitcoin](http://www.mercadobitcoin.com.br/)
5
+
6
+
7
+ Instalação
8
+ ----------
9
+
10
+ Adicione essa linha no Gemfile:
11
+
12
+ gem 'mbtc'
13
+
14
+ Execute:
15
+
16
+ $ bundle
17
+
18
+ Ou instale você mesmo:
19
+
20
+ $ gem install mbtc
21
+
22
+
23
+ Uso
24
+ ---
25
+
26
+ mercado = MBTC.Mercado.new( < :btc ou :ltc > ) # o padrão é :btc
27
+
28
+ # Ticker:
29
+ ticker = mercado.ticker
30
+
31
+ # Orderbook:
32
+ orderbook = mercado.orderbook
33
+
34
+ # Trades:
35
+ trades = mercado.trades
36
+
37
+
38
+ CLI
39
+ ---
40
+
41
+ $ mbtc [opções] [comando]
42
+
43
+ Opções:
44
+ -h, --help Mostra ajuda
45
+ --version Mostra versão
46
+ --log-level LEVEL Define o log level
47
+ (debug|info|warn|error|fatal)
48
+ (Padrão: info)
49
+ -t, --type TYPE Tipo do request (btc ou ltc)
50
+ (Padrão: btc)
51
+
52
+ Comandos:
53
+ ticker
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/bin/mbtc ADDED
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env ruby
2
+ require 'methadone'
3
+ require 'mbtc'
4
+
5
+ include Methadone::Main
6
+ include Methadone::CLILogging
7
+
8
+ def print_ticker( ticker, type )
9
+ logger.info( "===== Ticker #{type.upcase} =====" )
10
+ logger.info( "Última:\t#{ticker.last}" )
11
+ logger.info( "Compra:\t#{ticker.buy}" )
12
+ logger.info( "Venda:\t#{ticker.sell}" )
13
+ logger.info( "Maior:\t#{ticker.high}" )
14
+ logger.info( "Menor:\t#{ticker.low}" )
15
+ logger.info( "Volume:\t#{ticker.vol}" )
16
+ logger.info( "Data:\t#{Time.at( ticker.date ).utc}" )
17
+ end
18
+
19
+ def print_orderbook( orderbook, type )
20
+ logger.info( "===== Order Book #{type.upcase} =====" )
21
+ # TODO: implement
22
+ end
23
+
24
+ def print_trades( trades, type )
25
+ logger.info( "===== Trades #{type.upcase} =====" )
26
+ # TODO: implement
27
+ end
28
+
29
+ main do |command|
30
+ logger.debug( "command: #{command.inspect}" )
31
+ logger.debug( "options: #{options.inspect}" )
32
+
33
+ request_type = options[:type]
34
+ logger.debug( "initilizing MBTC::Mercado with type: #{request_type}" )
35
+ m = MBTC::Mercado.new( request_type.to_sym )
36
+
37
+ if command.nil?
38
+ logger.debug( 'nil command, setting to ticker' )
39
+ command = 'ticker'
40
+ end
41
+
42
+ case command
43
+ when 'ticker', 't'
44
+ logger.debug( 'executing ticker' )
45
+ print_ticker( m.ticker, request_type )
46
+ when 'orderbook', 'ob', 'o'
47
+ logger.error( 'not implemented' )
48
+ # logger.debug( 'executing orderbook' )
49
+ # print_orderbook( m.orderbook, request_type )
50
+ when 'trades'
51
+ logger.error( 'not implemented' )
52
+ # logger.debug( 'executing trades' )
53
+ # print_trades( m.trades, request_type )
54
+ else
55
+ help_now!( 'invalid command' )
56
+ end
57
+ end
58
+
59
+ version MBTC::VERSION
60
+ description 'Mercado Bitcoin CLI'
61
+ use_log_level_option
62
+ options['type'] = 'btc'
63
+ on( '-t TYPE', '--type', 'Request type (btc ou ltc)' )
64
+ go!
data/lib/mbtc/api.rb ADDED
@@ -0,0 +1,60 @@
1
+ require 'httparty'
2
+
3
+ module MBTC
4
+ class API
5
+ include HTTParty
6
+ base_uri 'https://www.mercadobitcoin.com.br/api'
7
+
8
+ ##
9
+ # GET Ticker request
10
+ #
11
+ # @param type [Symbol] Tipo de request `:btc` ou `:ltc`
12
+ # @return [HTTParty::Response] Retorna o ticker de preço
13
+ #
14
+ def self.ticker( type = :btc )
15
+ case type
16
+ when :btc
17
+ endpoint = '/ticker/'
18
+ when :ltc
19
+ endpoint = '/ticker_litecoin/'
20
+ end
21
+
22
+ get( endpoint )
23
+ end
24
+
25
+ ##
26
+ # GET Orderbook request
27
+ #
28
+ # @param type [Symbol] Tipo de request `:btc` ou `:ltc`
29
+ # @return [HTTParty::Response] Retorna as ofertas de compra e venda
30
+ #
31
+ def self.orderbook( type = :btc )
32
+ case type
33
+ when :btc
34
+ endpoint = '/orderbook/'
35
+ when :ltc
36
+ endpoint = '/orderbook_litecoin/'
37
+ end
38
+
39
+ get( endpoint )
40
+ end
41
+
42
+ ##
43
+ # GET Trades request
44
+ #
45
+ # @param type [Symbol] Tipo de request `:btc` ou `:ltc`
46
+ # @return [HTTParty::Response] Retorna as negociações ou operações realizadas
47
+ #
48
+ def self.trades( type = :btc )
49
+ case type
50
+ when :btc
51
+ endpoint = '/trades/'
52
+ when :ltc
53
+ endpoint = '/trades_litecoin/'
54
+ end
55
+
56
+ get( endpoint )
57
+ end
58
+
59
+ end
60
+ end
@@ -0,0 +1,39 @@
1
+ module MBTC
2
+ ##
3
+ # Order
4
+ #
5
+ # price: preço unitário em Reais
6
+ # volume: volume disponível
7
+ #
8
+ class Order
9
+ attr_reader :price
10
+ attr_reader :volume
11
+
12
+ def initialize( price, volume )
13
+ @price = price
14
+ @volume = volume
15
+ end
16
+ end
17
+
18
+ ##
19
+ # Orderbook
20
+ #
21
+ # asks [Array<Order>] lista das ofertas de venda disponíveis.
22
+ # bids [Array<Order>] lista das ofertas de compra disponíveis.
23
+ #
24
+ class Orderbook
25
+ attr_reader :asks
26
+ attr_reader :bids
27
+
28
+ def initialize( params )
29
+ @asks = params["asks"].collect do |ask|
30
+ Order.new( ask[0], ask[1] )
31
+ end
32
+
33
+ @bids = params["bids"].collect do |bid|
34
+ Order.new( bid[0], bid[1] )
35
+ end
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,29 @@
1
+ module MBTC
2
+ ##
3
+ # Ticker
4
+ #
5
+ # high: maior valor em Reais de negociação do dia.
6
+ # low: menor valor em Reais de negociação do dia.
7
+ # vol: volume de Bitcoin ou Litecoin negociado no dia.
8
+ # last: último valor em Reais negociado.
9
+ # buy: valor atual em Reais ofertado para compra.
10
+ # sell: valor atual em Reais ofertado para venda.
11
+ # date: timestamp da última atualização do ticker.
12
+ #
13
+ class Ticker
14
+ attr_reader :high
15
+ attr_reader :low
16
+ attr_reader :vol
17
+ attr_reader :last
18
+ attr_reader :buy
19
+ attr_reader :sell
20
+ attr_reader :date
21
+
22
+ def initialize( params = {} )
23
+ params.each do |k,v|
24
+ self.instance_variable_set( "@#{k}", v )
25
+ end
26
+ end
27
+
28
+ end
29
+ end
data/lib/mbtc/trade.rb ADDED
@@ -0,0 +1,23 @@
1
+ module MBTC
2
+ ##
3
+ # Trade
4
+ #
5
+ # date: timestamp da operação.
6
+ # price: preço unitário em Reais da operação.
7
+ # amount: volume de Litecoin ou Bitcoin da operação.
8
+ # tid: ID da operação.
9
+ #
10
+ class Trade
11
+ attr_reader :date
12
+ attr_reader :price
13
+ attr_reader :amount
14
+ attr_reader :tid
15
+
16
+ def initialize( params = {} )
17
+ params.each do |k,v|
18
+ self.instance_variable_set( "@#{k}", v )
19
+ end
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module MBTC
2
+ VERSION = '0.0.1'
3
+ end
data/lib/mbtc.rb ADDED
@@ -0,0 +1,51 @@
1
+ require 'mbtc/version'
2
+ require 'mbtc/api'
3
+ require 'mbtc/ticker'
4
+ require 'mbtc/orderbook'
5
+ require 'mbtc/trade'
6
+
7
+ module MBTC
8
+ class Mercado
9
+
10
+ # @param type [Symbol] Tipo de request (:btc ou :ltc)
11
+ def initialize( type = :btc )
12
+ @type = type
13
+ end
14
+
15
+ ##
16
+ # Ticker
17
+ #
18
+ # @return [Ticker] Retorna o ticker de preço
19
+ #
20
+ def ticker
21
+ ticker_json = API.ticker( @type ).parsed_response
22
+ response = JSON.parse( ticker_json )
23
+ Ticker.new( response["ticker"] )
24
+ end
25
+
26
+ ##
27
+ # Orderbook
28
+ #
29
+ # @return [Orderbook] Retorna as ofertas de compra e venda
30
+ #
31
+ def orderbook
32
+ orderbook_json = API.orderbook( @type ).parsed_response
33
+ response = JSON.parse( orderbook_json )
34
+ Orderbook.new( response )
35
+ end
36
+
37
+ ##
38
+ # Trades
39
+ #
40
+ # @return [Array] Retorna as negociações ou operações realizadas
41
+ #
42
+ def trades
43
+ trades_json = API.trades( @type ).parsed_response
44
+ response = JSON.parse( trades_json )
45
+ response.collect do |trade|
46
+ Trade.new( trade )
47
+ end
48
+ end
49
+
50
+ end
51
+ end
data/mbtc.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mbtc/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'mbtc'
8
+ spec.version = MBTC::VERSION
9
+ spec.authors = ['Marcos Trovilho']
10
+ spec.email = ['marcos@trovilho.com']
11
+ spec.description = %q{CLI para Mercado Bitcoin}
12
+ spec.summary = %q{CLI para Mercado Bitcoin}
13
+ spec.homepage = 'https://github.com/mtrovilho/mbtc.git'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'methadone', '~> 1.3.1'
22
+ spec.add_dependency 'httparty', '~> 0.12.0'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.3.5'
25
+ spec.add_development_dependency 'rake', '~> 10.1.1'
26
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mbtc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Marcos Trovilho
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: methadone
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 1.3.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 1.3.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: httparty
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.12.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.12.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 1.3.5
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.3.5
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 10.1.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 10.1.1
69
+ description: CLI para Mercado Bitcoin
70
+ email:
71
+ - marcos@trovilho.com
72
+ executables:
73
+ - mbtc
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - Gemfile
79
+ - LICENSE
80
+ - README.md
81
+ - Rakefile
82
+ - bin/mbtc
83
+ - lib/mbtc.rb
84
+ - lib/mbtc/api.rb
85
+ - lib/mbtc/orderbook.rb
86
+ - lib/mbtc/ticker.rb
87
+ - lib/mbtc/trade.rb
88
+ - lib/mbtc/version.rb
89
+ - mbtc.gemspec
90
+ homepage: https://github.com/mtrovilho/mbtc.git
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.1.11
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: CLI para Mercado Bitcoin
114
+ test_files: []
115
+ has_rdoc: