Skip to content
This repository has been archived by the owner on Jun 22, 2020. It is now read-only.

Commit

Permalink
New Capital exchange integration.
Browse files Browse the repository at this point in the history
  • Loading branch information
Halt committed Jul 3, 2019
1 parent 35615be commit f87c946
Show file tree
Hide file tree
Showing 7 changed files with 201 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ Or install it yourself as:
| Negociecoins | Y | Y [x] | Y | | User-Defined| | negociecoins | |
| Neraex | Y | Y | Y | | Y | Y | neraex | |
| Newdex | Y | N | N | | Y | Y | newdex | |
| New Capital | Y | Y [x] | Y | | Y | Y | new_capital | |
| Nexybit | Y | Y | N | | Y | N | nexybit | |
| Ninecoin (Halted) | Y | | | | Y | | ninecoin | |
| NLexch | Y | | | | Y | Y | nlexch | |
Expand Down
5 changes: 3 additions & 2 deletions lib/cryptoexchange/exchanges/new_capital/market.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ class Market < Cryptoexchange::Models::Market
NAME = 'new_capital'
API_URL = 'https://api.new.capital/v1'

def self.trade_page_url(args={})
"https://new.capital/exchange/trade/#{args[:target].downcase}_#{args[:base].downcase}"
def self.trade_page_url(args = {})
"https://new.capital/exchange/trade/#{args[:base].upcase}_#{args[:target].upcase}"
end

end
end
end
40 changes: 40 additions & 0 deletions lib/cryptoexchange/exchanges/new_capital/services/order_book.rb
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 lib/cryptoexchange/exchanges/new_capital/services/trades.rb
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

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

Large diffs are not rendered by default.

35 changes: 33 additions & 2 deletions spec/exchanges/new_capital/integration/market_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

RSpec.describe 'NewCapital integration specs' do
let(:client) {Cryptoexchange::Client.new}
let(:twins_btc_pair) {Cryptoexchange::Models::MarketPair.new(base: 'BTC', target: 'TWINS', market: 'new_capital')}
let(:btc_twins_pair) {Cryptoexchange::Models::MarketPair.new(base: 'BTC', target: 'TWINS', market: 'new_capital')}

it 'fetch pairs' do
pairs = client.pairs('new_capital')
Expand All @@ -14,7 +14,7 @@
end

it 'fetch ticker' do
ticker = client.ticker(twins_btc_pair)
ticker = client.ticker(btc_twins_pair)
expect(ticker.base).to eq 'BTC'
expect(ticker.target).to eq 'TWINS'
expect(ticker.market).to eq 'new_capital'
Expand All @@ -28,4 +28,35 @@
expect(ticker.payload).to_not be nil
end

it 'fetch order book' do
order_book = client.order_book(btc_twins_pair)

expect(order_book.base).to eq 'BTC'
expect(order_book.target).to eq 'TWINS'
expect(order_book.market).to eq 'new_capital'
expect(order_book.asks).to_not be_empty
expect(order_book.bids).to_not be_empty
expect(order_book.asks.first.price).to_not be_nil
expect(order_book.bids.first.amount).to_not be_nil
expect(order_book.bids.first.timestamp).to be_nil
expect(order_book.asks.count).to be > 0
expect(order_book.bids.count).to be > 0
expect(order_book.payload).to_not be nil
end

it 'fetch trade' do
trades = client.trades(btc_twins_pair)
trade = trades.sample

expect(trades).to_not be_empty
expect(trade.base).to eq 'BTC'
expect(trade.target).to eq 'TWINS'
expect(trade.market).to eq 'new_capital'
expect(trade.trade_id).to_not be_nil
expect(trade.price).to_not be_nil
expect(trade.amount).to_not be_nil
expect(trade.timestamp).to be_a Numeric
expect(trade.payload).to_not be nil
end

end

0 comments on commit f87c946

Please sign in to comment.