This repository has been archived by the owner on Jun 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #164 from weh/feature/litebiteu
Implement LiteBit.eu Ticker
- Loading branch information
Showing
8 changed files
with
248 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
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,8 @@ | ||
module Cryptoexchange::Exchanges | ||
module Litebiteu | ||
class Market | ||
NAME = 'litebiteu' | ||
API_URL = 'https://api.litebit.eu' | ||
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,50 @@ | ||
module Cryptoexchange::Exchanges | ||
module Litebiteu | ||
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::Litebiteu::Market::API_URL}/markets" | ||
end | ||
|
||
def adapt_all(output) | ||
fetch_timestamp = DateTime.now.to_time.to_i | ||
|
||
output['result'].map do |base, market| | ||
market_pair = Cryptoexchange::Models::MarketPair.new( | ||
base: base.upcase, | ||
target: 'EUR', | ||
market: Bithumb::Market::NAME | ||
) | ||
adapt(market, market_pair, fetch_timestamp) | ||
end | ||
end | ||
|
||
def adapt(market, market_pair, fetch_timestamp) | ||
ticker = Cryptoexchange::Models::Ticker.new | ||
|
||
ticker.base = market_pair.base | ||
ticker.target = market_pair.target | ||
ticker.market = Litebiteu::Market::NAME | ||
ticker.ask = NumericHelper.to_d(market['buy']) | ||
ticker.bid = NumericHelper.to_d(market['sell']) | ||
ticker.volume = NumericHelper.to_d(market['volume']) | ||
ticker.last = (ticker.ask + ticker.bid) / 2 | ||
ticker.timestamp = fetch_timestamp | ||
ticker.payload = market | ||
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,31 @@ | ||
module Cryptoexchange::Exchanges | ||
module Litebiteu | ||
module Services | ||
class Pairs < Cryptoexchange::Services::Pairs | ||
PAIRS_URL = "#{Cryptoexchange::Exchanges::Litebiteu::Market::API_URL}/markets" | ||
|
||
def fetch | ||
output = super | ||
adapt(output) | ||
end | ||
|
||
def adapt(output) | ||
market_pairs = [] | ||
|
||
output['result'].each do |currency, _| | ||
|
||
if currency | ||
market_pairs << Cryptoexchange::Models::MarketPair.new( | ||
base: currency.upcase, | ||
target: 'EUR', | ||
market: Litebiteu::Market::NAME | ||
) | ||
end | ||
end | ||
|
||
market_pairs | ||
end | ||
end | ||
end | ||
end | ||
end |
60 changes: 60 additions & 0 deletions
60
spec/cassettes/vcr_cassettes/Litebiteu/integration_specs_fetch_pairs.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
spec/cassettes/vcr_cassettes/Litebiteu/integration_specs_fetch_ticker.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,32 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe 'Litebiteu integration specs' do | ||
client = Cryptoexchange::Client.new | ||
|
||
it 'fetch pairs' do | ||
pairs = client.pairs('litebiteu') | ||
expect(pairs).not_to be_empty | ||
|
||
pair = pairs.first | ||
expect(pair.base).to eq 'BTC' | ||
expect(pair.target).to eq 'EUR' | ||
expect(pair.market).to eq 'litebiteu' | ||
end | ||
|
||
it 'fetch ticker' do | ||
btc_eur_pair = Cryptoexchange::Models::MarketPair.new(base: 'BTC', target: 'EUR', market: 'litebiteu') | ||
ticker = client.ticker(btc_eur_pair) | ||
|
||
expect(ticker.base).to eq 'BTC' | ||
expect(ticker.target).to eq 'EUR' | ||
expect(ticker.market).to eq 'litebiteu' | ||
|
||
expect(ticker.bid).to be_a Numeric | ||
expect(ticker.ask).to be_a Numeric | ||
expect(ticker.volume).to be_a Numeric | ||
expect(ticker.last).to be_a Numeric | ||
expect(ticker.timestamp).to be_a Numeric | ||
expect(DateTime.strptime(ticker.timestamp.to_s, '%s').year).to eq Date.today.year | ||
expect(ticker.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::Litebiteu::Market do | ||
it { expect(described_class::NAME).to eq 'litebiteu' } | ||
it { expect(described_class::API_URL).to eq 'https://api.litebit.eu' } | ||
end |