Skip to content

Commit

Permalink
Elvis/unidax exchange intergration (coingecko#1442)
Browse files Browse the repository at this point in the history
* 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
ElvisLYC authored and wongy91 committed Mar 25, 2019
1 parent 50cf664 commit 99730e1
Show file tree
Hide file tree
Showing 8 changed files with 207 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ Or install it yourself as:
| TRXMarket | Y | | | | Y | | trx_market | |
| Txbit | Y | | | | Y | Y | txbit | |
| UEX | Y | | | | Y | | uex | |
| Unidax | Y | N | N | | Y | N | unidax | |
| Uniswap | Y | N | N | | Y | N | uniswap | |
| Unocoin | | | | | | | unocoin | |
| Upbit | Y | Y | Y | | Y | Y | upbit | |
Expand Down
12 changes: 12 additions & 0 deletions lib/cryptoexchange/exchanges/unidax/market.rb
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
38 changes: 38 additions & 0 deletions lib/cryptoexchange/exchanges/unidax/services/market.rb
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
23 changes: 23 additions & 0 deletions lib/cryptoexchange/exchanges/unidax/services/pairs.rb
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

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.

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

0 comments on commit 99730e1

Please sign in to comment.