Skip to content

Commit

Permalink
almost there
Browse files Browse the repository at this point in the history
  • Loading branch information
nisbus committed Nov 1, 2012
1 parent b90e64e commit 3f35292
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/monterl_carlo_websocket_handler.erl
Expand Up @@ -17,9 +17,8 @@
}). }).


% Called to know how to dispatch a new connection. % Called to know how to dispatch a new connection.
init(_Any, _Req, _Opts) -> init(_Any, _Req, _Opts) ->

{upgrade, protocol, cowboy_websocket}.
{upgrade, protocol, cowboy_http_websocket}.


% Should never get here. % Should never get here.
handle(_Req, State) -> handle(_Req, State) ->
Expand Down Expand Up @@ -66,19 +65,22 @@ handle_message(Msg,Req,#state{callback = Callback} = State) ->
<<"graph">> -> <<"graph">> ->
Symbol = proplists:get_value(<<"symbol">>,Props), Symbol = proplists:get_value(<<"symbol">>,Props),
Points = proplists:get_value(<<"points">>,Props,50), Points = proplists:get_value(<<"points">>,Props,50),
Type = proplists:get_value("type",Props,bid), GraphType = proplists:get_value("graph_type",Props,bid),
Resp = monterl_carlo:graph(Symbol,Points,Type), Resp = monterl_carlo:graph(Symbol,Points,GraphType),
{reply,{text,jsx:term_to_json(Resp),Req,State}}; {reply,{text,jsx:term_to_json(Resp),Req,State}};
<<"subscribe">> -> <<"subscribe">> ->
Symbol = proplists:get_value(<<"symbol">>,Props),
monterl_carlo:start(Symbol,Callback),
{ok, Req, State};
<<"start">> ->
Symbol = proplists:get_value(<<"symbol">>,Props), Symbol = proplists:get_value(<<"symbol">>,Props),
Px = proplists:get_value(<<"price">>,Props), Px = proplists:get_value(<<"price">>,Props),
Precision = proplists:get_value(<<"precision">>,Props), Precision = proplists:get_value(<<"precision">>,Props),
Annual_Vol = proplists:get_value(<<"annual_volatility">>,Props), Annual_Vol = proplists:get_value(<<"annual_volatility">>,Props),
AnnualExpRet = proplists:get_value(<<"annual_expected_returns">>,Props), AnnualExpRet = proplists:get_value(<<"annual_expected_returns">>,Props),
Interval = proplists:get_value(<<"interval">>,Props), Interval = proplists:get_value(<<"interval">>,Props),
{ok, Pid} = monterl_carlo:start_link(Symbol,Px,Precision,Annual_Vol,AnnualExpRet,Interval), {ok, Pid} = monterl_carlo:start_link(Symbol,Px,Precision,Annual_Vol,AnnualExpRet,Interval),
monterl_carlo:start(Symbol,Callback), {ok, Req, State#state{sim_pid=Pid}};
{ok, Req, State#state{sim_pid = Pid}};
_ -> _ ->
{ok, Req, State} {ok, Req, State}
end. end.

0 comments on commit 3f35292

Please sign in to comment.