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 241
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
6 changed files
with
169 additions
and
0 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
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
51
lib/cryptoexchange/exchanges/new_capital/services/market.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,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
24
lib/cryptoexchange/exchanges/new_capital/services/pairs.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,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 |
45 changes: 45 additions & 0 deletions
45
spec/cassettes/vcr_cassettes/NewCapital/integration_specs_fetch_pairs.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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 |
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,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 |