Skip to content

Commit

Permalink
Merge pull request coingecko#2119 from ElvisLYC/implement_cryptlocex
Browse files Browse the repository at this point in the history
Implement cryptlocex
  • Loading branch information
ElvisLYC authored Jun 9, 2020
2 parents 6e39821 + 2a72c69 commit 8324368
Show file tree
Hide file tree
Showing 9 changed files with 388 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ Or install it yourself as:
| CRXZone | Y | Y [x] | Y | | Y | Y | crxzone | |
| Cryptagio | Y | Y | Y | | Y | Y | cryptagio | |
| Cryptaldash | Y | Y | Y | | Y | | cryptaldash | |
| Cryptlocex | Y | Y [x] | N | | Y | Y | cryptlocex | |
| Cryptex | Y | Y | Y | | User-Defined| Y | cryptex | |
| CryptoBridge | Y | | | | Y | Y | crypto_bridge | |
| CryptoHub | Y | N | N | | Y | | crypto_hub | |
Expand Down
12 changes: 12 additions & 0 deletions lib/cryptoexchange/exchanges/cryptlocex/market.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Cryptoexchange::Exchanges
module Cryptlocex
class Market < Cryptoexchange::Models::Market
NAME = 'cryptlocex'
API_URL = 'https://trade.cryptlocex.com/Api'

def self.trade_page_url(args={})
"https://trade.cryptlocex.com/trade/index/market/#{args[:base].downcase}_#{args[:target].downcase}/"
end
end
end
end
51 changes: 51 additions & 0 deletions lib/cryptoexchange/exchanges/cryptlocex/services/market.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
module Cryptoexchange::Exchanges
module Cryptlocex
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['data']['market'])
end

def ticker_url
"#{Cryptoexchange::Exchanges::Cryptlocex::Market::API_URL}/Index/marketInfo"
end

def adapt_all(output)
output.map do |output|
base, target = output["ticker"].split('_')
market_pair = Cryptoexchange::Models::MarketPair.new(
base: base,
target: target,
market: Cryptlocex::Market::NAME
)

adapt(output, market_pair)
end
end

def adapt(output, market_pair)
ticker = Cryptoexchange::Models::Ticker.new
ticker.base = market_pair.base
ticker.target = market_pair.target
ticker.market = Cryptlocex::Market::NAME
ticker.bid = NumericHelper.to_d(output['buy_price'])
ticker.ask = NumericHelper.to_d(output['sell_price'])
ticker.last = NumericHelper.to_d(output['new_price'])
ticker.volume = NumericHelper.to_d(output['volume'])
ticker.high = NumericHelper.to_d(output['max_price'])
ticker.low = NumericHelper.to_d(output['min_price'])
ticker.timestamp = nil
ticker.payload = output
ticker
end
end
end
end
end
46 changes: 46 additions & 0 deletions lib/cryptoexchange/exchanges/cryptlocex/services/order_book.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module Cryptoexchange::Exchanges
module Cryptlocex
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)
base = market_pair.base.downcase
target = market_pair.target.downcase
"#{Cryptoexchange::Exchanges::Cryptlocex::Market::API_URL}/Exchange/activeorders/market/#{base}_#{target}"
end

def adapt(output, market_pair)
output = output['data']['depth']
order_book = Cryptoexchange::Models::OrderBook.new

order_book.base = market_pair.base
order_book.target = market_pair.target
order_book.market = Cryptlocex::Market::NAME
order_book.asks = adapt_orders output['sell']
order_book.bids = adapt_orders output['buy']
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['price'],
amount: order_entry['nums']
)
end
end
end
end
end
end
25 changes: 25 additions & 0 deletions lib/cryptoexchange/exchanges/cryptlocex/services/pairs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module Cryptoexchange::Exchanges
module Cryptlocex
module Services
class Pairs < Cryptoexchange::Services::Pairs
PAIRS_URL = "#{Cryptoexchange::Exchanges::Cryptlocex::Market::API_URL}/Index/marketInfo"

def fetch
output = super
adapt(output['data']['market'])
end

def adapt(output)
output.map do |output|
base, target = output["ticker"].split('_')
Cryptoexchange::Models::MarketPair.new(
base: base,
target: target,
market: Cryptlocex::Market::NAME
)
end
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 8324368

Please sign in to comment.