This repository has been archived by the owner on Jun 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
201 additions
and
4 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
40 changes: 40 additions & 0 deletions
40
lib/cryptoexchange/exchanges/new_capital/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,40 @@ | ||
module Cryptoexchange::Exchanges | ||
module NewCapital | ||
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, market_pair) | ||
end | ||
|
||
def ticker_url(market_pair) | ||
"#{Cryptoexchange::Exchanges::NewCapital::Market::API_URL}/depth?symbol=#{market_pair.base}_#{market_pair.target}" | ||
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 = NewCapital::Market::NAME | ||
order_book.asks = adapt_orders(output['asks']) | ||
order_book.bids = adapt_orders(output['bids']) | ||
order_book.timestamp = Time.now.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[0], amount: order_entry[1], timestamp: nil) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
34 changes: 34 additions & 0 deletions
34
lib/cryptoexchange/exchanges/new_capital/services/trades.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,34 @@ | ||
module Cryptoexchange::Exchanges | ||
module NewCapital | ||
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) | ||
base = market_pair.base.upcase | ||
target = market_pair.target.upcase | ||
"#{Cryptoexchange::Exchanges::NewCapital::Market::API_URL}/trades?symbol=#{base}_#{target}" | ||
end | ||
|
||
def adapt(output, market_pair) | ||
output.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 = NewCapital::Market::NAME | ||
tr.price = trade['price'] | ||
tr.amount = trade['qty'] | ||
tr.timestamp = trade['time'] | ||
tr.payload = trade | ||
tr | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
45 changes: 45 additions & 0 deletions
45
spec/cassettes/vcr_cassettes/NewCapital/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.
45 changes: 45 additions & 0 deletions
45
spec/cassettes/vcr_cassettes/NewCapital/integration_specs_fetch_trade.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