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

add veridex markets and pairs #1651

Open
wants to merge 9 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
12 changes: 12 additions & 0 deletions lib/cryptoexchange/exchanges/veridex/market.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Cryptoexchange::Exchanges
module Veridex
class Market < Cryptoexchange::Models::Market
NAME = 'veridex'
API_URL = 'https://dex-backend.verisafe.io/v3'

def self.trade_page_url(args={})
"https://dex.verisafe.io/#/erc20/?base=#{args[:base]}&quote=#{args[:target]}"
end
end
end
end
56 changes: 56 additions & 0 deletions lib/cryptoexchange/exchanges/veridex/services/market.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
module Cryptoexchange::Exchanges
module Veridex
module Services
class Market < Cryptoexchange::Services::Market
class << self
def supports_individual_ticker_query?
false
end
end

def fetch
outputs = []
(0..0).each do |page_id|
ticker_output = super(ticker_url(page_id))
break if ticker_output.empty?
outputs = outputs + ticker_output['records']
end
adapt_all(outputs)
end

def ticker_url(page_id)
"#{Cryptoexchange::Exchanges::Veridex::Market::API_URL}/markets?include=stats&page=#{page_id}&perPage=100"
end

def adapt_all(output)
output.map do |pair_ticker|
base, target = pair_ticker["pair"].split("-")
market_pair = Cryptoexchange::Models::MarketPair.new(
base: base,
target: target,
market: Veridex::Market::NAME
)
adapt(market_pair, pair_ticker["stats"])
end
end

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

ticker.base = market_pair.base
ticker.target = market_pair.target
ticker.market = Veridex::Market::NAME
ticker.bid = NumericHelper.to_d(stats_output['price_max_24'])
ticker.ask = NumericHelper.to_d(stats_output['price_min_24'])
ticker.last = NumericHelper.to_d(stats_output['last_price'])
vol = NumericHelper.to_d(stats_output['volume_24'])
ticker.volume = (vol.nil? || vol == "") ? 0 : NumericHelper.divide(vol, ticker.last)
ticker.change = NumericHelper.to_d(stats_output['last_price_change'])
ticker.timestamp = nil
ticker.payload = [stats_output]
ticker
end
end
end
end
end
32 changes: 32 additions & 0 deletions lib/cryptoexchange/exchanges/veridex/services/pairs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Cryptoexchange::Exchanges
module Veridex
module Services
class Pairs < Cryptoexchange::Services::Pairs
PAIRS_URL = "#{Cryptoexchange::Exchanges::Veridex::Market::API_URL}/markets"

def fetch
outputs = []
(0..0).each do |page_id|
pair_url = PAIRS_URL + "?page=#{page_id}&perPage=100"
puts pair_url
output = fetch_via_api(pair_url)
break if output.empty?
outputs = outputs + output['records']
end
adapt(outputs)
end

def adapt(output)
output.map do |ticker|
base, target = ticker['pair'].split('-')
Cryptoexchange::Models::MarketPair.new({
base: base,
target: target,
market: Veridex::Market::NAME
})
end
end
end
end
end
end
37 changes: 37 additions & 0 deletions spec/exchanges/veridex/integration/market_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require 'spec_helper'

RSpec.describe 'Veridex integration specs' do
let(:client) { Cryptoexchange::Client.new }
let(:vsf_weth_pair) { Cryptoexchange::Models::MarketPair.new(base: 'VSF', target: 'WETH', market: 'veridex') }

it 'fetch pairs' do
pairs = client.pairs('veridex')
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 'veridex'
end

it 'give trade url' do
trade_page_url = client.trade_page_url 'veridex', base: vsf_weth_pair.base, target: vsf_weth_pair.target
expect(trade_page_url).to eq "https://dex.verisafe.io/#/erc20/?base=VSF&quote=WETH"
end

it 'fetch ticker' do
ticker = client.ticker(vsf_weth_pair)

expect(ticker.base).to eq 'VSF'
expect(ticker.target).to eq 'WETH'
expect(ticker.market).to eq 'veridex'
expect(ticker.last).to be_a Numeric
expect(ticker.last).to be < 100 # Test if number is reasonable
expect(ticker.bid).to be_a Numeric
expect(ticker.ask).to be_a Numeric
expect(ticker.change).to be_a Numeric
expect(ticker.volume).to be_a Numeric
expect(ticker.timestamp).to be nil
expect(ticker.payload).to_not be nil
end
end
6 changes: 6 additions & 0 deletions spec/exchanges/veridex/market_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'spec_helper'

RSpec.describe Cryptoexchange::Exchanges::Veridex::Market do
it { expect(described_class::NAME).to eq 'veridex' }
it { expect(described_class::API_URL).to eq 'https://dex-backend.verisafe.io/v3' }
end