mcoin 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4e02e930754307c6029c989977a57bb28f4301c2
4
- data.tar.gz: aa7664da661554e458f2d05c58746542d4c54a01
3
+ metadata.gz: ea7433590b7f0979f367b292a76590eacd5db058
4
+ data.tar.gz: d42319799e8e2248f12c1a52a2eeeed85ee69aca
5
5
  SHA512:
6
- metadata.gz: c64f029e2f6c51948cad461e74fc6eb182d5ffb89a34c21e4659dd0bf61fdf112e180fed85c7a5ade85a4d467c59c7a8fb8d7a643b44e3eea21c63fe65549772
7
- data.tar.gz: 843dfefd522eac65ee6c338aabd83a6ebe2e83bcee294b2c6ff804c46f16d8e2a48393d6b4513a66bf44dd296819999eb03968a7e8939bfba3a57ebeec4f3076
6
+ metadata.gz: 1d7b9d7616dcf7b429098dc2657da4e577eeec167c6ef7f84fbd78fa54d8f4a35a0cff8dcea9ce4a91b18f916538c5b2621bbdaa1580d258c02ab7d4cbb2a5a8
7
+ data.tar.gz: 698c2c86862ea27a2e4a32f60168a04d0423a4102fd27f3b9e47a7ececde1b5ad6fd57e08d2ffddfe5adc85f0733f0b9169375652e41b7cc877f4bffc7fd07e8
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mcoin (0.2.1)
4
+ mcoin (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -23,4 +23,4 @@ DEPENDENCIES
23
23
  rake (~> 10.0)
24
24
 
25
25
  BUNDLED WITH
26
- 1.16.0
26
+ 1.16.1
data/README.md CHANGED
@@ -37,6 +37,22 @@ mcoin ticker -m Bitfinex -d monitor -e http://localhsot:8086
37
37
 
38
38
  To get more information please use `-h` option.
39
39
 
40
+ ### Subscriber
41
+
42
+ If you want to subscribe market in your project, you can use `Subscriber`
43
+
44
+ ```ruby
45
+ require 'mcoin'
46
+
47
+ # Leave blank to subscribe all available market
48
+ subscriber = Mcoin::Subscriber.new([:Bitinfex], :BTC, :USD)
49
+ subscriber.start do |ticker|
50
+ # Deal with Mcoin::Data::Ticker object
51
+ end
52
+ ```
53
+
54
+ Please note, the ticker is async pull data from market, the timestamp may not totally same when you receive it.
55
+
40
56
  ## Roadmap
41
57
 
42
58
  * [x] Fetch ticker
@@ -13,4 +13,5 @@ module Mcoin
13
13
  autoload :Printer, 'mcoin/printer'
14
14
  autoload :Parallel, 'mcoin/parallel'
15
15
  autoload :InfluxDB, 'mcoin/influx_db'
16
+ autoload :Subscriber, 'mcoin/subscriber'
16
17
  end
@@ -9,6 +9,12 @@ module Mcoin
9
9
  Thread.new { item.send(method) }
10
10
  end.map(&:join).map(&:value)
11
11
  end
12
+
13
+ def async(array, method, &block)
14
+ array.each do |item|
15
+ Thread.new { yield item.send(method) }
16
+ end
17
+ end
12
18
  end
13
19
  end
14
20
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mcoin
4
+ class Subscriber
5
+ attr_reader :markets
6
+
7
+ def initialize(picked = Market.available, type = :BTC, currency = :USD)
8
+ @markets = markets_from(picked, type, currency)
9
+ end
10
+
11
+ def start(interval = 1, &block)
12
+ loop do
13
+ Parallel.async(markets, :fetch) do |result|
14
+ yield result.to_ticker
15
+ end
16
+ sleep interval
17
+ end
18
+ end
19
+
20
+ protected
21
+
22
+ def markets_from(picked, type, currency)
23
+ @markets ||= picked.map do |name|
24
+ Market
25
+ .pick(name)
26
+ .new(type, currency)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mcoin
4
- VERSION = '0.2.1'
4
+ VERSION = '0.3.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mcoin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - 蒼時弦也
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-02 00:00:00.000000000 Z
11
+ date: 2018-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -74,6 +74,7 @@ files:
74
74
  - lib/mcoin/market/kraken.rb
75
75
  - lib/mcoin/parallel.rb
76
76
  - lib/mcoin/printer.rb
77
+ - lib/mcoin/subscriber.rb
77
78
  - lib/mcoin/version.rb
78
79
  - mcoin.gemspec
79
80
  homepage: https://github.com/elct9620/mcoin
@@ -95,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
96
  version: '0'
96
97
  requirements: []
97
98
  rubyforge_project:
98
- rubygems_version: 2.6.13
99
+ rubygems_version: 2.6.14
99
100
  signing_key:
100
101
  specification_version: 4
101
102
  summary: The BTC market monitor tool