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

Add ionomy exchange #2067

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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ Or install it yourself as:
| IndependentReserve| Y | Y [x] | N | | Y | Y |independent_reserve| |
| InfinityCoin | Y | | | | Y | Y | infinity_coin | |
| InstantBitex | Y | Y [x] | Y | | Y | | instantbitex | |
| ionomy | Y | Y | Y | | Y | Y | ionomy | |
| Iqfinex | Y | Y | Y | | Y | Y | iqfinex | |
| Ironex | Y | | | | Y | | ironex | |
| Itbit | Y | Y [x] | Y | | User-Defined| | itbit | |
Expand Down
12 changes: 12 additions & 0 deletions lib/cryptoexchange/exchanges/ionomy/market.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Cryptoexchange::Exchanges
module Ionomy
class Market < Cryptoexchange::Models::Market
NAME = 'ionomy'
API_URL = 'https://ionomy.com/api/v1'

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

def fetch
output = super ticker_url
adapt_all(output)
end

def ticker_url
"#{Cryptoexchange::Exchanges::Ionomy::Market::API_URL}/public/markets-summaries"
end

def adapt_all(output)
output['data'].map do |output|
target, base = output['market'].split('-')
market_pair = Cryptoexchange::Models::MarketPair.new(
base: base,
target: target,
market: Ionomy::Market::NAME
)

adapt(output, market_pair)
end
end

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

def fetch(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::Ionomy::Market::API_URL}/public/orderbook?market=#{target}-#{base}&type=both"
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 = Ionomy::Market::NAME
order_book.asks = adapt_orders output['data']['asks']
order_book.bids = adapt_orders output['data']['bids']
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['size']
)
end
end
end
end
end
end
25 changes: 25 additions & 0 deletions lib/cryptoexchange/exchanges/ionomy/services/pairs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module Cryptoexchange::Exchanges
module Ionomy
module Services
class Pairs < Cryptoexchange::Services::Pairs
PAIRS_URL = "#{Cryptoexchange::Exchanges::Ionomy::Market::API_URL}/public/markets"

def fetch
output = super
adapt(output)
end

def adapt(output)
output['data'].map do |output|
target, base = output['market'].split('-')
Cryptoexchange::Models::MarketPair.new(
base: base,
target: target,
market: Ionomy::Market::NAME
)
end
end
end
end
end
end
34 changes: 34 additions & 0 deletions lib/cryptoexchange/exchanges/ionomy/services/trades.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module Cryptoexchange::Exchanges
module Ionomy
module Services
class Trades < Cryptoexchange::Services::Market
def fetch(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::Ionomy::Market::API_URL}/public/market-history?market=#{target}-#{base}"
end

def adapt(output, market_pair)
output['data'].collect do |trade|
tr = Cryptoexchange::Models::Trade.new
tr.trade_id = nil
tr.base = market_pair.base
tr.target = market_pair.target
tr.market = Ionomy::Market::NAME
tr.type = (trade['type'].include? "_BUY") ? "buy" : "sell"
tr.price = trade['price']
tr.amount = trade['amount']
tr.timestamp = DateTime.parse(trade['createdAt']).to_time.to_i
tr.payload = trade
tr
end
end
end
end
end
end

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

Loading