forked from coingecko/cryptoexchange
-
Notifications
You must be signed in to change notification settings - Fork 0
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
winker
committed
May 6, 2019
1 parent
d5463ae
commit 16a17c8
Showing
8 changed files
with
213 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
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,9 @@ | ||
module Cryptoexchange::Exchanges | ||
module Ccx | ||
class Market < Cryptoexchange::Models::Market | ||
NAME = 'ccx' | ||
API_URL = 'https://manager.ccxcanada.com/api/v2' | ||
|
||
end | ||
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,40 @@ | ||
module Cryptoexchange::Exchanges | ||
module Ccx | ||
module Services | ||
class Market < 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) | ||
base = market_pair.base.downcase | ||
target = market_pair.target.downcase | ||
"#{Cryptoexchange::Exchanges::Ccx::Market::API_URL}/tickers/#{base}#{target}.json" | ||
end | ||
|
||
def adapt(output, market_pair) | ||
ticker = Cryptoexchange::Models::Ticker.new | ||
ticker.base = market_pair.base | ||
ticker.target = market_pair.target | ||
ticker.market = Ccx::Market::NAME | ||
ticker.ask = NumericHelper.to_d(output['ticker']['sell']) | ||
ticker.bid = NumericHelper.to_d(output['ticker']['buy']) | ||
ticker.high = NumericHelper.to_d(output['ticker']['high']) | ||
ticker.low = NumericHelper.to_d(output['ticker']['low']) | ||
ticker.last = NumericHelper.to_d(output['ticker']['last']) | ||
ticker.volume = NumericHelper.to_d(output['ticker']['vol']) | ||
ticker.timestamp = nil | ||
ticker.payload = output | ||
ticker | ||
end | ||
end | ||
end | ||
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,24 @@ | ||
module Cryptoexchange::Exchanges | ||
module Ccx | ||
module Services | ||
class Pairs < Cryptoexchange::Services::Pairs | ||
PAIRS_URL = "#{Cryptoexchange::Exchanges::Ccx::Market::API_URL}/markets.json" | ||
|
||
def fetch | ||
output = super | ||
adapt(output) | ||
end | ||
|
||
def adapt(output) | ||
output.map do |pair| | ||
Cryptoexchange::Models::MarketPair.new( | ||
base: pair['base_unit'], | ||
target: pair['quote_unit'], | ||
market: Ccx::Market::NAME | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
50 changes: 50 additions & 0 deletions
50
spec/cassettes/vcr_cassettes/Ccx/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.
50 changes: 50 additions & 0 deletions
50
spec/cassettes/vcr_cassettes/Ccx/integration_specs_fetch_ticker.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,33 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe 'Ccx integration specs' do | ||
let(:client) { Cryptoexchange::Client.new } | ||
|
||
it 'fetch pairs' do | ||
pairs = client.pairs('ccx') | ||
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 'ccx' | ||
end | ||
|
||
it 'fetch ticker' do | ||
eth_aud_pair = Cryptoexchange::Models::MarketPair.new(base: 'btc', target: 'usdt', market: 'ccx') | ||
ticker = client.ticker(eth_aud_pair) | ||
|
||
expect(ticker.base).to eq 'BTC' | ||
expect(ticker.target).to eq 'USDT' | ||
expect(ticker.market).to eq 'ccx' | ||
expect(ticker.last).to be_a Numeric | ||
expect(ticker.high).to be_a Numeric | ||
expect(ticker.low).to be_a Numeric | ||
expect(ticker.ask).to be_a Numeric | ||
expect(ticker.bid).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::Ccx::Market do | ||
it { expect(described_class::NAME).to eq 'ccx' } | ||
it { expect(described_class::API_URL).to eq 'https://manager.ccxcanada.com/api/v2' } | ||
end |