cryptoexchange 0.1.1 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -12
  3. data/cryptoexchange.gemspec +2 -0
  4. data/lib/cryptoexchange.rb +5 -12
  5. data/lib/cryptoexchange/client.rb +46 -0
  6. data/lib/cryptoexchange/exchanges/anx/anx.yml +27 -0
  7. data/lib/cryptoexchange/exchanges/anx/market.rb +8 -0
  8. data/lib/cryptoexchange/exchanges/anx/models/market_pair.rb +8 -0
  9. data/lib/cryptoexchange/exchanges/anx/models/ticker.rb +8 -0
  10. data/lib/cryptoexchange/exchanges/anx/services/market.rb +41 -0
  11. data/lib/cryptoexchange/exchanges/anx/services/pairs.rb +25 -0
  12. data/lib/cryptoexchange/exchanges/bitcoin_indonesia/bitcoin_indonesia.yml +19 -0
  13. data/lib/cryptoexchange/exchanges/bitcoin_indonesia/market.rb +8 -0
  14. data/lib/cryptoexchange/exchanges/bitcoin_indonesia/models/market_pair.rb +8 -0
  15. data/lib/cryptoexchange/exchanges/bitcoin_indonesia/models/ticker.rb +8 -0
  16. data/lib/cryptoexchange/exchanges/bitcoin_indonesia/services/market.rb +41 -0
  17. data/lib/cryptoexchange/exchanges/bitcoin_indonesia/services/pairs.rb +25 -0
  18. data/lib/cryptoexchange/exchanges/bitflyer/services/market.rb +8 -2
  19. data/lib/cryptoexchange/exchanges/bitflyer/services/pairs.rb +1 -2
  20. data/lib/cryptoexchange/exchanges/bitstamp/bitstamp.yml +19 -0
  21. data/lib/cryptoexchange/exchanges/bitstamp/market.rb +8 -0
  22. data/lib/cryptoexchange/exchanges/bitstamp/models/market_pair.rb +8 -0
  23. data/lib/cryptoexchange/exchanges/bitstamp/models/ticker.rb +8 -0
  24. data/lib/cryptoexchange/exchanges/bitstamp/services/market.rb +40 -0
  25. data/lib/cryptoexchange/exchanges/bitstamp/services/pairs.rb +26 -0
  26. data/lib/cryptoexchange/exchanges/btcc/btcc.yml +5 -0
  27. data/lib/cryptoexchange/exchanges/btcc/market.rb +9 -0
  28. data/lib/cryptoexchange/exchanges/btcc/models/market_pair.rb +8 -0
  29. data/lib/cryptoexchange/exchanges/btcc/models/ticker.rb +8 -0
  30. data/lib/cryptoexchange/exchanges/btcc/services/market.rb +42 -0
  31. data/lib/cryptoexchange/exchanges/btcc/services/pairs.rb +25 -0
  32. data/lib/cryptoexchange/exchanges/coincheck/services/market.rb +8 -2
  33. data/lib/cryptoexchange/exchanges/coincheck/services/pairs.rb +1 -2
  34. data/lib/cryptoexchange/exchanges/coinone/services/market.rb +8 -2
  35. data/lib/cryptoexchange/exchanges/coinone/services/pairs.rb +1 -2
  36. data/lib/cryptoexchange/exchanges/cryptopia/services/market.rb +7 -2
  37. data/lib/cryptoexchange/exchanges/cryptopia/services/pairs.rb +1 -2
  38. data/lib/cryptoexchange/exchanges/gatecoin/services/market.rb +28 -27
  39. data/lib/cryptoexchange/exchanges/gatecoin/services/pairs.rb +1 -2
  40. data/lib/cryptoexchange/exchanges/gemini/market.rb +8 -0
  41. data/lib/cryptoexchange/exchanges/gemini/models/market_pair.rb +8 -0
  42. data/lib/cryptoexchange/exchanges/gemini/models/ticker.rb +8 -0
  43. data/lib/cryptoexchange/exchanges/gemini/services/market.rb +49 -0
  44. data/lib/cryptoexchange/exchanges/gemini/services/pairs.rb +28 -0
  45. data/lib/cryptoexchange/exchanges/korbit/services/market.rb +8 -2
  46. data/lib/cryptoexchange/exchanges/korbit/services/pairs.rb +1 -2
  47. data/lib/cryptoexchange/exchanges/liqui/market.rb +8 -0
  48. data/lib/cryptoexchange/exchanges/liqui/models/market_pair.rb +8 -0
  49. data/lib/cryptoexchange/exchanges/liqui/models/ticker.rb +8 -0
  50. data/lib/cryptoexchange/exchanges/liqui/services/market.rb +43 -0
  51. data/lib/cryptoexchange/exchanges/liqui/services/pairs.rb +27 -0
  52. data/lib/cryptoexchange/exchanges/livecoin/market.rb +8 -0
  53. data/lib/cryptoexchange/exchanges/livecoin/models/market_pair.rb +8 -0
  54. data/lib/cryptoexchange/exchanges/livecoin/models/ticker.rb +8 -0
  55. data/lib/cryptoexchange/exchanges/livecoin/services/market.rb +51 -0
  56. data/lib/cryptoexchange/exchanges/livecoin/services/pairs.rb +27 -0
  57. data/lib/cryptoexchange/exchanges/novaexchange/market.rb +8 -0
  58. data/lib/cryptoexchange/exchanges/novaexchange/models/market_pair.rb +8 -0
  59. data/lib/cryptoexchange/exchanges/novaexchange/models/ticker.rb +8 -0
  60. data/lib/cryptoexchange/exchanges/novaexchange/services/market.rb +44 -0
  61. data/lib/cryptoexchange/exchanges/novaexchange/services/pairs.rb +26 -0
  62. data/lib/cryptoexchange/exchanges/okcoin/market.rb +8 -0
  63. data/lib/cryptoexchange/exchanges/okcoin/models/market_pair.rb +8 -0
  64. data/lib/cryptoexchange/exchanges/okcoin/models/ticker.rb +8 -0
  65. data/lib/cryptoexchange/exchanges/okcoin/okcoin.yml +7 -0
  66. data/lib/cryptoexchange/exchanges/okcoin/services/market.rb +40 -0
  67. data/lib/cryptoexchange/exchanges/okcoin/services/pairs.rb +25 -0
  68. data/lib/cryptoexchange/helpers/string_helper.rb +7 -0
  69. data/lib/cryptoexchange/lru_ttl_cache.rb +7 -0
  70. data/lib/cryptoexchange/services/market.rb +15 -1
  71. data/lib/cryptoexchange/services/pairs.rb +7 -2
  72. data/lib/cryptoexchange/version.rb +1 -1
  73. metadata +69 -2
@@ -0,0 +1,8 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Okcoin
3
+ class Market
4
+ NAME = 'okcoin'
5
+ API_URL = 'https://www.okcoin.com/api/v1'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Okcoin
3
+ module Models
4
+ class MarketPair < Cryptoexchange::Models::MarketPair
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Okcoin
3
+ module Models
4
+ class Ticker < Cryptoexchange::Models::Ticker
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ :pairs:
2
+ - :base: BTC
3
+ :target: USD
4
+ - :base: LTC
5
+ :target: USD
6
+ - :base: ETH
7
+ :target: USD
@@ -0,0 +1,40 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Okcoin
3
+ module Services
4
+ class Market < Cryptoexchange::Services::Market
5
+ class << self
6
+ def supports_individual_ticker_query?
7
+ true
8
+ end
9
+ end
10
+
11
+ def fetch(market_pair)
12
+ output = super(ticker_url(market_pair))
13
+ adapt(output, market_pair)
14
+ end
15
+
16
+ def ticker_url(market_pair)
17
+ base = market_pair.base.downcase
18
+ target = market_pair.target.downcase
19
+ "#{Cryptoexchange::Exchanges::Okcoin::Market::API_URL}/ticker.do?symbol=#{base}_#{target}"
20
+ end
21
+
22
+ def adapt(output, market_pair)
23
+ ticker = Okcoin::Models::Ticker.new
24
+ ticker.base = market_pair.base
25
+ ticker.target = market_pair.target
26
+ ticker.market = Okcoin::Market::NAME
27
+ ticker.ask = output['ticker']['sell']
28
+ ticker.bid = output['ticker']['buy']
29
+ ticker.last = output['ticker']['last']
30
+ ticker.high = output['ticker']['high']
31
+ ticker.low = output['ticker']['low']
32
+ ticker.volume = output['ticker']['volume'].to_f
33
+ ticker.timestamp = output['date']
34
+ ticker.payload = output
35
+ ticker
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,25 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Okcoin
3
+ module Services
4
+ class Pairs < Cryptoexchange::Services::Pairs
5
+
6
+ def fetch
7
+ output = super
8
+ adapt(output)
9
+ end
10
+
11
+ def adapt(output)
12
+ market_pairs = []
13
+ output.each do |pair|
14
+ market_pairs << Okcoin::Models::MarketPair.new(
15
+ base: pair[:base],
16
+ target: pair[:target],
17
+ market: Okcoin::Market::NAME
18
+ )
19
+ end
20
+ market_pairs
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,7 @@
1
+ class StringHelper
2
+ class << self
3
+ def camelize(str)
4
+ str.split('_').map {|w| w.capitalize}.join
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ class LruTtlCache
2
+ class << self
3
+ def ticker_cache(ticker_ttl = 10)
4
+ @@ticker_cache ||= LruRedux::TTL::Cache.new(100, ticker_ttl)
5
+ end
6
+ end
7
+ end
@@ -1,9 +1,23 @@
1
1
  module Cryptoexchange
2
2
  module Services
3
3
  class Market
4
+ class << self
5
+ def supports_individual_ticker_query?
6
+ fail "Must define supports_individual_ticker_query? as true or false"
7
+ end
8
+ end
9
+
4
10
  def fetch(endpoint)
11
+ LruTtlCache.ticker_cache.getset(endpoint) do
12
+ response = http_get(endpoint)
13
+ JSON.parse(response.to_s)
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def http_get(endpoint)
5
20
  fetch_response = HTTP.get(endpoint)
6
- response = JSON.parse(fetch_response.to_s)
7
21
  end
8
22
  end
9
23
  end
@@ -27,11 +27,11 @@ module Cryptoexchange
27
27
  end
28
28
 
29
29
  def user_override_path
30
- "config/cryptoexchange/#{self.class::MARKET::NAME}.yml"
30
+ "config/cryptoexchange/#{exchange_class::NAME}.yml"
31
31
  end
32
32
 
33
33
  def default_override_path
34
- File.join(File.dirname(__dir__), "exchanges/#{self.class::MARKET::NAME}/#{self.class::MARKET::NAME}.yml")
34
+ File.join(File.dirname(__dir__), "exchanges/#{exchange_class::NAME}/#{exchange_class::NAME}.yml")
35
35
  end
36
36
 
37
37
  def user_override_exist?
@@ -41,6 +41,11 @@ module Cryptoexchange
41
41
  def default_override_exist?
42
42
  File.exist? default_override_path
43
43
  end
44
+
45
+ def exchange_class
46
+ exchange_name = self.class.name.split('::')[2]
47
+ Object.const_get "Cryptoexchange::Exchanges::#{exchange_name}::Market"
48
+ end
44
49
  end
45
50
  end
46
51
  end
@@ -1,3 +1,3 @@
1
1
  module Cryptoexchange
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cryptoexchange
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - TM Lee
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-07-11 00:00:00.000000000 Z
11
+ date: 2017-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: lru_redux
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: Ruby library to query market data from cryptocurrency exchanges.
98
112
  email:
99
113
  - tm89lee@gmail.com
@@ -113,11 +127,36 @@ files:
113
127
  - bin/setup
114
128
  - cryptoexchange.gemspec
115
129
  - lib/cryptoexchange.rb
130
+ - lib/cryptoexchange/client.rb
131
+ - lib/cryptoexchange/exchanges/anx/anx.yml
132
+ - lib/cryptoexchange/exchanges/anx/market.rb
133
+ - lib/cryptoexchange/exchanges/anx/models/market_pair.rb
134
+ - lib/cryptoexchange/exchanges/anx/models/ticker.rb
135
+ - lib/cryptoexchange/exchanges/anx/services/market.rb
136
+ - lib/cryptoexchange/exchanges/anx/services/pairs.rb
137
+ - lib/cryptoexchange/exchanges/bitcoin_indonesia/bitcoin_indonesia.yml
138
+ - lib/cryptoexchange/exchanges/bitcoin_indonesia/market.rb
139
+ - lib/cryptoexchange/exchanges/bitcoin_indonesia/models/market_pair.rb
140
+ - lib/cryptoexchange/exchanges/bitcoin_indonesia/models/ticker.rb
141
+ - lib/cryptoexchange/exchanges/bitcoin_indonesia/services/market.rb
142
+ - lib/cryptoexchange/exchanges/bitcoin_indonesia/services/pairs.rb
116
143
  - lib/cryptoexchange/exchanges/bitflyer/market.rb
117
144
  - lib/cryptoexchange/exchanges/bitflyer/models/market_pair.rb
118
145
  - lib/cryptoexchange/exchanges/bitflyer/models/ticker.rb
119
146
  - lib/cryptoexchange/exchanges/bitflyer/services/market.rb
120
147
  - lib/cryptoexchange/exchanges/bitflyer/services/pairs.rb
148
+ - lib/cryptoexchange/exchanges/bitstamp/bitstamp.yml
149
+ - lib/cryptoexchange/exchanges/bitstamp/market.rb
150
+ - lib/cryptoexchange/exchanges/bitstamp/models/market_pair.rb
151
+ - lib/cryptoexchange/exchanges/bitstamp/models/ticker.rb
152
+ - lib/cryptoexchange/exchanges/bitstamp/services/market.rb
153
+ - lib/cryptoexchange/exchanges/bitstamp/services/pairs.rb
154
+ - lib/cryptoexchange/exchanges/btcc/btcc.yml
155
+ - lib/cryptoexchange/exchanges/btcc/market.rb
156
+ - lib/cryptoexchange/exchanges/btcc/models/market_pair.rb
157
+ - lib/cryptoexchange/exchanges/btcc/models/ticker.rb
158
+ - lib/cryptoexchange/exchanges/btcc/services/market.rb
159
+ - lib/cryptoexchange/exchanges/btcc/services/pairs.rb
121
160
  - lib/cryptoexchange/exchanges/coincheck/coincheck.yml
122
161
  - lib/cryptoexchange/exchanges/coincheck/market.rb
123
162
  - lib/cryptoexchange/exchanges/coincheck/models/market_pair.rb
@@ -139,12 +178,40 @@ files:
139
178
  - lib/cryptoexchange/exchanges/gatecoin/models/ticker.rb
140
179
  - lib/cryptoexchange/exchanges/gatecoin/services/market.rb
141
180
  - lib/cryptoexchange/exchanges/gatecoin/services/pairs.rb
181
+ - lib/cryptoexchange/exchanges/gemini/market.rb
182
+ - lib/cryptoexchange/exchanges/gemini/models/market_pair.rb
183
+ - lib/cryptoexchange/exchanges/gemini/models/ticker.rb
184
+ - lib/cryptoexchange/exchanges/gemini/services/market.rb
185
+ - lib/cryptoexchange/exchanges/gemini/services/pairs.rb
142
186
  - lib/cryptoexchange/exchanges/korbit/korbit.yml
143
187
  - lib/cryptoexchange/exchanges/korbit/market.rb
144
188
  - lib/cryptoexchange/exchanges/korbit/models/market_pair.rb
145
189
  - lib/cryptoexchange/exchanges/korbit/models/ticker.rb
146
190
  - lib/cryptoexchange/exchanges/korbit/services/market.rb
147
191
  - lib/cryptoexchange/exchanges/korbit/services/pairs.rb
192
+ - lib/cryptoexchange/exchanges/liqui/market.rb
193
+ - lib/cryptoexchange/exchanges/liqui/models/market_pair.rb
194
+ - lib/cryptoexchange/exchanges/liqui/models/ticker.rb
195
+ - lib/cryptoexchange/exchanges/liqui/services/market.rb
196
+ - lib/cryptoexchange/exchanges/liqui/services/pairs.rb
197
+ - lib/cryptoexchange/exchanges/livecoin/market.rb
198
+ - lib/cryptoexchange/exchanges/livecoin/models/market_pair.rb
199
+ - lib/cryptoexchange/exchanges/livecoin/models/ticker.rb
200
+ - lib/cryptoexchange/exchanges/livecoin/services/market.rb
201
+ - lib/cryptoexchange/exchanges/livecoin/services/pairs.rb
202
+ - lib/cryptoexchange/exchanges/novaexchange/market.rb
203
+ - lib/cryptoexchange/exchanges/novaexchange/models/market_pair.rb
204
+ - lib/cryptoexchange/exchanges/novaexchange/models/ticker.rb
205
+ - lib/cryptoexchange/exchanges/novaexchange/services/market.rb
206
+ - lib/cryptoexchange/exchanges/novaexchange/services/pairs.rb
207
+ - lib/cryptoexchange/exchanges/okcoin/market.rb
208
+ - lib/cryptoexchange/exchanges/okcoin/models/market_pair.rb
209
+ - lib/cryptoexchange/exchanges/okcoin/models/ticker.rb
210
+ - lib/cryptoexchange/exchanges/okcoin/okcoin.yml
211
+ - lib/cryptoexchange/exchanges/okcoin/services/market.rb
212
+ - lib/cryptoexchange/exchanges/okcoin/services/pairs.rb
213
+ - lib/cryptoexchange/helpers/string_helper.rb
214
+ - lib/cryptoexchange/lru_ttl_cache.rb
148
215
  - lib/cryptoexchange/models/market_pair.rb
149
216
  - lib/cryptoexchange/models/ticker.rb
150
217
  - lib/cryptoexchange/services/market.rb