forked from coingecko/cryptoexchange
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Coinhouse ticker (coingecko#295)
* implement coinhouse pairs * implement coinhouse ticker * add rspec on coinhouse * add read me * use regex to detect target currency * Update readme for coinhouse mistake conflict resolve
- Loading branch information
1 parent
1395a64
commit 528d6fb
Showing
8 changed files
with
271 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module Cryptoexchange::Exchanges | ||
module Coinhouse | ||
class Market | ||
NAME = 'coinhouse' | ||
API_URL = 'https://coinhouse.eu/v2' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
module Cryptoexchange::Exchanges | ||
module Coinhouse | ||
module Services | ||
class Market < Cryptoexchange::Services::Market | ||
class << self | ||
def supports_individual_ticker_query? | ||
false | ||
end | ||
end | ||
|
||
def fetch | ||
output = super ticker_url | ||
adapt_all(output) | ||
end | ||
|
||
def ticker_url | ||
"#{Cryptoexchange::Exchanges::Coinhouse::Market::API_URL}/tickers" | ||
end | ||
|
||
def adapt_all(output) | ||
output.map do |key, value| | ||
separator = /(USDT|BTC|BCH|ETH)\z/i =~ key | ||
base = key[0..separator - 1] | ||
target = key[separator..-1] | ||
market_pair = Cryptoexchange::Models::MarketPair.new( | ||
base: base, | ||
target: target, | ||
market: Coinhouse::Market::NAME | ||
) | ||
adapt(value, market_pair) | ||
end | ||
end | ||
|
||
def adapt(output, market_pair) | ||
ticker = Cryptoexchange::Models::Ticker.new | ||
ticker.base = market_pair.base | ||
ticker.target = market_pair.target | ||
ticker.market = Coinhouse::Market::NAME | ||
ticker.ask = NumericHelper.to_d(output['sell']) | ||
ticker.bid = NumericHelper.to_d(output['buy']) | ||
ticker.last = NumericHelper.to_d(output['last']) | ||
ticker.high = NumericHelper.to_d(output['high']) | ||
ticker.low = NumericHelper.to_d(output['low']) | ||
ticker.volume = NumericHelper.to_d(output['quoteVolume']) | ||
ticker.timestamp = Time.now.to_i | ||
ticker.payload = output | ||
ticker | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module Cryptoexchange::Exchanges | ||
module Coinhouse | ||
module Services | ||
class Pairs < Cryptoexchange::Services::Pairs | ||
PAIRS_URL = "#{Cryptoexchange::Exchanges::Coinhouse::Market::API_URL}/tickers" | ||
TARGET = 'BTC' | ||
|
||
def fetch | ||
output = super | ||
adapt(output) | ||
end | ||
|
||
def adapt(output) | ||
market_pairs = [] | ||
output.each_key do |pair| | ||
base, target = strip_pairs(pair) | ||
next unless base && target | ||
market_pairs << Cryptoexchange::Models::MarketPair.new( | ||
base: base, | ||
target: target, | ||
market: Coinhouse::Market::NAME | ||
) | ||
end | ||
market_pairs | ||
end | ||
|
||
def strip_pairs(pair_symbol) | ||
separator = /(USDT|BTC|BCH|ETH)\z/i =~ pair_symbol | ||
base = pair_symbol[0..separator - 1] | ||
target = pair_symbol[separator..-1] | ||
|
||
[base, target] | ||
end | ||
end | ||
end | ||
end | ||
end |
67 changes: 67 additions & 0 deletions
67
spec/cassettes/vcr_cassettes/Coinhouse/integration_specs_fetch_pairs.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.