Commits

Oliver Gu  committed 553044c

Fixed parse error caused by empty price field

  • Participants
  • Parent commits 6a443bd

Comments (0)

Files changed (3)

File lib/response.ml

         Fields.fold
           ~init:(step Fn.id)
           ~tick_type:(fields_value (required Type.val_type))
-          ~price:(fields_value (required Price.val_type))
+          ~price:(fields_value (optional_with_default ~default:Price.zero Price.val_type))
           ~size:(fields_value (required int))
           ~can_auto_execute:(fields_value (optional bool ~none_on_default:"-1")))
       (fun tick_type price size can_auto_execute ->

File lib/tws_prot.ml

         serialize_opt default_on_none val_type.Val_type.tws_of_a a buf);
     }
 
+
+
     let skipped_if_none val_type = {
       value = (fun a_opt buf ->
         match a_opt with
         parse_opt none_on_default name val_type.Val_type.a_of_tws msg);
     }
 
+    let optional_with_default ~default val_type = {
+      value = (fun ~name msg ->
+        match parse_opt "" name val_type.Val_type.a_of_tws msg with
+        | None  , msg -> default, msg
+        | Some a, msg -> a      , msg);
+    }
+
     let capture_remaining_message = {
       f = (fun (k, msg) ->
         let captured_msg = Queue.create () in

File lib/tws_prot.mli

 
     val required : 'a Val_type.t -> 'a value
     val optional : ?none_on_default:raw_tws -> 'a Val_type.t -> 'a option value
+    val optional_with_default : default:'a -> 'a Val_type.t -> 'a value
 
     val value : 'a value -> name:string -> ('a -> 'c, 'c) t
     val capture_remaining_message : (raw_tws Queue.t -> 'c, 'c) t
 
-
     val fields_value
       :  'a value
       -> ('c1, 'a -> 'c2) t