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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c69eda62aac34e8e46b331cbb04b8d924ca2ac83
4
- data.tar.gz: e8e20d35a3139eae3ef8e68bc479bdad0f903016
3
+ metadata.gz: 1df6ea7c91d604d8106be0681b0ba54e90a6a95a
4
+ data.tar.gz: a91d02633e2906ed8ac6d61c5e02720511abf698
5
5
  SHA512:
6
- metadata.gz: a7d7c3ffc9b5c28cc086e874b67911d1b20c833a1b48fc18bbec3c0ae7cb635803340a6f77eb49665dbf0004dec24d1245caebf61f104e2f19ffe7c85c539e7b
7
- data.tar.gz: e817df96f2a9ebe3464cda353e36fae2fef3c2ea6211a99643b51b18b15350d07b7a55f9afaea1c72f42b5cc730929938729b81736a6c7a4e994ec051f1e5dae
6
+ metadata.gz: d816e318bfaad472126cd330757d78375289585b6476a948d3ae7f86b9939edb0a2de888ad43a49c420a7b0c7ae1f0319b8df96f0174be3d54cf6cf93b995f31
7
+ data.tar.gz: 41cc533bbc4661992833b1fb9eeeb24d7c7bd8b7c91d4cab4bb704667d9942125f928b9d5dacbf9ca9a4b1e0ff784525adeda03cb777ab2b231d179c7e5a81d2
data/README.md CHANGED
@@ -24,19 +24,19 @@ Or install it yourself as:
24
24
 
25
25
  | Exchange | Ticker | Order Book | Trade | Account | Market List |
26
26
  | ----------------- | ------- | ---------- | ------- | ------- | ----------- |
27
- | ANX | | | | | |
27
+ | ANX | Y | | | | User-Defined|
28
28
  | Gatecoin | Y | | | | Y |
29
- | BTCC | | | | | |
30
- | OKCoin | | | | | |
29
+ | BTCC | Y | | | | User-Defined|
30
+ | OKCoin | Y | | | | User-Defined|
31
31
  | LakeBTC | | | | | |
32
32
  | Huobi | | | | | |
33
33
  | Yunbi | | | | | |
34
34
  | BTC38 | | | | | |
35
35
  | CHBTC | | | | | |
36
- | Bitstamp | | | | | |
36
+ | Bitstamp | Y | | | | User-Defined|
37
37
  | Bittrex | | | | | |
38
38
  | GDAX | | | | | |
39
- | Gemini | | | | | |
39
+ | Gemini | Y | | | | Y |
40
40
  | Kraken | | | | | |
41
41
  | Poloniex | | | | | |
42
42
  | Coincheck | Y | | | | User-Defined|
@@ -54,21 +54,23 @@ Or install it yourself as:
54
54
  | Bitfinex | | | | | |
55
55
  | BTER | | | | | |
56
56
  | Cryptopia | Y | | | | Y |
57
- | Livecoin | | | | | |
58
- | Nova Exchange | | | | | |
59
- | Bitcoin Indonesia | | | | | |
57
+ | Livecoin | Y | | | | Y |
58
+ | Nova Exchange | Y | | | | Y |
59
+ | Bitcoin Indonesia | Y | | | | User-Defined|
60
+ | Liqui | Y | | | | Y |
60
61
 
61
62
  ## Usage
62
63
 
63
64
  ### List market pairs supported by an exchange
64
65
  ```
65
- Cryptoexchange::Exchanges::Bitflyer::Services::Pairs.new.fetch
66
+ client = Cryptoexchange::Client.new
67
+ pairs = client.pairs('bitflyer')
66
68
  ```
67
69
 
68
70
  ### Query the Ticker API
69
71
  ```
70
- pair = Cryptoexchange::Exchanges::Bitflyer::Services::Pairs.new.fetch.first
71
- ticker = Cryptoexchange::Exchanges::Bitflyer::Services::Market.new.fetch(pair)
72
+ pair = client.pairs('bitflyer').first
73
+ ticker = client.ticker(pairs.last)
72
74
  ticker.base
73
75
  ticker.target
74
76
  ticker.last
@@ -108,4 +110,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERN
108
110
  ## License
109
111
 
110
112
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
111
-
@@ -26,6 +26,8 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency "rspec", "~> 3.0"
27
27
  spec.add_development_dependency "pry"
28
28
  spec.add_development_dependency "rb-readline"
29
+
29
30
 
30
31
  spec.add_dependency "http"
32
+ spec.add_dependency "lru_redux"
31
33
  end
@@ -1,17 +1,13 @@
1
1
  require "cryptoexchange/version"
2
+ require "cryptoexchange/client"
3
+ require "cryptoexchange/lru_ttl_cache"
4
+ require "cryptoexchange/helpers/string_helper"
2
5
  require "cryptoexchange/models/ticker"
3
6
  require "cryptoexchange/models/market_pair"
4
7
  require "cryptoexchange/services/market"
5
8
  require "cryptoexchange/services/pairs"
6
9
 
7
- %w(
8
- bitflyer
9
- coincheck
10
- coinone
11
- korbit
12
- cryptopia
13
- gatecoin
14
- ).each do |market|
10
+ Cryptoexchange::Client::AVAILABLE_EXCHANGES.each do |market|
15
11
  require "cryptoexchange/exchanges/#{market}/market"
16
12
  require "cryptoexchange/exchanges/#{market}/models/ticker"
17
13
  require "cryptoexchange/exchanges/#{market}/models/market_pair"
@@ -20,7 +16,4 @@ require "cryptoexchange/services/pairs"
20
16
  end
21
17
 
22
18
  require "http"
23
-
24
- module Cryptoexchange
25
- # Your code goes here...
26
- end
19
+ require "lru_redux"
@@ -0,0 +1,46 @@
1
+ module Cryptoexchange
2
+ class Client
3
+ AVAILABLE_EXCHANGES = %w(
4
+ btcc
5
+ anx
6
+ bitcoin_indonesia
7
+ bitflyer
8
+ coincheck
9
+ coinone
10
+ korbit
11
+ cryptopia
12
+ gatecoin
13
+ livecoin
14
+ bitstamp
15
+ okcoin
16
+ novaexchange
17
+ liqui
18
+ gemini
19
+ )
20
+
21
+ def initialize(ticker_ttl: 3)
22
+ LruTtlCache.ticker_cache(ticker_ttl)
23
+ end
24
+
25
+ def pairs(exchange)
26
+ pairs_classname = "Cryptoexchange::Exchanges::#{StringHelper.camelize(exchange)}::Services::Pairs"
27
+ Object.const_get(pairs_classname).new.fetch
28
+ end
29
+
30
+ def ticker(market_pair)
31
+ exchange = market_pair.market
32
+ market_classname = "Cryptoexchange::Exchanges::#{StringHelper.camelize(exchange)}::Services::Market"
33
+ market_class = Object.const_get(market_classname)
34
+ market = market_class.new
35
+
36
+ if market_class.supports_individual_ticker_query?
37
+ market.fetch(market_pair)
38
+ else
39
+ tickers = market.fetch
40
+ tickers.find do |t|
41
+ t.base == market_pair.base && t.target == market_pair.target
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,27 @@
1
+ :pairs:
2
+ - :base: BTC
3
+ :target: USD
4
+ - :base: BTC
5
+ :target: HKD
6
+ - :base: BTC
7
+ :target: EUR
8
+ - :base: BTC
9
+ :target: CAD
10
+ - :base: BTC
11
+ :target: AUD
12
+ - :base: BTC
13
+ :target: SGD
14
+ - :base: BTC
15
+ :target: JPY
16
+ - :base: BTC
17
+ :target: GBP
18
+ - :base: BTC
19
+ :target: NZD
20
+ - :base: LTC
21
+ :target: BTC
22
+ - :base: DOGE
23
+ :target: BTC
24
+ - :base: STR
25
+ :target: BTC
26
+ - :base: XRP
27
+ :target: BTC
@@ -0,0 +1,8 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Anx
3
+ class Market
4
+ NAME = 'anx'
5
+ API_URL = 'https://anxpro.com/api/2'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Anx
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 Anx
3
+ module Models
4
+ class Ticker < Cryptoexchange::Models::Ticker
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,41 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Anx
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)
14
+ end
15
+
16
+ def ticker_url(market_pair)
17
+ "#{Cryptoexchange::Exchanges::Anx::Market::API_URL}/#{market_pair.base}#{market_pair.target}/money/ticker"
18
+ end
19
+
20
+ def adapt(output)
21
+ ticker = Anx::Models::Ticker.new
22
+ base = output['data']['vol']['currency']
23
+ target = output['data']['high']['currency']
24
+
25
+ ticker.base = base
26
+ ticker.target = target
27
+ ticker.market = Anx::Market::NAME
28
+ ticker.ask = output['data']['sell']['value']
29
+ ticker.bid = output['data']['buy']['value']
30
+ ticker.last = output['data']['last']['value']
31
+ ticker.high = output['data']['high']['value']
32
+ ticker.low = output['data']['low']['value']
33
+ ticker.volume = output['data']['vol']['value']
34
+ ticker.timestamp = output['data']['dataUpdateTime']
35
+ ticker.payload = output
36
+ ticker
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,25 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Anx
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 << Anx::Models::MarketPair.new(
15
+ base: pair[:base],
16
+ target: pair[:target],
17
+ market: Anx::Market::NAME
18
+ )
19
+ end
20
+ market_pairs
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,19 @@
1
+ :pairs:
2
+ - :base: BTC
3
+ :target: IDR
4
+ - :base: ETH
5
+ :target: BTC
6
+ - :base: DOGE
7
+ :target: BTC
8
+ - :base: BTS
9
+ :target: BTC
10
+ - :base: LTC
11
+ :target: BTC
12
+ - :base: STR
13
+ :target: BTC
14
+ - :base: NXT
15
+ :target: BTC
16
+ - :base: XRP
17
+ :target: BTC
18
+ - :base: NEM
19
+ :target: BTC
@@ -0,0 +1,8 @@
1
+ module Cryptoexchange::Exchanges
2
+ module BitcoinIndonesia
3
+ class Market
4
+ NAME = 'bitcoin_indonesia'
5
+ API_URL = 'https://vip.bitcoin.co.id/api'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Cryptoexchange::Exchanges
2
+ module BitcoinIndonesia
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 BitcoinIndonesia
3
+ module Models
4
+ class Ticker < Cryptoexchange::Models::Ticker
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,41 @@
1
+ module Cryptoexchange::Exchanges
2
+ module BitcoinIndonesia
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::BitcoinIndonesia::Market::API_URL}/#{base}_#{target}/ticker"
20
+ end
21
+
22
+ def adapt(output, market_pair)
23
+ output = output['ticker']
24
+ ticker = BitcoinIndonesia::Models::Ticker.new
25
+ ticker.base = market_pair.base
26
+ ticker.target = market_pair.target
27
+ ticker.market = BitcoinIndonesia::Market::NAME
28
+ ticker.bid = output['buy']
29
+ ticker.ask = output['sell']
30
+ ticker.last = output['last']
31
+ ticker.high = output['high']
32
+ ticker.low = output['low']
33
+ ticker.volume = output["vol_#{ticker.base.downcase}"].to_f
34
+ ticker.timestamp = output['server_time']
35
+ ticker.payload = output
36
+ ticker
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,25 @@
1
+ module Cryptoexchange::Exchanges
2
+ module BitcoinIndonesia
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 << BitcoinIndonesia::Models::MarketPair.new(
15
+ base: pair[:base],
16
+ target: pair[:target],
17
+ market: BitcoinIndonesia::Market::NAME
18
+ )
19
+ end
20
+ market_pairs
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -2,12 +2,18 @@ module Cryptoexchange::Exchanges
2
2
  module Bitflyer
3
3
  module Services
4
4
  class Market < Cryptoexchange::Services::Market
5
+ class << self
6
+ def supports_individual_ticker_query?
7
+ true
8
+ end
9
+ end
10
+
5
11
  def fetch(market_pair)
6
- output = super(market_url(market_pair))
12
+ output = super(ticker_url(market_pair))
7
13
  adapt(output)
8
14
  end
9
15
 
10
- def market_url(market_pair)
16
+ def ticker_url(market_pair)
11
17
  "#{Cryptoexchange::Exchanges::Bitflyer::Market::API_URL}/ticker?product_code=#{market_pair.base}_#{market_pair.target}"
12
18
  end
13
19
 
@@ -2,7 +2,6 @@ module Cryptoexchange::Exchanges
2
2
  module Bitflyer
3
3
  module Services
4
4
  class Pairs < Cryptoexchange::Services::Pairs
5
- MARKET = Bitflyer::Market
6
5
  PAIRS_URL = "#{Cryptoexchange::Exchanges::Bitflyer::Market::API_URL}/markets"
7
6
 
8
7
  def fetch
@@ -21,7 +20,7 @@ module Cryptoexchange::Exchanges
21
20
  market_pairs << Bitflyer::Models::MarketPair.new(
22
21
  base: base,
23
22
  target: target,
24
- market: MARKET::NAME
23
+ market: Bitflyer::Market::NAME
25
24
  )
26
25
  end
27
26
  end