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 7f4b94b commit 35615be
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/cryptoexchange/exchanges/new_capital/market.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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[:target].downcase}_#{args[:base].downcase}"
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
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

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

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

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')}

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(twins_btc_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

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

0 comments on commit 35615be

Please sign in to comment.