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.
Elvis/unidax exchange intergration (coingecko#1442)
* elvis/financex-exchange-intergration * Revert "elvis/financex-exchange-intergration" This reverts commit d39c73b. * unidax exchange intergration * Update README.md * set timestamp as nil
- Loading branch information
Showing
8 changed files
with
207 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,12 @@ | ||
module Cryptoexchange::Exchanges | ||
module Unidax | ||
class Market < Cryptoexchange::Models::Market | ||
NAME = 'unidax' | ||
API_URL = 'https://api.unidax.com/open/api' | ||
|
||
def self.trade_page_url(args={}) | ||
"https://www.unidax.com/trade" | ||
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,38 @@ | ||
module Cryptoexchange::Exchanges | ||
module Unidax | ||
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['data'], market_pair) | ||
end | ||
|
||
def ticker_url(market_pair) | ||
"#{Cryptoexchange::Exchanges::Unidax::Market::API_URL}/get_ticker?symbol=#{market_pair.base.downcase}#{market_pair.target.downcase}" | ||
end | ||
|
||
def adapt(output, market_pair) | ||
ticker = Cryptoexchange::Models::Ticker.new | ||
ticker.base = market_pair.base | ||
ticker.target = market_pair.target | ||
ticker.market = Unidax::Market::NAME | ||
ticker.last = NumericHelper.to_d(output['last']) | ||
ticker.high = NumericHelper.to_d(output['high']) | ||
ticker.low = NumericHelper.to_d(output['low']) | ||
ticker.bid = NumericHelper.to_d(output['buy']) | ||
ticker.ask = NumericHelper.to_d(output['sell']) | ||
ticker.volume = NumericHelper.to_d(output['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,23 @@ | ||
module Cryptoexchange::Exchanges | ||
module Unidax | ||
module Services | ||
class Pairs < Cryptoexchange::Services::Pairs | ||
PAIRS_URL = "#{Cryptoexchange::Exchanges::Unidax::Market::API_URL}/common/symbols" | ||
|
||
def fetch | ||
output = super | ||
market_pairs = [] | ||
output["data"].each do |pair| | ||
target, base = pair["count_coin"], pair["base_coin"] | ||
market_pairs << Cryptoexchange::Models::MarketPair.new( | ||
base: base, | ||
target: target, | ||
market: Unidax::Market::NAME | ||
) | ||
end | ||
market_pairs | ||
end | ||
end | ||
end | ||
end | ||
end |
44 changes: 44 additions & 0 deletions
44
spec/cassettes/vcr_cassettes/Unidax/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.
44 changes: 44 additions & 0 deletions
44
spec/cassettes/vcr_cassettes/Unidax/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,39 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe 'Unidax integration specs' do | ||
let(:client) { Cryptoexchange::Client.new } | ||
let(:market) { 'unidax' } | ||
let(:zrx_usdt_pair) { Cryptoexchange::Models::MarketPair.new(base: 'ZRX', target: 'USDT', market: 'unidax') } | ||
|
||
it 'fetch pairs' do | ||
pairs = client.pairs('unidax') | ||
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 'unidax' | ||
end | ||
|
||
it 'give trade url' do | ||
trade_page_url = client.trade_page_url market, base: zrx_usdt_pair.base, target: zrx_usdt_pair.target | ||
expect(trade_page_url).to eq "https://www.unidax.com/trade" | ||
end | ||
|
||
it 'fetch ticker' do | ||
ticker = client.ticker(zrx_usdt_pair) | ||
|
||
expect(ticker.base).to eq 'ZRX' | ||
expect(ticker.target).to eq 'USDT' | ||
expect(ticker.market).to eq 'unidax' | ||
expect(ticker.last).to be_a Numeric | ||
expect(ticker.high).to be_a Numeric | ||
expect(ticker.low).to be_a Numeric | ||
expect(ticker.bid).to be_a Numeric | ||
expect(ticker.ask).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::Unidax::Market do | ||
it { expect(described_class::NAME).to eq 'unidax' } | ||
it { expect(described_class::API_URL).to eq 'https://api.unidax.com/open/api' } | ||
end |