forked from coingecko/cryptoexchange
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Cryptoexchange::Exchanges | ||
module Xt | ||
class Market < Cryptoexchange::Models::Market | ||
NAME = 'xt' | ||
API_URL = 'https://kline.xt.com/api/data/v1' | ||
|
||
def self.trade_page_url(args={}) | ||
"https://www.xt.com/trade/#{args[:base].downcase}_#{args[:target].downcase}" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
module Cryptoexchange::Exchanges | ||
module Xt | ||
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::Xt::Market::API_URL}/tickers?isUseMarketName=true" | ||
end | ||
|
||
def adapt_all(output) | ||
output['datas'].map do |pair| | ||
base, target = pair[0].split('_') | ||
market_pair = Cryptoexchange::Models::MarketPair.new( | ||
base: base, | ||
target: target, | ||
market: Xt::Market::NAME | ||
) | ||
adapt(market_pair, pair[1]) | ||
end | ||
end | ||
|
||
def adapt(market_pair, output) | ||
ticker = Cryptoexchange::Models::Ticker.new | ||
ticker.base = market_pair.base | ||
ticker.target = market_pair.target | ||
ticker.market = Xt::Market::NAME | ||
ticker.last = NumericHelper.to_d(output[1]) | ||
ticker.high = NumericHelper.to_d(output[2]) | ||
ticker.low = NumericHelper.to_d(output[3]) | ||
ticker.volume = NumericHelper.to_d(output[4]) | ||
ticker.change = NumericHelper.to_d(output[5]) | ||
ticker.timestamp = nil | ||
ticker.payload = output | ||
ticker | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Cryptoexchange::Exchanges | ||
module Xt | ||
module Services | ||
class Pairs < Cryptoexchange::Services::Pairs | ||
PAIRS_URL = "#{Cryptoexchange::Exchanges::Xt::Market::API_URL}/tickers?isUseMarketName=true" | ||
|
||
def fetch | ||
output = super | ||
market_pairs = [] | ||
output['datas'].each do |pair| | ||
base, target = pair[0].split('_') | ||
market_pairs << Cryptoexchange::Models::MarketPair.new( | ||
base: base, | ||
target: target, | ||
market: Xt::Market::NAME | ||
) | ||
end | ||
market_pairs | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe 'Worldcore integration specs' do | ||
let(:client) { Cryptoexchange::Client.new } | ||
let(:btc_usdt_pair) { Cryptoexchange::Models::MarketPair.new(base: 'BTC', target: 'USDT', market: 'xt') } | ||
|
||
it 'has trade_page_url' do | ||
trade_page_url = client.trade_page_url btc_usdt_pair.market, base: btc_usdt_pair.base, target: btc_usdt_pair.target | ||
expect(trade_page_url).to eq "https://www.xt.com/trade/btc_usdt" | ||
end | ||
|
||
it 'fetch pairs' do | ||
pairs = client.pairs('xt') | ||
expect(pairs).not_to be_empty | ||
|
||
pair = pairs.first | ||
expect(pair.base).to_not be nil | ||
expect(pair.target).to_not be nil | ||
expect(pair.market).to eq 'xt' | ||
end | ||
|
||
it 'fetch ticker' do | ||
ticker = client.ticker(btc_usdt_pair) | ||
|
||
expect(ticker.base).to eq 'BTC' | ||
expect(ticker.target).to eq 'USDT' | ||
expect(ticker.market).to eq 'xt' | ||
expect(ticker.last).to be_a Numeric | ||
expect(ticker.low).to be_a Numeric | ||
expect(ticker.high).to be_a Numeric | ||
expect(ticker.volume).to be_a Numeric | ||
expect(ticker.change).to be_a Numeric | ||
expect(ticker.timestamp).to be nil | ||
expect(ticker.payload).to_not be nil | ||
end | ||
|
||
# it 'fetch order book' do | ||
# order_book = client.order_book(btc_usdt_pair) | ||
|
||
# expect(order_book.base).to eq 'BTC' | ||
# expect(order_book.target).to eq 'USDT' | ||
# expect(order_book.market).to eq 'xt' | ||
# 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 > 5 | ||
# expect(order_book.bids.count).to be > 5 | ||
# expect(order_book.timestamp).to be_a Numeric | ||
# expect(2000..Date.today.year).to include(Time.at(order_book.timestamp).year) | ||
# expect(order_book.payload).to_not be nil | ||
# end | ||
|
||
# it 'fetch trade' do | ||
# trades = client.trades(btc_usdt_pair) | ||
# trade = trades.sample | ||
|
||
# expect(trades).to_not be_empty | ||
# expect(trade.base).to eq 'BTC' | ||
# expect(trade.target).to eq 'USDT' | ||
# expect(trade.market).to eq 'xt' | ||
# expect(trade.trade_id).to_not be_nil | ||
# expect(['buy', 'sell']).to include trade.type | ||
# expect(trade.price).to_not be_nil | ||
# expect(trade.amount).to_not be_nil | ||
# expect(trade.timestamp).to be_a Numeric | ||
# expect(2000..Date.today.year).to include(Time.at(trade.timestamp).year) | ||
# expect(trade.payload).to_not be nil | ||
# end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe Cryptoexchange::Exchanges::Xt::Market do | ||
it { expect(described_class::NAME).to eq 'xt' } | ||
it { expect(described_class::API_URL).to eq 'https://kline.xt.com/api/data/v1' } | ||
end |