Commits

Oliver Gu committed 3a0340e

Added Account_update response

  • Participants
  • Parent commits 14e9ff9

Comments (0)

Files changed (4)

File lib/response.ml

    | Account and Portfolio                                                 |
    +-----------------------------------------------------------------------+ *)
 
+module Account_update = struct
+  type t = {
+    key : string;
+    value : string;
+    currency : Currency.t;
+    account_code : Account_code.t;
+  } with sexp, fields
+
+  let create = Fields.create
+
+  let ( = ) t1 t2 : bool =
+    let use op = fun field ->
+      op (Field.get field t1) (Field.get field t2)
+    in
+    Fields.for_all
+      ~key:(use (=))
+      ~value:(use (=))
+      ~currency:(use (=))
+      ~account_code:(use (=))
+
+  let unpickler =
+    Unpickler.create ~name:"Account_update"
+      Unpickler.Spec.(
+        Fields.fold
+          ~init:(empty ())
+          ~key:(fields_value (required string))
+          ~value:(fields_value (required string))
+          ~currency:(fields_value (required Currency.val_type))
+          ~account_code:(fields_value (required Account_code.val_type)))
+      (fun key value currency account_code ->
+        { key; value; currency; account_code })
+
+  let pickler = Only_in_test.of_thunk (fun () ->
+    Pickler.create ~name:"Account_update"
+      Pickler.Spec.(
+        wrap (
+          Fields.fold
+            ~init:(empty ())
+            ~key:(fields_value (required string))
+            ~value:(fields_value (required string))
+            ~currency:(fields_value (required Currency.val_type))
+            ~account_code:(fields_value (required Account_code.val_type)))
+          (fun t -> `Args $ t.key $ t.value $ t.currency $ t.account_code)))
+end
+
 (* +-----------------------------------------------------------------------+
    | Contract specs                                                        |
    +-----------------------------------------------------------------------+ *)

File lib/response.mli

     -> t
 end
 
-(** {1 Execution} *)
+(** {1 Account and Portfolio} *)
 (*****************************************************************************)
 
-module Execution_report : sig
-  module Side : sig
-    type t = [ `Purchase | `Sale ] with sexp
-    include Stringable.S with type t := t
-  end
-
+module Account_update : sig
   type t = private
-    { order_id : Order_id.t;
-      contract : Contract.Type.t Contract.t;
-      exec_id : Execution_id.t;
-      time : Time.t;
+    { key : string;
+      value : string;
+      currency : Currency.t;
       account_code : Account_code.t;
-      exchange : Exchange.t;
-      side : Side.t;
-      quantity : int;
-      price : Price.t;
-      permanent_id : int;
-      client_id : Client_id.t;
-      liquidation : int;
-      cumulative_quantity : int;
-      average_price : Price.t;
-      order_ref : string option;
     }
   with sexp, fields
   include Response_intf.S with type t := t
 
   val create :
-    order_id:Order_id.t
-    -> contract:Contract.Type.t Contract.t
-    -> exec_id:Execution_id.t
-    -> time:Time.t
-    -> account_code:Account_code.t
-    -> exchange:Exchange.t
-    -> side:[ `Purchase | `Sale ]
-    -> quantity:int
-    -> price:Price.t
-    -> permanent_id:int
-    -> client_id:Client_id.t
-    -> liquidation:int
-    -> cumulative_quantity:int
-    -> average_price:Price.t
-    -> order_ref:string option
-    -> t
-end
-
-module Commission_report : sig
-  type t = private
-    { exec_id : Execution_id.t;
-      commission : Price.t;
-      currency : Currency.t;
-      realized_pnl : Price.t;
-      yield : float;
-      yield_redemption_date : int option;
-    } with sexp, fields
-  include Response_intf.S with type t := t
-
-  val create
-    :  exec_id:Execution_id.t
-    -> commission:Price.t
+    key:string
+    -> value:string
     -> currency:Currency.t
-    -> realized_pnl:Price.t
-    -> yield:float
-    -> yield_redemption_date:int option
+    -> account_code:Account_code.t
     -> t
 end
 
   val to_contract : t -> Contract.Type.t Contract.t
 end
 
+(** {1 Execution} *)
+(*****************************************************************************)
+
+module Execution_report : sig
+  module Side : sig
+    type t = [ `Purchase | `Sale ] with sexp
+    include Stringable.S with type t := t
+  end
+
+  type t = private
+    { order_id : Order_id.t;
+      contract : Contract.Type.t Contract.t;
+      exec_id : Execution_id.t;
+      time : Time.t;
+      account_code : Account_code.t;
+      exchange : Exchange.t;
+      side : Side.t;
+      quantity : int;
+      price : Price.t;
+      permanent_id : int;
+      client_id : Client_id.t;
+      liquidation : int;
+      cumulative_quantity : int;
+      average_price : Price.t;
+      order_ref : string option;
+    }
+  with sexp, fields
+  include Response_intf.S with type t := t
+
+  val create :
+    order_id:Order_id.t
+    -> contract:Contract.Type.t Contract.t
+    -> exec_id:Execution_id.t
+    -> time:Time.t
+    -> account_code:Account_code.t
+    -> exchange:Exchange.t
+    -> side:[ `Purchase | `Sale ]
+    -> quantity:int
+    -> price:Price.t
+    -> permanent_id:int
+    -> client_id:Client_id.t
+    -> liquidation:int
+    -> cumulative_quantity:int
+    -> average_price:Price.t
+    -> order_ref:string option
+    -> t
+end
+
+module Commission_report : sig
+  type t = private
+    { exec_id : Execution_id.t;
+      commission : Price.t;
+      currency : Currency.t;
+      realized_pnl : Price.t;
+      yield : float;
+      yield_redemption_date : int option;
+    } with sexp, fields
+  include Response_intf.S with type t := t
+
+  val create
+    :  exec_id:Execution_id.t
+    -> commission:Price.t
+    -> currency:Currency.t
+    -> realized_pnl:Price.t
+    -> yield:float
+    -> yield_redemption_date:int option
+    -> t
+end
+
 (** {1 Market depth} *)
 (*****************************************************************************)
 

File lib_test/pickle_test.ml

       let module R = Response.Order_status in
       gen_test (module R : Response_intf.S with type t = R.t) Rg.R.order_status_g);
 
+    (* ======================= Account and Portfolio ======================= *)
+
+    (fun () ->
+      let module R = Response.Account_update in
+      gen_test (module R : Response_intf.S with type t = R.t) Rg.R.account_update_g);
+
     (* ========================== Contract specs =========================== *)
 
     (fun () ->

File lib_test/rg.ml

   val order_status_g : Response.Order_status.t gen
   val order_states_g : Response.Order_status.t list gen
 
-  (* Executions *)
+  (* Account and Portfolio *)
 
-  val execution_report_g  : Response.Execution_report.t gen
-  val execution_reports_g : Response.Execution_report.t list gen
+  val account_update_g : Response.Account_update.t gen
 
   (* Contract specs *)
 
   val contract_specs_g : Response.Contract_specs.t gen
 
+  (* Executions *)
+
+  val execution_report_g  : Response.Execution_report.t gen
+  val execution_reports_g : Response.Execution_report.t list gen
+
   (* Market depth *)
 
   val book_update_g  : Response.Book_update.t gen
 
   let server_time_g () = Response.Server_time.create ~time:(tmg ())
 
-  (* ============================ Contract specs =========================== *)
-
-  let contract_specs_g () =
-    let contract_type_g () = oneof [
-      always (`Stock);
-      always (`Option);
-      always (`Futures);
-    ] ()
-    in
-    Response.Contract_specs.create
-      ~symbol:(symbol_g ())
-      ~contract_type:(contract_type_g ())
-      ~expiry:(og expiry_g ())
-      ~strike:(og price_g ())
-      ~option_right:(og option_right_g ())
-      ~exchange:(exchange_g ())
-      ~currency:(currency_g ())
-      ~local_symbol:(og symbol_g ())
-      ~market_name:(sg ())
-      ~trading_class:(sg ())
-      ~contract_id:(contract_id_g ())
-      ~min_tick:(pfg ())
-      ~multiplier:(og sg ())
-      ~order_types:(List.init (Random.int 10) ~f:(fun _ -> sg ()))
-      ~valid_exchanges:(List.init (Random.int 10) ~f:(fun _ -> exchange_g ()))
-      ~price_magnifier:(nng ())
-      ~underlying_id:(nng ())
-      ~long_name:(sg ())
-      ~listing_exchange:(og exchange_g ())
-      ~contract_month:(sg ())
-      ~industry:(sg ())
-      ~category:(sg ())
-      ~subcategory:(sg ())
-      ~timezone_id:(sg ())
-      ~trading_hours:(sg ())
-      ~liquid_hours:(sg ())
-
   (* ============================== Market data ============================ *)
 
   let tick_price_g () =
     List.permute ~random_state:(Random.State.make_self_init ())
       (List.init (1 + Random.int bound) ~f:(fun _ -> order_status_g ()))
 
+  (* ======================== Account and Portfolio ======================== *)
+
+  let account_update_g () =
+    Response.Account_update.create
+      ~key:(sg ())
+      ~value:(sg ())
+      ~currency:(currency_g ())
+      ~account_code:(account_code_g ())
+
+  (* ============================ Contract specs =========================== *)
+
+  let contract_specs_g () =
+    let contract_type_g () = oneof [
+      always (`Stock);
+      always (`Option);
+      always (`Futures);
+    ] ()
+    in
+    Response.Contract_specs.create
+      ~symbol:(symbol_g ())
+      ~contract_type:(contract_type_g ())
+      ~expiry:(og expiry_g ())
+      ~strike:(og price_g ())
+      ~option_right:(og option_right_g ())
+      ~exchange:(exchange_g ())
+      ~currency:(currency_g ())
+      ~local_symbol:(og symbol_g ())
+      ~market_name:(sg ())
+      ~trading_class:(sg ())
+      ~contract_id:(contract_id_g ())
+      ~min_tick:(pfg ())
+      ~multiplier:(og sg ())
+      ~order_types:(List.init (Random.int 10) ~f:(fun _ -> sg ()))
+      ~valid_exchanges:(List.init (Random.int 10) ~f:(fun _ -> exchange_g ()))
+      ~price_magnifier:(nng ())
+      ~underlying_id:(nng ())
+      ~long_name:(sg ())
+      ~listing_exchange:(og exchange_g ())
+      ~contract_month:(sg ())
+      ~industry:(sg ())
+      ~category:(sg ())
+      ~subcategory:(sg ())
+      ~timezone_id:(sg ())
+      ~trading_hours:(sg ())
+      ~liquid_hours:(sg ())
+
   (* ============================= Executions ============================== *)
 
   let execution_report_g () =