Skip to content

Commit

Permalink
ccx exchange intergration
Browse files Browse the repository at this point in the history
  • Loading branch information
winker committed May 6, 2019
1 parent d5463ae commit 16a17c8
Show file tree
Hide file tree
Showing 8 changed files with 213 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ Or install it yourself as:
| CPatex | Y | Y | Y | | Y | | c_patex | |
| Cbx | Y | Y | Y | | Y | Y | cbx | |
| CCex | Y | | | | Y | | ccex | |
| Ccx | Y | | | | Y | Y | ccx | |
| Cex | Y | Y | Y | | Y | | cex | |
| Cfinex | Y | Y | Y | | Y | Y | cfinex | |
| Chaince | Y | | | | Y | Y | chaince | |
Expand Down
9 changes: 9 additions & 0 deletions lib/cryptoexchange/exchanges/ccx/market.rb
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
40 changes: 40 additions & 0 deletions lib/cryptoexchange/exchanges/ccx/services/market.rb
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
24 changes: 24 additions & 0 deletions lib/cryptoexchange/exchanges/ccx/services/pairs.rb
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 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.

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

33 changes: 33 additions & 0 deletions spec/exchanges/ccx/integration/market_spec.rb
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
6 changes: 6 additions & 0 deletions spec/exchanges/ccx/market_spec.rb
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

0 comments on commit 16a17c8

Please sign in to comment.