cryptoexchange 0.2.1 → 0.3.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 (71) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +16 -5
  3. data/lib/cryptoexchange.rb +3 -1
  4. data/lib/cryptoexchange/client.rb +5 -17
  5. data/lib/cryptoexchange/exchanges/anx/services/market.rb +11 -11
  6. data/lib/cryptoexchange/exchanges/bitcoin_indonesia/services/market.rb +13 -13
  7. data/lib/cryptoexchange/exchanges/bitflyer/services/market.rb +10 -10
  8. data/lib/cryptoexchange/exchanges/bithumb/bithumb.yml +13 -0
  9. data/lib/cryptoexchange/exchanges/bithumb/market.rb +8 -0
  10. data/lib/cryptoexchange/exchanges/bithumb/models/market_pair.rb +8 -0
  11. data/lib/cryptoexchange/exchanges/bithumb/models/ticker.rb +8 -0
  12. data/lib/cryptoexchange/exchanges/bithumb/services/market.rb +40 -0
  13. data/lib/cryptoexchange/exchanges/bithumb/services/pairs.rb +26 -0
  14. data/lib/cryptoexchange/exchanges/bitstamp/market.rb +1 -1
  15. data/lib/cryptoexchange/exchanges/bitstamp/services/market.rb +13 -13
  16. data/lib/cryptoexchange/exchanges/bittrex/market.rb +8 -0
  17. data/lib/cryptoexchange/exchanges/bittrex/models/market_pair.rb +8 -0
  18. data/lib/cryptoexchange/exchanges/bittrex/models/ticker.rb +8 -0
  19. data/lib/cryptoexchange/exchanges/bittrex/services/market.rb +42 -0
  20. data/lib/cryptoexchange/exchanges/bittrex/services/pairs.rb +28 -0
  21. data/lib/cryptoexchange/exchanges/bleutrade/market.rb +8 -0
  22. data/lib/cryptoexchange/exchanges/bleutrade/models/market_pair.rb +8 -0
  23. data/lib/cryptoexchange/exchanges/bleutrade/models/ticker.rb +8 -0
  24. data/lib/cryptoexchange/exchanges/bleutrade/services/market.rb +50 -0
  25. data/lib/cryptoexchange/exchanges/bleutrade/services/pairs.rb +27 -0
  26. data/lib/cryptoexchange/exchanges/btcc/services/market.rb +12 -12
  27. data/lib/cryptoexchange/exchanges/bter/market.rb +8 -0
  28. data/lib/cryptoexchange/exchanges/bter/models/market_pair.rb +8 -0
  29. data/lib/cryptoexchange/exchanges/bter/models/ticker.rb +8 -0
  30. data/lib/cryptoexchange/exchanges/bter/services/market.rb +38 -0
  31. data/lib/cryptoexchange/exchanges/bter/services/pairs.rb +26 -0
  32. data/lib/cryptoexchange/exchanges/ccex/market.rb +8 -0
  33. data/lib/cryptoexchange/exchanges/ccex/models/market_pair.rb +8 -0
  34. data/lib/cryptoexchange/exchanges/ccex/models/ticker.rb +8 -0
  35. data/lib/cryptoexchange/exchanges/ccex/services/market.rb +48 -0
  36. data/lib/cryptoexchange/exchanges/ccex/services/pairs.rb +26 -0
  37. data/lib/cryptoexchange/exchanges/coin_exchange/market.rb +8 -0
  38. data/lib/cryptoexchange/exchanges/coin_exchange/models/market_pair.rb +8 -0
  39. data/lib/cryptoexchange/exchanges/coin_exchange/models/ticker.rb +8 -0
  40. data/lib/cryptoexchange/exchanges/coin_exchange/services/market.rb +70 -0
  41. data/lib/cryptoexchange/exchanges/coin_exchange/services/pairs.rb +24 -0
  42. data/lib/cryptoexchange/exchanges/coincheck/services/market.rb +12 -12
  43. data/lib/cryptoexchange/exchanges/coinone/services/market.rb +10 -10
  44. data/lib/cryptoexchange/exchanges/cryptopia/services/market.rb +13 -13
  45. data/lib/cryptoexchange/exchanges/ether_delta/market.rb +8 -0
  46. data/lib/cryptoexchange/exchanges/ether_delta/models/market_pair.rb +8 -0
  47. data/lib/cryptoexchange/exchanges/ether_delta/models/ticker.rb +8 -0
  48. data/lib/cryptoexchange/exchanges/ether_delta/services/market.rb +41 -0
  49. data/lib/cryptoexchange/exchanges/ether_delta/services/pairs.rb +26 -0
  50. data/lib/cryptoexchange/exchanges/gatecoin/services/market.rb +11 -11
  51. data/lib/cryptoexchange/exchanges/gemini/services/market.rb +4 -4
  52. data/lib/cryptoexchange/exchanges/hitbtc/market.rb +8 -0
  53. data/lib/cryptoexchange/exchanges/hitbtc/models/market_pair.rb +8 -0
  54. data/lib/cryptoexchange/exchanges/hitbtc/models/ticker.rb +8 -0
  55. data/lib/cryptoexchange/exchanges/hitbtc/services/market.rb +42 -0
  56. data/lib/cryptoexchange/exchanges/hitbtc/services/pairs.rb +24 -0
  57. data/lib/cryptoexchange/exchanges/korbit/services/market.rb +12 -12
  58. data/lib/cryptoexchange/exchanges/lakebtc/market.rb +8 -0
  59. data/lib/cryptoexchange/exchanges/lakebtc/models/market_pair.rb +8 -0
  60. data/lib/cryptoexchange/exchanges/lakebtc/models/ticker.rb +8 -0
  61. data/lib/cryptoexchange/exchanges/lakebtc/services/market.rb +51 -0
  62. data/lib/cryptoexchange/exchanges/lakebtc/services/pairs.rb +29 -0
  63. data/lib/cryptoexchange/exchanges/liqui/services/market.rb +6 -6
  64. data/lib/cryptoexchange/exchanges/livecoin/services/market.rb +12 -12
  65. data/lib/cryptoexchange/exchanges/novaexchange/services/market.rb +13 -13
  66. data/lib/cryptoexchange/exchanges/novaexchange/services/pairs.rb +6 -2
  67. data/lib/cryptoexchange/exchanges/okcoin/services/market.rb +12 -12
  68. data/lib/cryptoexchange/helpers/hash_helper.rb +20 -0
  69. data/lib/cryptoexchange/helpers/numeric_helper.rb +7 -0
  70. data/lib/cryptoexchange/version.rb +1 -1
  71. metadata +50 -2
@@ -18,18 +18,18 @@ module Cryptoexchange::Exchanges
18
18
  end
19
19
 
20
20
  def adapt(output)
21
- ticker = Coincheck::Models::Ticker.new
22
- ticker.base = 'BTC'
23
- ticker.target = 'JPY'
24
- ticker.market = Coincheck::Market::NAME
25
- ticker.ask = output['ask']
26
- ticker.bid = output['bid']
27
- ticker.last = output['last']
28
- ticker.high = output['high']
29
- ticker.low = output['low']
30
- ticker.volume = output['volume'].to_f
31
- ticker.timestamp = output['timestamp']
32
- ticker.payload = output
21
+ ticker = Coincheck::Models::Ticker.new
22
+ ticker.base = 'BTC'
23
+ ticker.target = 'JPY'
24
+ ticker.market = Coincheck::Market::NAME
25
+ ticker.ask = NumericHelper.to_d(output['ask'])
26
+ ticker.bid = NumericHelper.to_d(output['bid'])
27
+ ticker.last = NumericHelper.to_d(output['last'])
28
+ ticker.high = NumericHelper.to_d(output['high'])
29
+ ticker.low = NumericHelper.to_d(output['low'])
30
+ ticker.volume = NumericHelper.to_d(output['volume'])
31
+ ticker.timestamp = output['timestamp'].to_i
32
+ ticker.payload = output
33
33
  ticker
34
34
  end
35
35
  end
@@ -19,16 +19,16 @@ module Cryptoexchange::Exchanges
19
19
  end
20
20
 
21
21
  def adapt(output)
22
- ticker = Coinone::Models::Ticker.new
23
- ticker.base = output['currency']
24
- ticker.target = 'KRW'
25
- ticker.market = Coinone::Market::NAME
26
- ticker.last = output['last']
27
- ticker.high = output['high']
28
- ticker.low = output['low']
29
- ticker.volume = output['volume']
30
- ticker.timestamp = output['timestamp']
31
- ticker.payload = output
22
+ ticker = Coinone::Models::Ticker.new
23
+ ticker.base = output['currency']
24
+ ticker.target = 'KRW'
25
+ ticker.market = Coinone::Market::NAME
26
+ ticker.last = NumericHelper.to_d(output['last'])
27
+ ticker.high = NumericHelper.to_d(output['high'])
28
+ ticker.low = NumericHelper.to_d(output['low'])
29
+ ticker.volume = NumericHelper.to_d(output['volume'])
30
+ ticker.timestamp = output['timestamp'].to_i
31
+ ticker.payload = output
32
32
  ticker
33
33
  end
34
34
  end
@@ -23,19 +23,19 @@ module Cryptoexchange::Exchanges
23
23
  data = output['Data']
24
24
  base, target = data['Label'].split('/')
25
25
 
26
- ticker = Cryptopia::Models::Ticker.new
27
- ticker.base = base
28
- ticker.target = target
29
- ticker.market = Cryptopia::Market::NAME
30
- ticker.last = data['LastPrice']
31
- ticker.bid = data['BidPrice']
32
- ticker.ask = data['AskPrice']
33
- ticker.high = data['High']
34
- ticker.low = data['Low']
35
- ticker.volume = data['Volume']
36
- ticker.change = data['Change']
37
- ticker.timestamp = DateTime.now.to_time.to_i
38
- ticker.payload = data
26
+ ticker = Cryptopia::Models::Ticker.new
27
+ ticker.base = base
28
+ ticker.target = target
29
+ ticker.market = Cryptopia::Market::NAME
30
+ ticker.last = NumericHelper.to_d(data['LastPrice'])
31
+ ticker.bid = NumericHelper.to_d(data['BidPrice'])
32
+ ticker.ask = NumericHelper.to_d(data['AskPrice'])
33
+ ticker.high = NumericHelper.to_d(data['High'])
34
+ ticker.low = NumericHelper.to_d(data['Low'])
35
+ ticker.volume = NumericHelper.to_d(data['Volume'])
36
+ ticker.change = NumericHelper.to_d(data['Change'])
37
+ ticker.timestamp = Time.now.to_i
38
+ ticker.payload = data
39
39
  ticker
40
40
  end
41
41
  end
@@ -0,0 +1,8 @@
1
+ module Cryptoexchange::Exchanges
2
+ module EtherDelta
3
+ class Market
4
+ NAME = 'ether_delta'
5
+ API_URL = 'https://cache1.etherdelta.com'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Cryptoexchange::Exchanges
2
+ module EtherDelta
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 EtherDelta
3
+ module Models
4
+ class Ticker < Cryptoexchange::Models::Ticker
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,41 @@
1
+ require 'bigdecimal'
2
+
3
+ module Cryptoexchange::Exchanges
4
+ module EtherDelta
5
+ module Services
6
+ class Market < Cryptoexchange::Services::Market
7
+ class << self
8
+ def supports_individual_ticker_query?
9
+ true
10
+ end
11
+ end
12
+
13
+ def fetch(market_pair)
14
+ output = super(ticker_url(market_pair))
15
+ adapt(output, market_pair)
16
+ end
17
+
18
+ def ticker_url(market_pair)
19
+ "#{Cryptoexchange::Exchanges::EtherDelta::Market::API_URL}/returnTicker"
20
+ end
21
+
22
+ def adapt(output, market_pair)
23
+ name = "#{market_pair.base}_#{market_pair.target}"
24
+ market = output[name]
25
+
26
+ ticker = EtherDelta::Models::Ticker.new
27
+ ticker.base = market_pair.base
28
+ ticker.target = market_pair.target
29
+ ticker.market = EtherDelta::Market::NAME
30
+ ticker.last = NumericHelper.to_d(market['last'].to_s)
31
+ ticker.bid = NumericHelper.to_d(market['bid'].to_s)
32
+ ticker.ask = NumericHelper.to_d(market['ask'].to_s)
33
+ ticker.volume = NumericHelper.to_d(market['quoteVolume'].to_s)
34
+ ticker.timestamp = DateTime.now.to_time.to_i
35
+ ticker.payload = market
36
+ ticker
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,26 @@
1
+ module Cryptoexchange::Exchanges
2
+ module EtherDelta
3
+ module Services
4
+ class Pairs < Cryptoexchange::Services::Pairs
5
+ PAIRS_URL = "#{Cryptoexchange::Exchanges::EtherDelta::Market::API_URL}/returnTicker"
6
+
7
+ def fetch
8
+ output = super
9
+ adapt(output)
10
+ end
11
+
12
+ def adapt(output)
13
+ output.keys.map do |pair|
14
+ base, target = pair.split('_')
15
+
16
+ EtherDelta::Models::MarketPair.new({
17
+ base: base,
18
+ target: target,
19
+ market: EtherDelta::Market::NAME
20
+ })
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -30,18 +30,18 @@ module Cryptoexchange::Exchanges
30
30
  end
31
31
 
32
32
  def adapt(output, market_pair)
33
- ticker = Gatecoin::Models::Ticker.new
34
- ticker.base = market_pair.base
35
- ticker.target = market_pair.target
36
- ticker.market = 'gatecoin'
37
- ticker.last = output['last']
38
- ticker.bid = output['bid']
39
- ticker.ask = output['ask']
40
- ticker.high = output['high']
41
- ticker.low = output['low']
42
- ticker.volume = output['volume'] # TODO: Check if it is base denominated?
33
+ ticker = Gatecoin::Models::Ticker.new
34
+ ticker.base = market_pair.base
35
+ ticker.target = market_pair.target
36
+ ticker.market = Gatecoin::Market::NAME
37
+ ticker.last = NumericHelper.to_d(output['last'])
38
+ ticker.bid = NumericHelper.to_d(output['bid'])
39
+ ticker.ask = NumericHelper.to_d(output['ask'])
40
+ ticker.high = NumericHelper.to_d(output['high'])
41
+ ticker.low = NumericHelper.to_d(output['low'])
42
+ ticker.volume = NumericHelper.to_d(output['volume'])
43
43
  ticker.timestamp = output['createDateTime'].to_i
44
- ticker.payload = output
44
+ ticker.payload = output
45
45
  ticker
46
46
  end
47
47
  end
@@ -35,10 +35,10 @@ module Cryptoexchange::Exchanges
35
35
  ticker.base = market_pair.base
36
36
  ticker.target = market_pair.target
37
37
  ticker.market = Gemini::Market::NAME
38
- ticker.ask = output['ask'] ? BigDecimal.new(output['ask'].to_s) : nil
39
- ticker.bid = output['bid'] ? BigDecimal.new(output['bid'].to_s) : nil
40
- #this is BTC's volume
41
- ticker.volume = output['volume'][market_pair.base] ? BigDecimal.new(output['volume'][market_pair.base].to_s) : nil
38
+ ticker.ask = NumericHelper.to_d(output['ask'])
39
+ ticker.bid = NumericHelper.to_d(output['bid'])
40
+ # this is Base currency's volume
41
+ ticker.volume = NumericHelper.to_d(output['volume'][market_pair.base])
42
42
  ticker.timestamp = output['volume']['timestamp'].to_i
43
43
  ticker.payload = output
44
44
  ticker
@@ -0,0 +1,8 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Hitbtc
3
+ class Market
4
+ NAME = 'hitbtc'
5
+ API_URL = 'http://api.hitbtc.com/api/1'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Hitbtc
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 Hitbtc
3
+ module Models
4
+ class Ticker < Cryptoexchange::Models::Ticker
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,42 @@
1
+ require 'bigdecimal'
2
+
3
+ module Cryptoexchange::Exchanges
4
+ module Hitbtc
5
+ module Services
6
+ class Market < Cryptoexchange::Services::Market
7
+ class << self
8
+ def supports_individual_ticker_query?
9
+ true
10
+ end
11
+ end
12
+
13
+ def fetch(market_pair)
14
+ output = super(ticker_url(market_pair))
15
+ adapt(output, market_pair)
16
+ end
17
+
18
+ def ticker_url(market_pair)
19
+ symbol = "#{market_pair.base}#{market_pair.target}"
20
+
21
+ "#{Cryptoexchange::Exchanges::Hitbtc::Market::API_URL}/public/#{symbol}/ticker"
22
+ end
23
+
24
+ def adapt(output, market_pair)
25
+ ticker = Hitbtc::Models::Ticker.new
26
+ ticker.base = market_pair.base
27
+ ticker.target = market_pair.target
28
+ ticker.market = Hitbtc::Market::NAME
29
+ ticker.last = NumericHelper.to_d(output['last'])
30
+ ticker.bid = NumericHelper.to_d(output['bid'])
31
+ ticker.ask = NumericHelper.to_d(output['ask'])
32
+ ticker.high = NumericHelper.to_d(output['high'])
33
+ ticker.low = NumericHelper.to_d(output['low'])
34
+ ticker.volume = NumericHelper.to_d(output['volume'])
35
+ ticker.timestamp = output['timestamp']
36
+ ticker.payload = output
37
+ ticker
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,24 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Hitbtc
3
+ module Services
4
+ class Pairs < Cryptoexchange::Services::Pairs
5
+ PAIRS_URL = "#{Cryptoexchange::Exchanges::Hitbtc::Market::API_URL}/public/symbols"
6
+
7
+ def fetch
8
+ output = super
9
+ adapt(output)
10
+ end
11
+
12
+ def adapt(output)
13
+ output['symbols'].map do |market|
14
+ Hitbtc::Models::MarketPair.new({
15
+ base: market['commodity'],
16
+ target: market['currency'],
17
+ market: Hitbtc::Market::NAME
18
+ })
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -20,18 +20,18 @@ module Cryptoexchange::Exchanges
20
20
  end
21
21
 
22
22
  def adapt(output, market_pair)
23
- ticker = Korbit::Models::Ticker.new
24
- ticker.base = market_pair.base
25
- ticker.target = market_pair.target
26
- ticker.market = Korbit::Market::NAME
27
- ticker.ask = output['ask']
28
- ticker.bid = output['bid']
29
- ticker.last = output['last']
30
- ticker.high = output['high']
31
- ticker.low = output['low']
32
- ticker.volume = output['volume'].to_f
33
- ticker.timestamp = output['timestamp']/1000
34
- ticker.payload = output
23
+ ticker = Korbit::Models::Ticker.new
24
+ ticker.base = market_pair.base
25
+ ticker.target = market_pair.target
26
+ ticker.market = Korbit::Market::NAME
27
+ ticker.ask = NumericHelper.to_d(output['ask'])
28
+ ticker.bid = NumericHelper.to_d(output['bid'])
29
+ ticker.last = NumericHelper.to_d(output['last'])
30
+ ticker.high = NumericHelper.to_d(output['high'])
31
+ ticker.low = NumericHelper.to_d(output['low'])
32
+ ticker.volume = NumericHelper.to_d(output['volume'])
33
+ ticker.timestamp = output['timestamp'] / 1000
34
+ ticker.payload = output
35
35
  ticker
36
36
  end
37
37
  end
@@ -0,0 +1,8 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Lakebtc
3
+ class Market
4
+ NAME = 'lakebtc'
5
+ API_URL = 'https://api.lakebtc.com/api_v2'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Lakebtc
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 Lakebtc
3
+ module Models
4
+ class Ticker < Cryptoexchange::Models::Ticker
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,51 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Lakebtc
3
+ module Services
4
+ class Market < Cryptoexchange::Services::Market
5
+ class << self
6
+ def supports_individual_ticker_query?
7
+ false
8
+ end
9
+ end
10
+
11
+ def fetch
12
+ output = super(ticker_url)
13
+ adapt_all(output)
14
+ end
15
+
16
+ def ticker_url
17
+ "#{Cryptoexchange::Exchanges::Lakebtc::Market::API_URL}/ticker"
18
+ end
19
+
20
+ def adapt_all(output)
21
+ tickers = []
22
+
23
+ output.keys.each do |pair|
24
+ if pair.include?('btc')
25
+ ticker_json = output[pair]
26
+ ticker = Lakebtc::Models::Ticker.new
27
+ ticker.base = 'btc'
28
+ ticker.target = pair[3..-1]
29
+ ticker.market = Lakebtc::Market::NAME
30
+
31
+ # NOTE: apparently it can be nil
32
+ ticker.ask = NumericHelper.to_d(ticker_json['ask'])
33
+ ticker.bid = NumericHelper.to_d(ticker_json['bid'])
34
+ ticker.last = NumericHelper.to_d(ticker_json['last'])
35
+ ticker.high = NumericHelper.to_d(ticker_json['high'])
36
+ ticker.low = NumericHelper.to_d(ticker_json['low'])
37
+ ticker.volume = NumericHelper.to_d(ticker_json['volume'])
38
+
39
+ ticker.timestamp = Time.now.to_i
40
+ ticker.payload = ticker_json
41
+
42
+ tickers << ticker
43
+ end
44
+ end
45
+
46
+ tickers
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end