Skip to content

Commit

Permalink
Coinzest Integration (coingecko#1100)
Browse files Browse the repository at this point in the history
* Added Pairs, Tickers, OrderBook and updated README for Coinzest

* Fixed inverted base/target and added trade URL
  • Loading branch information
estherleongym authored and wongy91 committed Oct 30, 2018
1 parent 90b0d27 commit 7157e33
Show file tree
Hide file tree
Showing 10 changed files with 2,317 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ Or install it yourself as:
| Coinsuper | Y | | | | Y | Y | coinsuper |
| Cointiger | Y | Y | Y | | Y | | cointiger |
| Coinut (Auth) | Y | Y | Y | Y | Y | | coinut |
| Coinzest | Y | Y | | | Y | | coinzest |
| COSS | Y | | | | Y | Y | coss |
| Cpdax | Y | Y | Y | | Y | | cpdax |
| CredoEx | Y | | | | Y | | credoex |
Expand Down
12 changes: 12 additions & 0 deletions lib/cryptoexchange/exchanges/coinzest/market.rb
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
52 changes: 52 additions & 0 deletions lib/cryptoexchange/exchanges/coinzest/services/market.rb
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 lib/cryptoexchange/exchanges/coinzest/services/order_book.rb
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
26 changes: 26 additions & 0 deletions lib/cryptoexchange/exchanges/coinzest/services/pairs.rb
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7157e33

Please sign in to comment.