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 Poloniex orderbook, fix bibox, fcoin orderbook data
- Loading branch information
Showing
7 changed files
with
132 additions
and
10 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
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
57 changes: 57 additions & 0 deletions
57
lib/cryptoexchange/exchanges/poloniex/services/order_book.rb
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,57 @@ | ||
module Cryptoexchange::Exchanges | ||
module Poloniex | ||
module Services | ||
class OrderBook < Cryptoexchange::Services::Market | ||
class << self | ||
def supports_individual_ticker_query? | ||
false | ||
end | ||
end | ||
|
||
def fetch | ||
output = super(self.order_book_url) | ||
adapt_all(output) | ||
end | ||
|
||
def order_book_url | ||
"#{Cryptoexchange::Exchanges::Poloniex::Market::API_URL}?command=returnOrderBook¤cyPair=all&depth=100" | ||
end | ||
|
||
def adapt_all(output) | ||
output.map do |pair, ticker| | ||
# Target comes first in Poloniex ie. BTC-BCN | ||
# BTC cannot be a base in this pair | ||
target, base = pair.split('_') | ||
market_pair = Cryptoexchange::Models::MarketPair.new( | ||
base: base, | ||
target: target, | ||
market: Poloniex::Market::NAME | ||
) | ||
|
||
adapt(ticker, market_pair) | ||
end | ||
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 = Poloniex::Market::NAME | ||
order_book.asks = adapt_orders(output['asks']) | ||
order_book.bids = adapt_orders(output['bids']) | ||
order_book.payload = output | ||
order_book | ||
end | ||
|
||
def adapt_orders(orders) | ||
orders.collect do |order_entry| | ||
Cryptoexchange::Models::Order.new(price: NumericHelper.to_d(order_entry[0]), | ||
amount: NumericHelper.to_d(order_entry[1]), | ||
timestamp: nil) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
10 changes: 5 additions & 5 deletions
10
spec/cassettes/vcr_cassettes/Fcoin/integration_specs_fetch_order_book.yml
Large diffs are not rendered by default.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
spec/cassettes/vcr_cassettes/Poloniex/integration_specs_fetch_order_book.yml
Large diffs are not rendered by default.
Oops, something went wrong.
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