Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

almost there

  • Loading branch information...
commit 3f35292181232eab385dfb5312827fab1549d088 1 parent b90e64e
@nisbus authored
Showing with 9 additions and 7 deletions.
  1. +9 −7 src/monterl_carlo_websocket_handler.erl
View
16 src/monterl_carlo_websocket_handler.erl
@@ -17,9 +17,8 @@
}).
% Called to know how to dispatch a new connection.
-init(_Any, _Req, _Opts) ->
-
- {upgrade, protocol, cowboy_http_websocket}.
+init(_Any, _Req, _Opts) ->
+ {upgrade, protocol, cowboy_websocket}.
% Should never get here.
handle(_Req, State) ->
@@ -66,19 +65,22 @@ handle_message(Msg,Req,#state{callback = Callback} = State) ->
<<"graph">> ->
Symbol = proplists:get_value(<<"symbol">>,Props),
Points = proplists:get_value(<<"points">>,Props,50),
- Type = proplists:get_value("type",Props,bid),
- Resp = monterl_carlo:graph(Symbol,Points,Type),
+ GraphType = proplists:get_value("graph_type",Props,bid),
+ Resp = monterl_carlo:graph(Symbol,Points,GraphType),
{reply,{text,jsx:term_to_json(Resp),Req,State}};
<<"subscribe">> ->
Symbol = proplists:get_value(<<"symbol">>,Props),
+ monterl_carlo:start(Symbol,Callback),
+ {ok, Req, State};
+ <<"start">> ->
+ Symbol = proplists:get_value(<<"symbol">>,Props),
Px = proplists:get_value(<<"price">>,Props),
Precision = proplists:get_value(<<"precision">>,Props),
Annual_Vol = proplists:get_value(<<"annual_volatility">>,Props),
AnnualExpRet = proplists:get_value(<<"annual_expected_returns">>,Props),
Interval = proplists:get_value(<<"interval">>,Props),
{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}
end.
Please sign in to comment.
Something went wrong with that request. Please try again.