1. Oliver Gu
  2. ibx

Commits

Oliver Gu  committed b009cc4

Added Account_and_portfolio_updates query

  • Participants
  • Parent commits 90064eb
  • Branches master

Comments (0)

Files changed (4)

File lib/query.ml

View file
 
 module Submit_order = Submit_order
 
+(* +-----------------------------------------------------------------------+
+   | Account and portfolio                                                 |
+   +-----------------------------------------------------------------------+ *)
+
+module Account_and_portfolio_updates = struct
+  type t =
+    { subscribe : bool;
+      account_code : Account_code.t;
+    } with sexp, fields
+
+  let create = Fields.create
+
+  let ( = ) t1 t2 =
+    let use op = fun field ->
+      op (Field.get field t1) (Field.get field t2)
+    in
+    Fields.for_all
+      ~subscribe:(use (=))
+      ~account_code:(use Account_code.(=))
+
+  let pickler =
+    Pickler.create ~name:"Account_and_portfolio_updates"
+      Pickler.Spec.(
+        wrap (
+          Fields.fold
+            ~init:(empty ())
+            ~subscribe:(fields_value (required bool))
+            ~account_code:(fields_value (required Account_code.val_type)))
+      (fun t -> `Args $ t.subscribe $ t.account_code))
+
+  let unpickler = Only_in_test.of_thunk (fun () ->
+    Unpickler.create ~name:"Account_and_portfolio_updates"
+      Unpickler.Spec.(
+        Fields.fold
+          ~init:(empty ())
+          ~subscribe:(fields_value (required bool))
+          ~account_code:(fields_value (required Account_code.val_type)))
+      (fun subscribe account_code -> { subscribe; account_code }))
+end
 
 (* +-----------------------------------------------------------------------+
    | Executions                                                            |

File lib/query.mli

View file
     -> t
 end
 
+(** {1 Account and portfolio} *)
+(*****************************************************************************)
+
+module Account_and_portfolio_updates : sig
+  type t with sexp
+  include Query_intf.S with type t := t
+  val create :
+    subscribe:bool
+    -> account_code:Account_code.t
+    -> t
+end
+
+(** {1 Executions} *)
+(*****************************************************************************)
+
 module Execution_reports : sig
   type t with sexp
   include Query_intf.S with type t := t

File lib_test/pickle_test.ml

View file
       let module Q = Query.Submit_order in
       gen_test (module Q : Query_intf.S with type t = Q.t) Rg.Q.submit_order_g);
 
+    (* ====================== Account and portfolio ======================== *)
+
+    (fun () ->
+      let module Q = Query.Account_and_portfolio_updates in
+      gen_test (module Q : Query_intf.S with type t = Q.t)
+        Rg.Q.account_and_portfolio_updates);
+
     (* ======================== Execution reports ========================== *)
 
     (fun () ->

File lib_test/rg.ml

View file
 
 module Q : sig
 
-  (* Connection and Server *)
+  (* Connection and server *)
 
   val server_log_level_g : Query.Server_log_level.t gen
   val server_time_g : Query.Server_time.t gen
 
   val submit_order_g : Query.Submit_order.t gen
 
-  (* Account and Portfolio *)
+  (* Account and portfolio *)
+
+  val account_and_portfolio_updates : Query.Account_and_portfolio_updates.t gen
 
   (* Executions *)
 
       ~order:(order_g ())
       ~account_code:(account_code_g ())
 
+  (* =================== Account and portfolio updates ===================== *)
+
+  let account_and_portfolio_updates () =
+    Query.Account_and_portfolio_updates.create
+      ~subscribe:(bg ())
+      ~account_code:(account_code_g ())
+
+  (* ========================= Execution reports =========================== *)
+
   let execution_reports_g () =
     Query.Execution_reports.create
       ~contract:(contract_g ())