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 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Pairs, Tickers, OrderBook, Trades, updated README for CoinAsset (…
- Loading branch information
1 parent
aa127a1
commit 1e3cb6b
Showing
12 changed files
with
426 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 Coinasset | ||
class Market < Cryptoexchange::Models::Market | ||
NAME = 'coinasset' | ||
API_URL = 'https://api.coinasset.co.th/api/v1' | ||
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,51 @@ | ||
module Cryptoexchange::Exchanges | ||
module Coinasset | ||
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::Coinasset::Market::API_URL}/tickers" | ||
end | ||
|
||
def adapt_all(output) | ||
output.map do |pair| | ||
base, target = pair[1]['symbol'].split('-') | ||
market_pair = Cryptoexchange::Models::MarketPair.new( | ||
base: base, | ||
target: target, | ||
market: Coinasset::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 = Coinasset::Market::NAME | ||
ticker.last = NumericHelper.to_d(output['lastPrice']) | ||
ticker.high = NumericHelper.to_d(output['high24Hr']) | ||
ticker.low = NumericHelper.to_d(output['low24Hr']) | ||
ticker.bid = NumericHelper.to_d(output['highestBid']) | ||
ticker.ask = NumericHelper.to_d(output['lowestAsk']) | ||
ticker.volume = NumericHelper.to_d(output['volume24Hr']) | ||
ticker.change = NumericHelper.to_d(output['change24Hr']) | ||
ticker.timestamp = nil | ||
ticker.payload = output | ||
ticker | ||
end | ||
end | ||
end | ||
end | ||
end |
42 changes: 42 additions & 0 deletions
42
lib/cryptoexchange/exchanges/coinasset/services/order_book.rb
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,42 @@ | ||
module Cryptoexchange::Exchanges | ||
module Coinasset | ||
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::Coinasset::Market::API_URL}/order-books?symbol=#{market_pair.base}-#{market_pair.target}" | ||
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 = Coinasset::Market::NAME | ||
order_book.asks = adapt_orders(output['asks']) | ||
order_book.bids = adapt_orders(output['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[0], | ||
amount: order_entry[1]) | ||
end | ||
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 Coinasset | ||
module Services | ||
class Pairs < Cryptoexchange::Services::Pairs | ||
PAIRS_URL = "#{Cryptoexchange::Exchanges::Coinasset::Market::API_URL}/tickers" | ||
|
||
def fetch | ||
output = super | ||
market_pairs = [] | ||
output.each do |pair| | ||
base, target = pair[1]['symbol'].split('-') | ||
market_pairs << Cryptoexchange::Models::MarketPair.new( | ||
base: base, | ||
target: target, | ||
market: Coinasset::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,32 @@ | ||
module Cryptoexchange::Exchanges | ||
module Coinasset | ||
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::Coinasset::Market::API_URL}/trades?symbol=#{market_pair.base}-#{market_pair.target}" | ||
end | ||
|
||
def adapt(output, market_pair) | ||
output.collect do |trade| | ||
tr = Cryptoexchange::Models::Trade.new | ||
tr.trade_id = trade['reference_id'] | ||
tr.base = market_pair.base | ||
tr.target = market_pair.target | ||
tr.market = Coinasset::Market::NAME | ||
tr.type = trade['type'] | ||
tr.price = trade['price'] | ||
tr.amount = trade['amount'] | ||
tr.timestamp = trade['time'] | ||
tr.payload = trade | ||
tr | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
49 changes: 49 additions & 0 deletions
49
spec/cassettes/vcr_cassettes/CoinAsset/integration_specs_fetch_order_book.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
49 changes: 49 additions & 0 deletions
49
spec/cassettes/vcr_cassettes/CoinAsset/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.
49 changes: 49 additions & 0 deletions
49
spec/cassettes/vcr_cassettes/CoinAsset/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.
Oops, something went wrong.