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.
- checksums.yaml +4 -4
- data/README.md +13 -12
- data/cryptoexchange.gemspec +2 -0
- data/lib/cryptoexchange.rb +5 -12
- data/lib/cryptoexchange/client.rb +46 -0
- data/lib/cryptoexchange/exchanges/anx/anx.yml +27 -0
- data/lib/cryptoexchange/exchanges/anx/market.rb +8 -0
- data/lib/cryptoexchange/exchanges/anx/models/market_pair.rb +8 -0
- data/lib/cryptoexchange/exchanges/anx/models/ticker.rb +8 -0
- data/lib/cryptoexchange/exchanges/anx/services/market.rb +41 -0
- data/lib/cryptoexchange/exchanges/anx/services/pairs.rb +25 -0
- data/lib/cryptoexchange/exchanges/bitcoin_indonesia/bitcoin_indonesia.yml +19 -0
- data/lib/cryptoexchange/exchanges/bitcoin_indonesia/market.rb +8 -0
- data/lib/cryptoexchange/exchanges/bitcoin_indonesia/models/market_pair.rb +8 -0
- data/lib/cryptoexchange/exchanges/bitcoin_indonesia/models/ticker.rb +8 -0
- data/lib/cryptoexchange/exchanges/bitcoin_indonesia/services/market.rb +41 -0
- data/lib/cryptoexchange/exchanges/bitcoin_indonesia/services/pairs.rb +25 -0
- data/lib/cryptoexchange/exchanges/bitflyer/services/market.rb +8 -2
- data/lib/cryptoexchange/exchanges/bitflyer/services/pairs.rb +1 -2
- data/lib/cryptoexchange/exchanges/bitstamp/bitstamp.yml +19 -0
- data/lib/cryptoexchange/exchanges/bitstamp/market.rb +8 -0
- data/lib/cryptoexchange/exchanges/bitstamp/models/market_pair.rb +8 -0
- data/lib/cryptoexchange/exchanges/bitstamp/models/ticker.rb +8 -0
- data/lib/cryptoexchange/exchanges/bitstamp/services/market.rb +40 -0
- data/lib/cryptoexchange/exchanges/bitstamp/services/pairs.rb +26 -0
- data/lib/cryptoexchange/exchanges/btcc/btcc.yml +5 -0
- data/lib/cryptoexchange/exchanges/btcc/market.rb +9 -0
- data/lib/cryptoexchange/exchanges/btcc/models/market_pair.rb +8 -0
- data/lib/cryptoexchange/exchanges/btcc/models/ticker.rb +8 -0
- data/lib/cryptoexchange/exchanges/btcc/services/market.rb +42 -0
- data/lib/cryptoexchange/exchanges/btcc/services/pairs.rb +25 -0
- data/lib/cryptoexchange/exchanges/coincheck/services/market.rb +8 -2
- data/lib/cryptoexchange/exchanges/coincheck/services/pairs.rb +1 -2
- data/lib/cryptoexchange/exchanges/coinone/services/market.rb +8 -2
- data/lib/cryptoexchange/exchanges/coinone/services/pairs.rb +1 -2
- data/lib/cryptoexchange/exchanges/cryptopia/services/market.rb +7 -2
- data/lib/cryptoexchange/exchanges/cryptopia/services/pairs.rb +1 -2
- data/lib/cryptoexchange/exchanges/gatecoin/services/market.rb +28 -27
- data/lib/cryptoexchange/exchanges/gatecoin/services/pairs.rb +1 -2
- data/lib/cryptoexchange/exchanges/gemini/market.rb +8 -0
- data/lib/cryptoexchange/exchanges/gemini/models/market_pair.rb +8 -0
- data/lib/cryptoexchange/exchanges/gemini/models/ticker.rb +8 -0
- data/lib/cryptoexchange/exchanges/gemini/services/market.rb +49 -0
- data/lib/cryptoexchange/exchanges/gemini/services/pairs.rb +28 -0
- data/lib/cryptoexchange/exchanges/korbit/services/market.rb +8 -2
- data/lib/cryptoexchange/exchanges/korbit/services/pairs.rb +1 -2
- data/lib/cryptoexchange/exchanges/liqui/market.rb +8 -0
- data/lib/cryptoexchange/exchanges/liqui/models/market_pair.rb +8 -0
- data/lib/cryptoexchange/exchanges/liqui/models/ticker.rb +8 -0
- data/lib/cryptoexchange/exchanges/liqui/services/market.rb +43 -0
- data/lib/cryptoexchange/exchanges/liqui/services/pairs.rb +27 -0
- data/lib/cryptoexchange/exchanges/livecoin/market.rb +8 -0
- data/lib/cryptoexchange/exchanges/livecoin/models/market_pair.rb +8 -0
- data/lib/cryptoexchange/exchanges/livecoin/models/ticker.rb +8 -0
- data/lib/cryptoexchange/exchanges/livecoin/services/market.rb +51 -0
- data/lib/cryptoexchange/exchanges/livecoin/services/pairs.rb +27 -0
- data/lib/cryptoexchange/exchanges/novaexchange/market.rb +8 -0
- data/lib/cryptoexchange/exchanges/novaexchange/models/market_pair.rb +8 -0
- data/lib/cryptoexchange/exchanges/novaexchange/models/ticker.rb +8 -0
- data/lib/cryptoexchange/exchanges/novaexchange/services/market.rb +44 -0
- data/lib/cryptoexchange/exchanges/novaexchange/services/pairs.rb +26 -0
- data/lib/cryptoexchange/exchanges/okcoin/market.rb +8 -0
- data/lib/cryptoexchange/exchanges/okcoin/models/market_pair.rb +8 -0
- data/lib/cryptoexchange/exchanges/okcoin/models/ticker.rb +8 -0
- data/lib/cryptoexchange/exchanges/okcoin/okcoin.yml +7 -0
- data/lib/cryptoexchange/exchanges/okcoin/services/market.rb +40 -0
- data/lib/cryptoexchange/exchanges/okcoin/services/pairs.rb +25 -0
- data/lib/cryptoexchange/helpers/string_helper.rb +7 -0
- data/lib/cryptoexchange/lru_ttl_cache.rb +7 -0
- data/lib/cryptoexchange/services/market.rb +15 -1
- data/lib/cryptoexchange/services/pairs.rb +7 -2
- data/lib/cryptoexchange/version.rb +1 -1
- metadata +69 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1df6ea7c91d604d8106be0681b0ba54e90a6a95a
|
4
|
+
data.tar.gz: a91d02633e2906ed8ac6d61c5e02720511abf698
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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::
|
66
|
+
client = Cryptoexchange::Client.new
|
67
|
+
pairs = client.pairs('bitflyer')
|
66
68
|
```
|
67
69
|
|
68
70
|
### Query the Ticker API
|
69
71
|
```
|
70
|
-
pair =
|
71
|
-
ticker =
|
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
|
-
|
data/cryptoexchange.gemspec
CHANGED
data/lib/cryptoexchange.rb
CHANGED
@@ -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
|
-
|
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,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,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(
|
12
|
+
output = super(ticker_url(market_pair))
|
7
13
|
adapt(output)
|
8
14
|
end
|
9
15
|
|
10
|
-
def
|
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:
|
23
|
+
market: Bitflyer::Market::NAME
|
25
24
|
)
|
26
25
|
end
|
27
26
|
end
|