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

add dydx orderbook #1994

Open
wants to merge 1 commit 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
2 changes: 1 addition & 1 deletion lib/cryptoexchange/exchanges/dydx/market.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Cryptoexchange::Exchanges
module Dydx
class Market < Cryptoexchange::Models::Market
NAME = 'dydx'
API_URL = 'https://api.dydx.exchange/v1/stats/markets'
API_URL = 'https://api.dydx.exchange/v1'

def self.trade_page_url(args={})
"https://trade.dydx.exchange/markets"
Expand Down
2 changes: 1 addition & 1 deletion lib/cryptoexchange/exchanges/dydx/services/market.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def fetch
end

def ticker_url
"#{Cryptoexchange::Exchanges::Dydx::Market::API_URL}"
"#{Cryptoexchange::Exchanges::Dydx::Market::API_URL}/stats/markets"
end


Expand Down
46 changes: 46 additions & 0 deletions lib/cryptoexchange/exchanges/dydx/services/order_book.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module Cryptoexchange::Exchanges
module Dydx
module Services
class OrderBook < Cryptoexchange::Services::Market
class << self
def supports_individual_ticker_query?
true
end
end

def fetch(market_pair)
puts ticker_url(market_pair)
output = super(ticker_url(market_pair))
adapt(output, market_pair)
end

def ticker_url(market_pair)
base = market_pair.base
target = market_pair.target
"#{Cryptoexchange::Exchanges::Dydx::Market::API_URL}/orderbook/#{base}-#{target}"
end

def adapt(output, market_pair)
order_book = Cryptoexchange::Models::OrderBook.new

order_book.base = market_pair.base
order_book.target = market_pair.target
order_book.market = Dydx::Market::NAME
order_book.asks = adapt_orders(output['bids'])
order_book.bids = adapt_orders(output['asks'])
order_book.timestamp = nil
order_book.payload = output
order_book
end

def adapt_orders(orders)
orders.collect do |order_entry|
Cryptoexchange::Models::Order.new(price: order_entry['price'],
amount: order_entry['amount'].to_f,
timestamp: nil)
end
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/cryptoexchange/exchanges/dydx/services/pairs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Cryptoexchange::Exchanges
module Dydx
module Services
class Pairs < Cryptoexchange::Services::Pairs
PAIRS_URL = "#{Cryptoexchange::Exchanges::Dydx::Market::API_URL}"
PAIRS_URL = "#{Cryptoexchange::Exchanges::Dydx::Market::API_URL}/stats/markets"

def fetch
output = super
Expand Down
2 changes: 1 addition & 1 deletion spec/exchanges/dydx/market_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

RSpec.describe Cryptoexchange::Exchanges::Dydx::Market do
it { expect(described_class::NAME).to eq 'dydx' }
it { expect(described_class::API_URL).to eq 'https://api.dydx.exchange/v1/stats/markets' }
it { expect(described_class::API_URL).to eq 'https://api.dydx.exchange/v1' }
end