forked from coingecko/cryptoexchange
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Coinzest Integration (coingecko#1100)
* Added Pairs, Tickers, OrderBook and updated README for Coinzest * Fixed inverted base/target and added trade URL
- Loading branch information
1 parent
90b0d27
commit 7157e33
Showing
10 changed files
with
2,317 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,12 @@ | ||
module Cryptoexchange::Exchanges | ||
module Coinzest | ||
class Market < Cryptoexchange::Models::Market | ||
NAME = 'coinzest' | ||
API_URL = 'https://api.coinzest.co.kr/api/public' | ||
|
||
def self.trade_page_url(args={}) | ||
"https://www.coinzest.co.kr/app/cxweb/it/IT4001.jsp" | ||
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,52 @@ | ||
module Cryptoexchange::Exchanges | ||
module Coinzest | ||
module Services | ||
class Market < Cryptoexchange::Services::Market | ||
class << self | ||
def supports_individual_ticker_query? | ||
false | ||
end | ||
end | ||
def fetch | ||
ctx = OpenSSL::SSL::SSLContext.new | ||
ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE | ||
result = HTTP.get(ticker_url, ssl_context: ctx) | ||
output = JSON.parse(result) | ||
adapt_all(output) | ||
end | ||
|
||
def ticker_url | ||
"#{Cryptoexchange::Exchanges::Coinzest::Market::API_URL}/market_summary" | ||
end | ||
|
||
def adapt_all(output) | ||
output['result'].map do |pair| | ||
target, base = pair['MarketName'].split('-') | ||
market_pair = Cryptoexchange::Models::MarketPair.new( | ||
base: base, | ||
target: target, | ||
market: Coinzest::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 = Coinzest::Market::NAME | ||
ticker.last = NumericHelper.to_d(output['Last']) | ||
ticker.bid = NumericHelper.to_d(output['Bid']) | ||
ticker.ask = NumericHelper.to_d(output['Ask']) | ||
ticker.high = NumericHelper.to_d(output['High']) | ||
ticker.low = NumericHelper.to_d(output['Low']) | ||
ticker.volume = NumericHelper.to_d(output['BaseVolume']/output['Last']) | ||
ticker.timestamp = output['TimeStamp']/1000 | ||
ticker.payload = output | ||
ticker | ||
end | ||
end | ||
end | ||
end | ||
end |
45 changes: 45 additions & 0 deletions
45
lib/cryptoexchange/exchanges/coinzest/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,45 @@ | ||
module Cryptoexchange::Exchanges | ||
module Coinzest | ||
module Services | ||
class OrderBook < Cryptoexchange::Services::Market | ||
class << self | ||
def supports_individual_ticker_query? | ||
true | ||
end | ||
end | ||
def fetch(market_pair) | ||
ctx = OpenSSL::SSL::SSLContext.new | ||
ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE | ||
result = HTTP.get(ticker_url(market_pair), ssl_context: ctx) | ||
output = JSON.parse(result) | ||
adapt(output, market_pair) | ||
end | ||
|
||
def ticker_url(market_pair) | ||
"#{Cryptoexchange::Exchanges::Coinzest::Market::API_URL}/bid_price/#{market_pair.target}-#{market_pair.base}" | ||
end | ||
|
||
def adapt(output, market_pair) | ||
order_book = Cryptoexchange::Models::OrderBook.new | ||
timestamp = Time.now.to_i | ||
order_book.base = market_pair.base | ||
order_book.target = market_pair.target | ||
order_book.market = Coinzest::Market::NAME | ||
order_book.asks = adapt_orders(output['bid_price']['askList']) | ||
order_book.bids = adapt_orders(output['bid_price']['bidList']) | ||
order_book.timestamp = timestamp | ||
order_book.payload = output | ||
order_book | ||
end | ||
|
||
def adapt_orders(orders) | ||
orders.collect do |order_entry| | ||
Cryptoexchange::Models::Order.new(price: order_entry['price'], | ||
amount: order_entry['quantity'], | ||
timestamp: nil) | ||
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,26 @@ | ||
module Cryptoexchange::Exchanges | ||
module Coinzest | ||
module Services | ||
class Pairs < Cryptoexchange::Services::Pairs | ||
PAIRS_URL = "#{Cryptoexchange::Exchanges::Coinzest::Market::API_URL}/market" | ||
|
||
def fetch | ||
ctx = OpenSSL::SSL::SSLContext.new | ||
ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE | ||
result = HTTP.get(PAIRS_URL, ssl_context: ctx) | ||
output = JSON.parse(result) | ||
market_pairs = [] | ||
output['list'].each do |pair| | ||
market_pairs << Cryptoexchange::Models::MarketPair.new( | ||
base: pair['trdCoinName'], | ||
target: pair['mrkCoinName'], | ||
inst_id: "#{pair['mrkCoin']}-#{pair['trdCoin']}", | ||
market: Coinzest::Market::NAME | ||
) | ||
end | ||
market_pairs | ||
end | ||
end | ||
end | ||
end | ||
end |
136 changes: 136 additions & 0 deletions
136
spec/cassettes/vcr_cassettes/Coinzest/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.
Oops, something went wrong.