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

WIP: add xbtprime #1800

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
92 changes: 0 additions & 92 deletions .byebug_history

This file was deleted.

8 changes: 8 additions & 0 deletions lib/cryptoexchange/exchanges/xbt_prime/market.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Cryptoexchange::Exchanges
module XbtPrime
class Market < Cryptoexchange::Models::Market
NAME = 'xbt_prime'
API_URL = 'https://api.primexbt.com/v1'
end
end
end
50 changes: 50 additions & 0 deletions lib/cryptoexchange/exchanges/xbt_prime/services/market.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
module Cryptoexchange::Exchanges
module XbtPrime
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::XbtPrime::Market::API_URL}/tickers"
end

def adapt_all(output)
output['ticker'].map do |pair|
base, target = pair['symbol'].split('_')
market_pair = Cryptoexchange::Models::MarketPair.new(
base: base,
target: target,
market: XbtPrime::Market::NAME
)
adapt(market_pair, pair)
end
end

def adapt(market_pair, output)
ticker = Cryptoexchange::Models::Ticker.new
ticker.base = market_pair.base
ticker.target = market_pair.target
ticker.market = XbtPrime::Market::NAME
ticker.last = NumericHelper.to_d(output['last'])
ticker.high = NumericHelper.to_d(output['high'])
ticker.low = NumericHelper.to_d(output['low'])
ticker.bid = NumericHelper.to_d(output['buy'])
ticker.ask = NumericHelper.to_d(output['sell'])
ticker.volume = NumericHelper.to_d(output['vol'])
ticker.timestamp = nil
ticker.payload = output
ticker
end
end
end
end
end
42 changes: 42 additions & 0 deletions lib/cryptoexchange/exchanges/xbt_prime/services/order_book.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module Cryptoexchange::Exchanges
module XbtPrime
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)
"#{Cryptoexchange::Exchanges::XbtPrime::Market::API_URL}/depth?symbol=#{market_pair.base.downcase}_#{market_pair.target.downcase}"
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 = XbtPrime::Market::NAME
order_book.asks = adapt_orders(output['asks'])
order_book.bids = adapt_orders(output['bids'])
order_book.timestamp = Time.now.to_i
order_book.payload = output
order_book
end

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

def fetch
output = super
market_pairs = []
output['data'].each do |pair|
next unless pair['name'].include?('/')

base, target = pair['name'].split('/')
market_pairs << Cryptoexchange::Models::MarketPair.new(
base: base,
target: target,
market: XbtPrime::Market::NAME
)
end.compact
market_pairs
end
end
end
end
end
31 changes: 31 additions & 0 deletions lib/cryptoexchange/exchanges/xbt_prime/services/trades.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module Cryptoexchange::Exchanges
module XbtPrime
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)
"#{Cryptoexchange::Exchanges::XbtPrime::Market::API_URL}/trades?symbol=#{market_pair.base.downcase}_#{market_pair.target.downcase}"
end

def adapt(output, market_pair)
output.collect do |trade|
tr = Cryptoexchange::Models::Trade.new
tr.base = market_pair.base
tr.target = market_pair.target
tr.market = XbtPrime::Market::NAME
tr.type = trade['side']
tr.price = trade['price']
tr.amount = trade['amount']
tr.timestamp = trade['timestamp']/1000
tr.payload = trade
tr
end
end
end
end
end
end