Permalink
Browse files

Merge branch 'master' into github-master

Conflicts:
	rebar.config
  • Loading branch information...
2 parents afc2211 + 839a1b7 commit 85dc9cffae8b1d0d397a9518c56d30d2c7f7c597 Steven Gravell committed Feb 14, 2012
Showing with 92 additions and 6 deletions.
  1. +1 −1 README.md
  2. +7 −0 include/smk_tests.hrl
  3. +19 −0 priv/ca-api.smarkets.com.crt
  4. +1 −1 rebar.config
  5. +1 −1 src/smk.app.src
  6. +11 −2 src/smk_client.erl
  7. +8 −1 src/smk_my_callbacks.erl
  8. +44 −0 test/smk_client_tests.erl
View
@@ -41,7 +41,7 @@ An example client is available in src/smk\_example\_client.erl - to start it up
undefined} ... }
2> rr(seto_piqi).
[...]
- 3> smk_client:order(smk_my_callbacks, 400000, 25, buy, #seto_uuid_128{low=122001}, #seto_uuid_128{low=175002}).
+ 3> smk_client:order(smk_my_callbacks, 400000, 2500, buy, #seto_uuid_128{low=122001}, #seto_uuid_128{low=175002}).
{ok, 2}
Received {seto_payload,order_accepted,
{eto_payload,2,undefined,false,undefined,undefined,
View
@@ -82,6 +82,13 @@ all([H|T], F, Recv, Acc) ->
-define(assertLogoutConfirmation(Seq),
?assertLogout(Seq, confirmation)).
+-define(assertAccountState(Seq, State),
+ ?assertRecv(#seto_payload{
+ eto_payload=#eto_payload{seq=Seq},
+ type=account_state,
+ account_state=State
+ })).
+
-define(assertLogout(Seq, Reason),
?assertRecv(#seto_payload{
eto_payload=#eto_payload{
@@ -0,0 +1,19 @@
+-----BEGIN CERTIFICATE-----
+MIIDIDCCAomgAwIBAgIENd70zzANBgkqhkiG9w0BAQUFADBOMQswCQYDVQQGEwJV
+UzEQMA4GA1UEChMHRXF1aWZheDEtMCsGA1UECxMkRXF1aWZheCBTZWN1cmUgQ2Vy
+dGlmaWNhdGUgQXV0aG9yaXR5MB4XDTk4MDgyMjE2NDE1MVoXDTE4MDgyMjE2NDE1
+MVowTjELMAkGA1UEBhMCVVMxEDAOBgNVBAoTB0VxdWlmYXgxLTArBgNVBAsTJEVx
+dWlmYXggU2VjdXJlIENlcnRpZmljYXRlIEF1dGhvcml0eTCBnzANBgkqhkiG9w0B
+AQEFAAOBjQAwgYkCgYEAwV2xWGcIYu6gmi0fCG2RFGiYCh7+2gRvE4RiIcPRfM6f
+BeC4AfBONOziipUEZKzxa1NfBbPLZ4C/QgKO/t0BCezhABRP/PvwDN1Dulsr4R+A
+cJkVV5MW8Q+XarfCaCMczE1ZMKxRHjuvK9buY0V7xdlfUNLjUA86iOe/FP3gx7kC
+AwEAAaOCAQkwggEFMHAGA1UdHwRpMGcwZaBjoGGkXzBdMQswCQYDVQQGEwJVUzEQ
+MA4GA1UEChMHRXF1aWZheDEtMCsGA1UECxMkRXF1aWZheCBTZWN1cmUgQ2VydGlm
+aWNhdGUgQXV0aG9yaXR5MQ0wCwYDVQQDEwRDUkwxMBoGA1UdEAQTMBGBDzIwMTgw
+ODIyMTY0MTUxWjALBgNVHQ8EBAMCAQYwHwYDVR0jBBgwFoAUSOZo+SvSspXXR9gj
+IBBPM5iQn9QwHQYDVR0OBBYEFEjmaPkr0rKV10fYIyAQTzOYkJ/UMAwGA1UdEwQF
+MAMBAf8wGgYJKoZIhvZ9B0EABA0wCxsFVjMuMGMDAgbAMA0GCSqGSIb3DQEBBQUA
+A4GBAFjOKer89961zgK5F7WF0bnj4JXMJTENAKaSbn+2kmOeUJXRmm/kEd5jhW6Y
+7qj/WsjTVbJmcVfewCHrPSqnI0kBBIZCe/zuf6IWUrVnZ9NA2zsmWLIodz2uFHdh
+1voqZiegDfqnc1zqcPGUIWVEX/r87yloqaKHee9570+sB3c4
+-----END CERTIFICATE-----
View
@@ -3,7 +3,7 @@
{erl_opts, [debug_info, fail_on_warnings]}.
{deps, [
{lager, ".*", {git, "https://github.com/basho/lager.git", {branch, "master"}}},
- {smk_api_common, ".*", {git, "git://github.com/smarkets/smk_api_common.git", {tag, "v0.4.0"}}},
+ {smk_api_common, ".*", {git, "git://github.com/smarkets/smk_api_common.git", {tag, "v0.4.1"}}},
{piqi, "0.5.6", {git, "git://github.com/smarkets/piqi.git", {tag, "0.5.6-smarkets"}}},
{ossp_uuid, ".*", {git, "https://github.com/yrashk/erlang-ossp-uuid.git", {branch, "master"}}},
{proper, ".*", {git, "https://github.com/manopapad/proper.git", {branch, "master"}}}
View
@@ -1,6 +1,6 @@
{application, smk, [
{description, "Smarkets API Software Development Kit for Erlang"},
- {vsn, "0.3.1"},
+ {vsn, "0.3.2"},
{registered, []},
{mod, { smk_app, [] }},
{applications, [
View
@@ -290,7 +290,16 @@ handle_info({connect, Opts}, StateName, #s{session=Session, cache=Cache, name=Na
end,
Cache:connecting(Name),
lager:log(info, self(), "Connecting ~p ~p ssl:~p", [Host, Port, Ssl]),
- case smk_sock:connect(Ssl, Host, Port, ?SOCK_OPTS, []) of
+ SslOpts =
+ case Host of
+ "api.smarkets.com" ->
+ [
+ {verify, verify_peer},
+ {cacertfile, "ca-api.smarkets.com.crt"}
+ ];
+ _ -> []
+ end,
+ case smk_sock:connect(Ssl, Host, Port, ?SOCK_OPTS, SslOpts) of
{ok, Sock} ->
lager:log(info, self(), "Connected ~p", [Sock]),
{ok, _, NewState} = send_call(Login, State#s{sock=Sock}),
@@ -392,7 +401,7 @@ logging_out(_Message, _From, State0) ->
%% async
awaiting_session(stop, State) ->
- {next_state, awaiting_session, State}.
+ {stop, normal, State}.
logged_in(drop_in, #s{drop_in=Drop} = State) ->
{next_state, logged_in, State#s{drop_in=Drop+1}};
View
@@ -1,6 +1,6 @@
-module(smk_my_callbacks).
--export([start/2, cb/2]).
+-export([start/2, start_unnamed/2, cb/2]).
start(Username, Password) ->
smk_clients_sup:start_client({local, ?MODULE}, [
@@ -9,6 +9,13 @@ start(Username, Password) ->
{callback, fun ?MODULE:cb/2}
]).
+start_unnamed(Username, Password) ->
+ smk_clients_sup:start_client([
+ {username,Username},
+ {password,Password},
+ {callback, fun ?MODULE:cb/2}
+ ]).
+
cb(_Payload, _Session) ->
%io:format("Payload Received for session ~p : ~p~n", [Session, Payload]),
ok.
View
@@ -29,6 +29,37 @@ login_test_() -> ?setup(
end}
).
+account_state_exposure_test() ->
+ {ok, C} = login(),
+ ?assertLoginResponse(1),
+
+ {ok, 2} = smk_client:account_state(C),
+ ?assertAccountState(2, #seto_account_state{
+ exposure = #seto_decimal{value=0, exponent=2}
+ }),
+
+ Qty = 100000,
+ Px = 2500,
+ Side = buy,
+ {ok, 3} = smk_client:order(C, Qty, Px, Side, ?MARKET_ID, ?CONTRACT_ID),
+ ?assertOrderAccepted(3, Order, 3),
+
+ {ok, 4} = smk_client:account_state(C),
+ ?assertAccountState(4, #seto_account_state{
+ exposure = #seto_decimal{value=-250, exponent=2}
+ }),
+
+ {ok, 5} = smk_client:order_cancel(C, Order),
+ ?assertOrderCancelled(5, Order, member_requested),
+
+ {ok, 6} = smk_client:account_state(C),
+ ?assertAccountState(6, #seto_account_state{
+ exposure = #seto_decimal{value=0, exponent=2}
+ }),
+
+ {ok, 7} = smk_client:logout(C),
+ ?assertLogoutConfirmation(7).
+
unauthorised_test() ->
UserCreds = [
{username, <<"not a valid username">>},
@@ -130,6 +161,19 @@ order_rejected_market_not_found_test_() ->
?assertLogoutConfirmation(3)
end}.
+order_rejected_contract_not_found_test() ->
+ {ok, C} = login(),
+ ?assertLoginResponse(1),
+ Qty = 100000,
+ Px = 2500,
+ Side = buy,
+ {ok, 2} = smk_client:order(C, Qty, Px, Side, ?MARKET_ID, #seto_uuid_128{low=0}),
+ ?assertOrderRejected(2, contract_not_found, 2),
+ {ok, 3} = smk_client:logout(C),
+ ?assertLogoutConfirmation(3).
+
+
+
many_order_create_test() ->
{ok, C} = login(),
?assertLoginResponse(1),

0 comments on commit 85dc9cf

Please sign in to comment.