Skip to content
This repository has been archived by the owner on Jun 22, 2020. It is now read-only.

change ddex data source from api v3 to api v4 #2016

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/cryptoexchange/exchanges/ddex/market.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ module Cryptoexchange::Exchanges
module Ddex
class Market < Cryptoexchange::Models::Market
NAME = 'ddex'
API_URL = 'https://api.ddex.io/v3'
API_URL = 'https://api.ddex.io/v4'

def self.trade_page_url(args={})
"https://ddex.io/trade/#{args[:base]}-#{args[:target]}"
"https://ddex.io/margin/#{args[:base]}-#{args[:target]}"
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/cryptoexchange/exchanges/ddex/services/order_book.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def supports_individual_ticker_query?

def fetch(market_pair)
output = super(ticker_url(market_pair))
adapt(output['data']['orderBook'], market_pair)
adapt(output['data']['orderbook'], market_pair)
end

def ticker_url(market_pair)
Expand Down
4 changes: 2 additions & 2 deletions lib/cryptoexchange/exchanges/ddex/services/pairs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def fetch
def adapt(output)
output['data']['markets'].map do |pair|
Cryptoexchange::Models::MarketPair.new(
base: pair['baseToken'],
target: pair['quoteToken'],
base: pair['baseAsset'],
target: pair['quoteAsset'],
market: Ddex::Market::NAME
)
end
Expand Down

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

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions spec/exchanges/ddex/integration/market_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

RSpec.describe 'Ddex integration specs' do
let(:client) { Cryptoexchange::Client.new }
let(:abt_weth_pair) { Cryptoexchange::Models::MarketPair.new(base: 'ABT', target: 'WETH', market: 'ddex') }
let(:eth_usdt_pair) { Cryptoexchange::Models::MarketPair.new(base: 'ETH', target: 'USDT', market: 'ddex') }

it 'fetch pairs' do
pairs = client.pairs('ddex')
Expand All @@ -15,15 +15,15 @@
end

it 'give trade url' do
trade_page_url = client.trade_page_url 'ddex', base: abt_weth_pair.base, target: abt_weth_pair.target
expect(trade_page_url).to eq "https://ddex.io/trade/ABT-WETH"
trade_page_url = client.trade_page_url 'ddex', base: eth_usdt_pair.base, target: eth_usdt_pair.target
expect(trade_page_url).to eq "https://ddex.io/margin/ETH-USDT"
end

it 'fetch ticker' do
ticker = client.ticker(abt_weth_pair)
ticker = client.ticker(eth_usdt_pair)

expect(ticker.base).to eq 'ABT'
expect(ticker.target).to eq 'WETH'
expect(ticker.base).to eq 'ETH'
expect(ticker.target).to eq 'USDT'
expect(ticker.market).to eq 'ddex'

expect(ticker.last).to be_a Numeric
Expand All @@ -38,10 +38,10 @@
end

it 'fetch order book' do
order_book = client.order_book(abt_weth_pair)
order_book = client.order_book(eth_usdt_pair)

expect(order_book.base).to eq 'ABT'
expect(order_book.target).to eq 'WETH'
expect(order_book.base).to eq 'ETH'
expect(order_book.target).to eq 'USDT'
expect(order_book.market).to eq 'ddex'
expect(order_book.asks).to_not be_empty
expect(order_book.bids).to_not be_empty
Expand All @@ -54,12 +54,12 @@
end

it 'fetch trade' do
trades = client.trades(abt_weth_pair)
trades = client.trades(eth_usdt_pair)
trade = trades.sample

expect(trades).to_not be_empty
expect(trade.base).to eq 'ABT'
expect(trade.target).to eq 'WETH'
expect(trade.base).to eq 'ETH'
expect(trade.target).to eq 'USDT'
expect(trade.market).to eq 'ddex'
expect(trade.trade_id).to_not be_nil
expect(trade.price).to_not be_nil
Expand Down
2 changes: 1 addition & 1 deletion spec/exchanges/ddex/market_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

RSpec.describe Cryptoexchange::Exchanges::Ddex::Market do
it { expect(described_class::NAME).to eq 'ddex' }
it { expect(described_class::API_URL).to eq 'https://api.ddex.io/v3' }
it { expect(described_class::API_URL).to eq 'https://api.ddex.io/v4' }
end