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

Implement zooomex exchange #1708

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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ Or install it yourself as:
| Zeniex | Y | Y | Y | | Y | | zeniex | |
| ZG | Y | Y [x] | Y | | Y | Y | zg | |
| ZG.TOP | Y | | | | Y | | zgtop | |
| Zooomex | Y | Y [x] | Y | | Y | Y | zooomex | |

** Mapping and data may be incorrect (Cannot determine correctness)

Expand Down
12 changes: 12 additions & 0 deletions lib/cryptoexchange/exchanges/zooomex/market.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Cryptoexchange::Exchanges
module Zooomex
class Market < Cryptoexchange::Models::Market
NAME = 'zooomex'
API_URL = 'https://www.zooomex.com/api/v2/trade'

def self.trade_page_url(args={})
"https://www.zooomex.com/exchange/#{args[:base]}-#{args[:target]}"
end
end
end
end
44 changes: 44 additions & 0 deletions lib/cryptoexchange/exchanges/zooomex/services/market.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module Cryptoexchange::Exchanges
module Zooomex
module Services
class Market < Cryptoexchange::Services::Market
class << self
def supports_individual_ticker_query?
true
end
end

def fetch(market_pair)
ctx = OpenSSL::SSL::SSLContext.new
ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
result = HTTP.get(ticker_url(market_pair), ssl_context: ctx)
output = JSON.parse(result)
adapt(output, market_pair)
end

def ticker_url(market_pair)
"#{Cryptoexchange::Exchanges::Zooomex::Market::API_URL}/public/markets/#{market_pair.inst_id}/tickers"
end

def adapt(output, market_pair)
ticker = Cryptoexchange::Models::Ticker.new
market = output

ticker = Cryptoexchange::Models::Ticker.new
ticker.base = market_pair.base
ticker.target = market_pair.target
ticker.market = Zooomex::Market::NAME
ticker.last = NumericHelper.to_d(market['last'])
ticker.bid = NumericHelper.to_d(market['buy'])
ticker.ask = NumericHelper.to_d(market['sell'])
ticker.high = NumericHelper.to_d(market['high'])
ticker.low = NumericHelper.to_d(market['low'])
ticker.volume = NumericHelper.to_d(market['volume'])
ticker.timestamp = nil
ticker.payload = output
ticker
end
end
end
end
end
46 changes: 46 additions & 0 deletions lib/cryptoexchange/exchanges/zooomex/services/order_book.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module Cryptoexchange::Exchanges
module Zooomex
module Services
class OrderBook < Cryptoexchange::Services::Market
class << self
def supports_individual_ticker_query?
true
end
end

def fetch(market_pair)
ctx = OpenSSL::SSL::SSLContext.new
ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
result = HTTP.get(order_book_url(market_pair), ssl_context: ctx)
output = JSON.parse(result)
adapt(output, market_pair)
end

def order_book_url(market_pair)
"#{Cryptoexchange::Exchanges::Zooomex::Market::API_URL}/public/markets/#{market_pair.inst_id}/depth"
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 = Zooomex::Market::NAME
order_book.asks = adapt_orders output['asks']
order_book.bids = adapt_orders output['bids']
order_book.timestamp = output['timestamp']
order_book.payload = output
order_book
end

def adapt_orders(orders)
orders.collect do |order_entry|
price = NumericHelper.to_d(order_entry[0])
amount = NumericHelper.to_d(order_entry[1])
Cryptoexchange::Models::Order.new(price: price,
amount: amount)
end
end
end
end
end
end
35 changes: 35 additions & 0 deletions lib/cryptoexchange/exchanges/zooomex/services/pairs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module Cryptoexchange::Exchanges
module Zooomex
module Services
class Pairs < Cryptoexchange::Services::Pairs
PAIRS_URL = "#{Cryptoexchange::Exchanges::Zooomex::Market::API_URL}/public/markets"

def fetch
ctx = OpenSSL::SSL::SSLContext.new
ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
result = HTTP.get(PAIRS_URL, ssl_context: ctx)
output = JSON.parse(result)
adapt(output)
end

def adapt(output)
market_pairs = []
output.each do |pair|
base = pair["base_unit"]
target = pair["quote_unit"]
id_market = pair["id"]
next unless base && target
market_pairs << Cryptoexchange::Models::MarketPair.new(
base: base,
target: target,
market: Zooomex::Market::NAME,
inst_id: id_market
)
end
market_pairs
end
end
end
end
end

37 changes: 37 additions & 0 deletions lib/cryptoexchange/exchanges/zooomex/services/trades.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module Cryptoexchange::Exchanges
module Zooomex
module Services
class Trades < Cryptoexchange::Services::Market

def fetch(market_pair)
ctx = OpenSSL::SSL::SSLContext.new
ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
result = HTTP.get(trades_url(market_pair), ssl_context: ctx)
output = JSON.parse(result)
adapt(output, market_pair)
end

def trades_url(market_pair)
"#{Cryptoexchange::Exchanges::Zooomex::Market::API_URL}/public/markets/#{market_pair.inst_id}/trades"
end

def adapt(output, market_pair)
output.collect do |trade|
tr = Cryptoexchange::Models::Trade.new
tr.trade_id = trade['id']
tr.base = market_pair.base
tr.target = market_pair.target
tr.type = trade['taker_type'] == 'buy' ? 'buy' : 'sell'
tr.price = trade['price']
tr.amount = trade['volume']
tr.timestamp = DateTime.parse(trade['created_at']).strftime("%s").to_i
tr.payload = trade
tr.market = Zooomex::Market::NAME
tr
end
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.

Loading