Skip to content
This repository has been archived by the owner on Jun 22, 2020. It is now read-only.

365.stream Integration #1307

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Or install it yourself as:

| Exchange | Ticker | Order Book | Trade | Account | Market List | Pair URL | slug |
| ----------------- | ------- | ---------- | ------- | ------- | ----------- |----------|-------------------|
| 365stream | Y | Y | Y | | Y | Y | stream365 |
| 58Coin | Y | Y | Y | | Y | Y | fifty_eight_coin |
| Abcc | Y | N | N | | Y | Y | abcc |
| Abucoins | Y | Y | Y | | Y | | abucoins |
Expand Down
12 changes: 12 additions & 0 deletions lib/cryptoexchange/exchanges/stream365/market.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Cryptoexchange::Exchanges
module Stream365
class Market < Cryptoexchange::Models::Market
NAME = 'stream365'
API_URL = 'https://api.365.stream'

def self.trade_page_url(args={})
"https://365.stream/exchange/#{args[:target]}_#{args[:base]}"
end
end
end
end
48 changes: 48 additions & 0 deletions lib/cryptoexchange/exchanges/stream365/services/market.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module Cryptoexchange::Exchanges
module Stream365
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::Stream365::Market::API_URL}/market/all"
end

def adapt_all(output)
output.map do |pair|
market_pair = Cryptoexchange::Models::MarketPair.new(
base: pair[1]['ticker'],
target: pair[1]['market'],
market: Stream365::Market::NAME
)
adapt(market_pair, pair[1]['detail'])
end
end

def adapt(market_pair, output)
ticker = Cryptoexchange::Models::Ticker.new
ticker.base = market_pair.base
ticker.target = market_pair.target
ticker.market = Stream365::Market::NAME
ticker.last = NumericHelper.to_d(output['close'])
ticker.high = NumericHelper.to_d(output['high'])
ticker.low = NumericHelper.to_d(output['low'])
ticker.volume = NumericHelper.to_d(output['volume'])
ticker.change = NumericHelper.to_d(output['percent'])
ticker.timestamp = nil
ticker.payload = output
ticker
end
end
end
end
end
42 changes: 42 additions & 0 deletions lib/cryptoexchange/exchanges/stream365/services/order_book.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module Cryptoexchange::Exchanges
module Stream365
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::Stream365::Market::API_URL}/api/orderbook/?pairing=#{market_pair.inst_id}"
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 = Stream365::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
23 changes: 23 additions & 0 deletions lib/cryptoexchange/exchanges/stream365/services/pairs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Cryptoexchange::Exchanges
module Stream365
module Services
class Pairs < Cryptoexchange::Services::Pairs
PAIRS_URL = "#{Cryptoexchange::Exchanges::Stream365::Market::API_URL}/api/pairing/"

def fetch
output = super
market_pairs = []
output.each do |pair|
market_pairs << Cryptoexchange::Models::MarketPair.new(
base: pair[1]['ticker'],
target: pair[1]['market'],
inst_id: pair[1]['pairing_id'],
market: Stream365::Market::NAME
)
end
market_pairs
end
end
end
end
end
32 changes: 32 additions & 0 deletions lib/cryptoexchange/exchanges/stream365/services/trades.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Cryptoexchange::Exchanges
module Stream365
module Services
class Trades < Cryptoexchange::Services::Market
def fetch(market_pair)
output = super(ticker_url(market_pair))
adapt(output['trades'], market_pair)
end

def ticker_url(market_pair)
"#{Cryptoexchange::Exchanges::Stream365::Market::API_URL}/api/trade/?pairing=#{market_pair.inst_id}"
end

def adapt(output, market_pair)
output.collect do |trade|
tr = Cryptoexchange::Models::Trade.new
tr.trade_id = trade['trade_id']
tr.base = market_pair.base
tr.target = market_pair.target
tr.market = Stream365::Market::NAME
tr.type = trade['trade_type']
tr.price = trade['rate']
tr.amount = trade['amount']
tr.timestamp = DateTime.parse(trade['trade_date']).to_time.to_i
tr.payload = trade
tr
end
end
end
end
end
end

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

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

Loading