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.
Added Pairs, Tickers, OrderBook, Trades, and updated README for HPX (c…
- Loading branch information
1 parent
5074862
commit 47e4303
Showing
12 changed files
with
400 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 Hpx | ||
class Market < Cryptoexchange::Models::Market | ||
NAME = 'hpx' | ||
API_URL = 'https://api.hpx.com/data/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,50 @@ | ||
module Cryptoexchange::Exchanges | ||
module Hpx | ||
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::Hpx::Market::API_URL}/tickers" | ||
end | ||
|
||
def adapt_all(output) | ||
output['data'].map do |pair| | ||
base, target = pair['symbol'].split('_') | ||
market_pair = Cryptoexchange::Models::MarketPair.new( | ||
base: base.upcase, | ||
target: target.upcase, | ||
market: Hpx::Market::NAME | ||
) | ||
adapt(market_pair, pair['ticker']) | ||
end | ||
end | ||
|
||
def adapt(market_pair, output) | ||
ticker = Cryptoexchange::Models::Ticker.new | ||
ticker.base = market_pair.base | ||
ticker.target = market_pair.target | ||
ticker.market = Hpx::Market::NAME | ||
ticker.last = NumericHelper.to_d(output['last']) | ||
ticker.high = NumericHelper.to_d(output['high']) | ||
ticker.low = NumericHelper.to_d(output['low']) | ||
ticker.bid = NumericHelper.to_d(output['buy']) | ||
ticker.ask = NumericHelper.to_d(output['sell']) | ||
ticker.volume = NumericHelper.to_d(output['vol']) | ||
ticker.timestamp = nil | ||
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,42 @@ | ||
module Cryptoexchange::Exchanges | ||
module Hpx | ||
module Services | ||
class OrderBook < Cryptoexchange::Services::Market | ||
class << self | ||
def supports_individual_ticker_query? | ||
true | ||
end | ||
end | ||
|
||
def fetch(market_pair) | ||
output = super(ticker_url(market_pair)) | ||
adapt(output['data'], market_pair) | ||
end | ||
|
||
def ticker_url(market_pair) | ||
"#{Cryptoexchange::Exchanges::Hpx::Market::API_URL}/depth?currency=#{market_pair.base.downcase}_#{market_pair.target.upcase}" | ||
end | ||
|
||
def adapt(output, market_pair) | ||
order_book = Cryptoexchange::Models::OrderBook.new | ||
|
||
order_book.base = market_pair.base | ||
order_book.target = market_pair.target | ||
order_book.market = Hpx::Market::NAME | ||
order_book.asks = adapt_orders(output['asks']) | ||
order_book.bids = adapt_orders(output['bids']) | ||
order_book.timestamp = output['timestamp'].to_i | ||
order_book.payload = output | ||
order_book | ||
end | ||
|
||
def adapt_orders(orders) | ||
orders.collect do |order_entry| | ||
Cryptoexchange::Models::Order.new(price: order_entry['price'], | ||
amount: order_entry['amount']) | ||
end | ||
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,23 @@ | ||
module Cryptoexchange::Exchanges | ||
module Hpx | ||
module Services | ||
class Pairs < Cryptoexchange::Services::Pairs | ||
PAIRS_URL = "#{Cryptoexchange::Exchanges::Hpx::Market::API_URL}/tickers" | ||
|
||
def fetch | ||
output = super | ||
market_pairs = [] | ||
output['data'].each do |pair| | ||
base, target = pair['symbol'].split('_') | ||
market_pairs << Cryptoexchange::Models::MarketPair.new( | ||
base: base.upcase, | ||
target: target.upcase, | ||
market: Hpx::Market::NAME | ||
) | ||
end | ||
market_pairs | ||
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,32 @@ | ||
module Cryptoexchange::Exchanges | ||
module Hpx | ||
module Services | ||
class Trades < Cryptoexchange::Services::Market | ||
def fetch(market_pair) | ||
output = super(ticker_url(market_pair)) | ||
adapt(output, market_pair) | ||
end | ||
|
||
def ticker_url(market_pair) | ||
"#{Cryptoexchange::Exchanges::Hpx::Market::API_URL}/trades?currency=#{market_pair.base.downcase}_#{market_pair.target.upcase}" | ||
end | ||
|
||
def adapt(output, market_pair) | ||
output['data'].collect do |trade| | ||
tr = Cryptoexchange::Models::Trade.new | ||
tr.trade_id = trade['id'] | ||
tr.base = market_pair.base | ||
tr.target = market_pair.target | ||
tr.market = Hpx::Market::NAME | ||
tr.type = trade['en_type'] == 0 ? 'buy' : 'sell' | ||
tr.price = trade['price'] | ||
tr.amount = trade['amount'] | ||
tr.timestamp = nil | ||
tr.payload = trade | ||
tr | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
43 changes: 43 additions & 0 deletions
43
spec/cassettes/vcr_cassettes/HPX/integration_specs_fetch_order_book.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
spec/cassettes/vcr_cassettes/HPX/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.
43 changes: 43 additions & 0 deletions
43
spec/cassettes/vcr_cassettes/HPX/integration_specs_fetch_ticker.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.