Skip to content

Commit

Permalink
Verify orderbooks (coingecko#1465)
Browse files Browse the repository at this point in the history
* Verify orderbook - Bitmax, OKex, Fcoin

* Increase bitmax orderbook return, exclude timestamp from orderbook
  • Loading branch information
tmlee authored Apr 9, 2019
1 parent c14a277 commit 52f3a6d
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 34 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Or install it yourself as:
| Bitkub | Y | Y | Y | | Y | Y | bitkub | |
| Bitlish | Y | Y | Y | | Y | | bitlish | |
| Bitmart | Y | Y | Y | | Y | | bitmart | |
| Bitmax | Y | Y | Y | | Y | Y | bitmax | |
| Bitmax | Y | Y [x] | Y | | Y | Y | bitmax | |
| Bitmesh | Y | N | N | | Y | Y | bitmesh | |
| Bitmex (alpha) | Y | Y | Y | | Y | | bitmex |futures|
| BitOnBay | Y | | | | Y | | bitonbay | |
Expand Down Expand Up @@ -216,7 +216,7 @@ Or install it yourself as:
| Exx | Y | Y | Y | | Y | Y | exx | |
| F1cx | Y | Y | Y | | Y | Y | f1cx | |
| FatBTC | Y | Y | Y | | Y | | fatbtc | |
| Fcoin | Y | Y | Y | | Y | Y | fcoin | |
| Fcoin | Y | Y [x] | Y | | Y | Y | fcoin | |
| Fex | Y | N | N | | Y | | fex | |
| Financex | Y | N | N | | Y | Y | financex | |
| Fisco | Y | Y | Y | | Y | Y | fisco | |
Expand Down Expand Up @@ -302,7 +302,7 @@ Or install it yourself as:
| Oceanex | Y | Y | Y | | Y | Y | oceanex | |
| Octaex | Y | Y | Y | | Y | | octaex | |
| OKCoin | Y | | | | User-Defined| | okcoin | |
| OKEx | Y | Y | Y | | Y | Y | okex | |
| OKEx | Y | Y [x] | Y | | Y | Y | okex | |
| OKEx Perpetual Swaps (alpha) | Y | | | | Y | Y | okex_swap |futures|
| OmniTrade | Y | Y | Y | Y | Y | | omnitrade | |
| Ooobtc | Y | Y | Y | | Y | Y | ooobtc | |
Expand Down
10 changes: 4 additions & 6 deletions lib/cryptoexchange/exchanges/binance/services/order_book.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,21 @@ def order_book_url(market_pair)

def adapt(output, market_pair)
order_book = Cryptoexchange::Models::OrderBook.new
timestamp = Time.now.to_i

order_book.base = market_pair.base
order_book.target = market_pair.target
order_book.market = Binance::Market::NAME
order_book.asks = adapt_orders(output['asks'], timestamp)
order_book.bids = adapt_orders(output['bids'], timestamp)
order_book.timestamp = timestamp
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, timestamp)
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: timestamp)
timestamp: nil)
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/cryptoexchange/exchanges/bitmax/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 order_book_url(market_pair)
base = market_pair.base
target = market_pair.target
"#{Cryptoexchange::Exchanges::Bitmax::Market::API_URL}/depth?symbol=#{base}-#{target}"
"#{Cryptoexchange::Exchanges::Bitmax::Market::API_URL}/depth?symbol=#{base}-#{target}&n=100"
end

def adapt(output, market_pair)
Expand All @@ -34,8 +34,8 @@ def adapt(output, market_pair)
def adapt_orders(orders)
orders.collect do |order_entry|
price, amount = order_entry
Cryptoexchange::Models::Order.new(price: price,
amount: amount,
Cryptoexchange::Models::Order.new(price: price.to_f,
amount: amount.to_f,
timestamp: nil)
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/cryptoexchange/exchanges/fcoin/services/order_book.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def adapt(output, market_pair)
order_book.market = Fcoin::Market::NAME
order_book.asks = adapt_orders(output['asks'].each_slice(2).to_a)
order_book.bids = adapt_orders(output['bids'].each_slice(2).to_a)
order_book.timestamp = output['ts']
order_book.timestamp = nil
order_book.payload = output
order_book
end
Expand All @@ -33,7 +33,7 @@ def adapt_orders(orders)
orders.collect do |order_entry|
Cryptoexchange::Models::Order.new(price: order_entry[0],
amount: order_entry[1],
timestamp: Time.now.to_i)
timestamp: nil)
end
end
end
Expand Down
9 changes: 4 additions & 5 deletions lib/cryptoexchange/exchanges/okex/services/order_book.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,19 @@ def adapt(output, market_pair)
order_book.base = market_pair.base
order_book.target = market_pair.target
order_book.market = Okex::Market::NAME
order_book.asks = adapt_orders(output['asks'], timestamp)
order_book.bids = adapt_orders(output['bids'], timestamp)
order_book.timestamp = Time.now.to_i
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, timestamp)
def adapt_orders(orders)
orders.collect do |order_entry|
price = order_entry[0]
amount = order_entry[1]
Cryptoexchange::Models::Order.new(price: price,
amount: amount,
timestamp: timestamp)
timestamp: nil)
end
end
end
Expand Down

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

4 changes: 2 additions & 2 deletions spec/exchanges/binance/integration/market_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@
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_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_a Numeric
expect(order_book.timestamp).to be_nil
expect(order_book.payload).to_not be nil
end
end
4 changes: 2 additions & 2 deletions spec/exchanges/fcoin/integration/market_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
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_not be_nil
expect(order_book.timestamp).to be_a Numeric
expect(order_book.bids.first.timestamp).to be_nil
expect(order_book.timestamp).to be_nil
expect(order_book.payload).to_not be nil
end

Expand Down
4 changes: 2 additions & 2 deletions spec/exchanges/okex/integration/market_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
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_not be_nil
expect(order_book.timestamp).to be_a Numeric
expect(order_book.bids.first.timestamp).to be_nil
expect(order_book.timestamp).to be_nil
expect(order_book.payload).to_not be nil
end

Expand Down

0 comments on commit 52f3a6d

Please sign in to comment.