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

New Capital community exchange #1630

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
22 changes: 12 additions & 10 deletions lib/cryptoexchange/config.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
module Cryptoexchange

class Configuration
attr_accessor :rails_cache, :ticker_ttl, :cache_size, :proxy_list

def initialize
@proxy_list = nil
@rails_cache = false
@ticker_ttl = 10
@cache_size = 200
end
end

class << self
attr_accessor :configuration

Expand All @@ -13,13 +25,3 @@ def reset_config
end
end

class Configuration
attr_accessor :rails_cache, :ticker_ttl, :cache_size, :proxy_list

def initialize
@proxy_list = nil
@rails_cache = false
@ticker_ttl = 10
@cache_size = 200
end
end
13 changes: 13 additions & 0 deletions lib/cryptoexchange/exchanges/new_capital/market.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Cryptoexchange::Exchanges
module NewCapital
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[:base].upcase}_#{args[:target].upcase}"
end

end
end
end
51 changes: 51 additions & 0 deletions lib/cryptoexchange/exchanges/new_capital/services/market.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
module Cryptoexchange::Exchanges
module NewCapital
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::NewCapital::Market::API_URL}/ticker"
end

def adapt_all(output)
output.map do |pair|
base, target = pair["symbol"].split('_')
market_pair = Cryptoexchange::Models::MarketPair.new(
base: base,
target: target,
market: NewCapital::Market::NAME
)
adapt(market_pair, pair)
end
end

def adapt(market_pair, output)
ticker = Cryptoexchange::Models::Ticker.new
ticker.base = market_pair.base
ticker.target = market_pair.target
ticker.market = NewCapital::Market::NAME
ticker.last = NumericHelper.to_d(output['lastPrice'])
ticker.bid = NumericHelper.to_d(output['bidPrice'])
ticker.ask = NumericHelper.to_d(output['askPrice'])
ticker.high = NumericHelper.to_d(output['highPrice'])
ticker.low = NumericHelper.to_d(output['lowPrice'])
ticker.volume = NumericHelper.to_d(output['volume'])
ticker.change = NumericHelper.to_d(output['priceChangePercent'])
ticker.timestamp = nil
ticker.payload = output
ticker
end
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
24 changes: 24 additions & 0 deletions lib/cryptoexchange/exchanges/new_capital/services/pairs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module Cryptoexchange::Exchanges
module NewCapital
module Services
class Pairs < Cryptoexchange::Services::Pairs
PAIRS_URL = "#{Cryptoexchange::Exchanges::NewCapital::Market::API_URL}/ticker"

def fetch
output = super
market_pairs = []
output.each do |pair|
base, target = pair["symbol"].split('_')
market_pairs << Cryptoexchange::Models::MarketPair.new(
base: base,
target: target,
market: NewCapital::Market::NAME
)
end
market_pairs
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.

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

Large diffs are not rendered by default.

62 changes: 62 additions & 0 deletions spec/exchanges/new_capital/integration/market_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
require 'spec_helper'

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

it 'fetch pairs' do
pairs = client.pairs('new_capital')
expect(pairs).not_to be_empty
pair = pairs.first
expect(pair.base).to_not be nil
expect(pair.target).to_not be nil
expect(pair.market).to eq 'new_capital'
end

it 'fetch ticker' do
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'
expect(ticker.last).to be_a Numeric
expect(ticker.bid).to be_a Numeric
expect(ticker.ask).to be_a Numeric
expect(ticker.low).to be_a Numeric
expect(ticker.high).to be_a Numeric
expect(ticker.volume).to be_a Numeric
expect(ticker.timestamp).to be nil
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
6 changes: 6 additions & 0 deletions spec/exchanges/new_capital/market_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'spec_helper'

RSpec.describe Cryptoexchange::Exchanges::NewCapital::Market do
it { expect(described_class::NAME).to eq 'new_capital' }
it { expect(described_class::API_URL).to eq 'https://api.new.capital/v1' }
end