Skip to content

Commit

Permalink
Implement Coinhouse ticker (coingecko#295)
Browse files Browse the repository at this point in the history
* 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
Swingcloud authored and tmlee committed Apr 7, 2018
1 parent 1395a64 commit 528d6fb
Show file tree
Hide file tree
Showing 8 changed files with 271 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Or install it yourself as:
| Coinfalcon | Y | Y | Y | | Y |
| CoinExchange | Y | | | | Y |
| Coinbene | Y | Y | Y | | Y |
| Coinhouse | Y | | | | Y |
| Coinmate | Y | Y | | | User-Defined|
| Coinnest | Y | Y | Y | | User-Defined|
| Coinroom | Y | | | | Y |
Expand Down
8 changes: 8 additions & 0 deletions lib/cryptoexchange/exchanges/coinhouse/market.rb
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
52 changes: 52 additions & 0 deletions lib/cryptoexchange/exchanges/coinhouse/services/market.rb
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
37 changes: 37 additions & 0 deletions lib/cryptoexchange/exchanges/coinhouse/services/pairs.rb
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 528d6fb

Please sign in to comment.