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 market.rb * Added specs for OrderBook and Trades * Removed redundant slash in ticker_url
- Loading branch information
Showing
11 changed files
with
385 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module Cryptoexchange::Exchanges | ||
module Zb | ||
class Market | ||
NAME = 'zb' | ||
API_URL = 'http://api.zb.com/data/v1' | ||
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,39 @@ | ||
module Cryptoexchange::Exchanges | ||
module Zb | ||
module Services | ||
class Market < 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, market_pair) | ||
end | ||
|
||
def ticker_url(market_pair) | ||
"#{Cryptoexchange::Exchanges::Zb::Market::API_URL}/ticker?market=#{market_pair.base.downcase}_#{market_pair.target.downcase}" | ||
end | ||
|
||
def adapt(output, market_pair) | ||
ticker = Cryptoexchange::Models::Ticker.new | ||
ticker.base = market_pair.base | ||
ticker.target = market_pair.target | ||
ticker.market = Zb::Market::NAME | ||
ticker.ask = NumericHelper.to_d(output["ticker"]["sell"]) | ||
ticker.bid = NumericHelper.to_d(output["ticker"]["buy"]) | ||
ticker.last = NumericHelper.to_d(output["ticker"]["last"]) | ||
ticker.high = NumericHelper.to_d(output["ticker"]["high"]) | ||
ticker.low = NumericHelper.to_d(output["ticker"]["low"]) | ||
ticker.volume = NumericHelper.to_d(output["ticker"]["vol"]) | ||
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,44 @@ | ||
module Cryptoexchange::Exchanges | ||
module Zb | ||
module Services | ||
class OrderBook < Cryptoexchange::Services::Market | ||
class << self | ||
def supports_individual_ticker_query? | ||
true | ||
end | ||
end | ||
|
||
def fetch(market_pair) | ||
output = super(orderbook_url(market_pair)) | ||
adapt(output, market_pair) | ||
end | ||
|
||
def orderbook_url(market_pair) | ||
"#{Cryptoexchange::Exchanges::Zb::Market::API_URL}/depth?market=#{market_pair.base.downcase}_#{market_pair.target.downcase}" | ||
end | ||
|
||
def adapt(output, market_pair) | ||
order_book = Cryptoexchange::Models::OrderBook.new | ||
timestamp = output["timestamp"].to_i | ||
|
||
order_book.base = market_pair.base | ||
order_book.target = market_pair.target | ||
order_book.market = Zb::Market::NAME | ||
order_book.asks = adapt_orders(output["asks"]) | ||
order_book.bids = adapt_orders(output["bids"]) | ||
order_book.timestamp = timestamp | ||
order_book.payload = output | ||
order_book | ||
end | ||
|
||
def adapt_orders(orders) | ||
orders.collect do |order_entry| | ||
Cryptoexchange::Models::Order.new(price: order_entry[0], | ||
amount: order_entry[1], | ||
timestamp: nil) | ||
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,24 @@ | ||
module Cryptoexchange::Exchanges | ||
module Zb | ||
module Services | ||
class Pairs < Cryptoexchange::Services::Pairs | ||
PAIRS_URL = "#{Cryptoexchange::Exchanges::Zb::Market::API_URL}/markets" | ||
|
||
def fetch | ||
output = super | ||
market_pairs = [] | ||
output.each do |pair| | ||
pair_split = pair[0].split('_') | ||
market_pairs << Cryptoexchange::Models::MarketPair.new( | ||
base: pair_split[0], | ||
target: pair_split[1], | ||
market: Zb::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 Zb | ||
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::Zb::Market::API_URL}/trades?market=#{market_pair.base.downcase}_#{market_pair.target.downcase}" | ||
end | ||
|
||
def adapt(output, market_pair) | ||
output.collect do |trade| | ||
tr = Cryptoexchange::Models::Trade.new | ||
tr.trade_id = trade["tid"] | ||
tr.base = market_pair.base | ||
tr.target = market_pair.target | ||
tr.market = Zb::Market::NAME | ||
tr.type = trade["type"] | ||
tr.price = trade["price"] | ||
tr.amount = trade["amount"] | ||
tr.timestamp = trade["date"].to_i | ||
tr.payload = trade | ||
tr | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
42 changes: 42 additions & 0 deletions
42
spec/cassettes/vcr_cassettes/ZB/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.
42 changes: 42 additions & 0 deletions
42
spec/cassettes/vcr_cassettes/ZB/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.
40 changes: 40 additions & 0 deletions
40
spec/cassettes/vcr_cassettes/ZB/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.
42 changes: 42 additions & 0 deletions
42
spec/cassettes/vcr_cassettes/ZB/integration_specs_fetch_trade.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.