Skip to content

Commit

Permalink
Implement Poloniex orderbook, fix bibox, fcoin orderbook data
Browse files Browse the repository at this point in the history
  • Loading branch information
tmlee committed May 3, 2019
1 parent 21fcedc commit 4c68fd0
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 10 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ Or install it yourself as:
| Fubt | Y | | | | Y | Y | fubt | |
| Gate | Y | Y [x] | Y | | Y | Y | gate | |
| Gatecoin | Y | | | | Y | | gatecoin | |
| GDAX(Coinbase Pro)| Y | | | | Y | Y | gdax | |
| GDAX(Coinbase Pro)| Y | Y [x] | | | Y | Y | gdax | |
| Gemini | Y | Y | Y | | Y | | gemini | |
| GetBTC | Y | Y | Y | | User-Defined| Y | getbtc | |
| Gibraltar | Y | N | N | | Y | Y | gbx | |
Expand Down Expand Up @@ -324,7 +324,7 @@ Or install it yourself as:
| Paribu | Y | | | | Y | | paribu | |
| Paro Exchange | Y | | | | Y | | paroexchange | |
| Paymium | Y | Y | Y | | User-Defined| | paymium | |
| Poloniex | Y | | | | Y | Y | poloniex | |
| Poloniex | Y | Y [x] | | | Y | Y | poloniex | |
| Purcow | Y | | | | Y | Y | purcow | |
| QBTC | Y | Y | Y | | Y | | qbtc | |
| Qryptos | Y | | | | Y | | qryptos | |
Expand Down Expand Up @@ -376,7 +376,7 @@ Or install it yourself as:
| Unidax | Y | N | N | | Y | N | unidax | |
| Uniswap | Y | N | N | | Y | N | uniswap | |
| Unocoin | | | | | | | unocoin | |
| Upbit | Y | Y | Y | | Y | Y | upbit | |
| Upbit | Y | Y [x] | Y | | Y | Y | upbit | |
| Vaultmex | Y | Y | Y | | Y | Y | vaultmex | |
| Vbitex | Y | N | N | | Y | Y | vbitex | |
| Vebitcoin | Y | N | N | | Y | N | vebitcoin | |
Expand Down
2 changes: 1 addition & 1 deletion lib/cryptoexchange/exchanges/bibox/services/order_book.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def fetch(market_pair)
def ticker_url(market_pair)
base = market_pair.base
target = market_pair.target
"#{Cryptoexchange::Exchanges::Bibox::Market::API_URL}/mdata?cmd=depth&pair=#{base}_#{target}&size=15"
"#{Cryptoexchange::Exchanges::Bibox::Market::API_URL}/mdata?cmd=depth&pair=#{base}_#{target}&size=200"
end

def adapt(output, market_pair)
Expand Down
2 changes: 1 addition & 1 deletion lib/cryptoexchange/exchanges/fcoin/services/order_book.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def fetch(market_pair)
end

def ticker_url(market_pair)
"#{Cryptoexchange::Exchanges::Fcoin::Market::API_URL}/market/depth/full/#{market_pair.base.downcase}#{market_pair.target.downcase}"
"#{Cryptoexchange::Exchanges::Fcoin::Market::API_URL}/market/depth/L150/#{market_pair.base.downcase}#{market_pair.target.downcase}"
end

def adapt(output, market_pair)
Expand Down
57 changes: 57 additions & 0 deletions lib/cryptoexchange/exchanges/poloniex/services/order_book.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
module Cryptoexchange::Exchanges
module Poloniex
module Services
class OrderBook < Cryptoexchange::Services::Market
class << self
def supports_individual_ticker_query?
false
end
end

def fetch
output = super(self.order_book_url)
adapt_all(output)
end

def order_book_url
"#{Cryptoexchange::Exchanges::Poloniex::Market::API_URL}?command=returnOrderBook&currencyPair=all&depth=100"
end

def adapt_all(output)
output.map do |pair, ticker|
# Target comes first in Poloniex ie. BTC-BCN
# BTC cannot be a base in this pair
target, base = pair.split('_')
market_pair = Cryptoexchange::Models::MarketPair.new(
base: base,
target: target,
market: Poloniex::Market::NAME
)

adapt(ticker, market_pair)
end
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 = Poloniex::Market::NAME
order_book.asks = adapt_orders(output['asks'])
order_book.bids = adapt_orders(output['bids'])
order_book.payload = output
order_book
end

def adapt_orders(orders)
orders.collect do |order_entry|
Cryptoexchange::Models::Order.new(price: NumericHelper.to_d(order_entry[0]),
amount: NumericHelper.to_d(order_entry[1]),
timestamp: nil)
end
end
end
end
end
end

Large diffs are not rendered by default.

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions spec/exchanges/poloniex/integration/market_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,22 @@

expect(ticker.payload).to_not be nil
end

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

expect(order_book.base).to eq 'LTC'
expect(order_book.target).to eq 'BTC'
expect(order_book.market).to eq 'poloniex'

expect(order_book.asks).to_not be_empty
expect(order_book.bids).to_not be_empty
expect(order_book.asks.first.price).to_not be_nil
expect(order_book.bids.first.amount).to_not be_nil
expect(order_book.bids.first.timestamp).to be_nil
expect(order_book.asks.count).to be > 10
expect(order_book.bids.count).to be > 10
expect(order_book.timestamp).to be_nil
expect(order_book.payload).to_not be nil
end
end

0 comments on commit 4c68fd0

Please sign in to comment.