0
私は証券取引所から(ウェブソケット経由で)受け取ったデータをストリーミングし、そのデータをクライアントにブロードキャストしたいと考えています。私はアクションケーブルが最善のアプローチだと信じていますが、それまでのところ成功していません。アクションケーブル(レール5)証券取引所からデータを引き出す
"DataProvider"は、私のサーバーと証券取引所との間の接続を作成するためにRuby上にSDKを構築しました。私は正常に接続することができましたが、データストリームを見たことがありません。
何か提案がありますか?
チャンネル:(componentDidMount中())
class StockPriceChannel < ApplicationCable::Channel
def subscribed
stream_from "portfolio_#{params[:portfolio_id]}"
end
def unsubscribed
# Any cleanup needed when channel is unsubscribed
EventMachine.stop()
end
def receive(data)
tickers = data["message"]
tickers = tickers.split(",")
puts tickers
options = {
username: ENV["DataProvider_USERNAME"],
password: ENV["DataProvider_PASSWORD"],
channels: tickers
}
EventMachine.run do
client = DataProvider::Realtime::Client.new(options)
client.on_quote do |quote|
StockPriceChannel.server.broadcast_to("portfolio_#
{params[:portfolio_id]}",quote)
end
client.connect()
EventMachine.add_timer(1) do
puts "joining tickers"
client.join(tickers)
end
# EventMachine.add_timer(10) do
# client.disconnect()
# EventMachine.stop()
# end
end
end
end
ReactJS
App.portfolioChannel = App.cable.subscriptions.create(
{
channel:"StockPriceChannel",
portfolio_id:this.props.match.params.port_id
},
{
connected:() => console.log("StockPriceChannel connected"),
disconnected:() => console.log("StockPriceChannel disconnected"),
received: data => {
debugger;
console.log(data)
}
}
)
App.portfolioChannel.send({
message:"AAPL,MSFT"
})