Add manual fills before validating

This commit is contained in:
Michael Harding committed 2019-08-27 12:41:09 -04:00
1 parent 7cbfc4d7d7
commit 631964e8bd
4 files changed
+61 -43

No files matched your search

+4
View File
@@ -355,4 +355,8 @@ body {
.disabled-label {
color: $grey;
}
.is-100-width {
width: 100px
}
+20 -14
View File
@@ -44,7 +44,15 @@ let sideToString side =
| _ -> "Buy"
let emptyTempManualFill = {id = 0u; newId = 0u; qty = "0"; price = "0"; side="Buy"; user=""; venue=""; symbol=""; expiration=""; SecurityId=""; fillType = ManualFill.FillType.LOCAL }
let emptyTempManualFill = {id = 0u; newId = 0u; qty = "0"; price = "0"; side="Buy"; user=""; venue=""; symbol=""; expiration=""; SecurityId="0"; fillType = ManualFill.FillType.AdminDay }
let validateManualFill (fill:TempFillData) =
let parsedQty = System.Int32.TryParse fill.qty
fill.SecurityId <> "0"
&& fill.user <> ""
&& parsedQty |> fst
&& snd parsedQty >= 0
&& System.Double.TryParse fill.price |> fst
let convertTempManualFIll (tempFill:TempFillData) (model: Model) =
{ emptyManualFill with
@@ -60,7 +68,10 @@ let convertTempManualFIll (tempFill:TempFillData) (model: Model) =
}
let convertTempFillList (fills:TempFillData list) (model:Model) =
let lst = List.map (fun mf -> convertTempManualFIll mf model) fills
let lst =
fills
|> List.filter (fun mf -> mf |> validateManualFill)
|> List.map (fun mf -> convertTempManualFIll mf model)
{
manualFill = Array.ofList lst
}
@@ -221,8 +232,8 @@ let saveAccount (admin:IAdminService) (account:BTSAccount) (manualFillData:Manua
let result6Msg = result6.response |> Array.tryFind (fun i -> (not i.ok))
let result7Msg = result7.response |> Array.tryFind (fun i -> (not i.ok))
//match result.isSuccess, result2.success, result3.success, result4.success, result5Msg, result6Msg, result7Msg with
match result.isSuccess, true, true, true, result5Msg, result6Msg, result7Msg with
match result.isSuccess, result2.success, result3.success, result4.success, result5Msg, result6Msg, result7Msg with
//match result.isSuccess, true, true, true, result5Msg, result6Msg, result7Msg with
| false, _, _, _, _, _, _ ->
return ErrorOccured (sprintf "Error saving account: %s" result.errorText)
| _, false, _, _, _, _, _ ->
@@ -314,14 +325,6 @@ let clearSelection model =
ShowLoading = false
}
let clearData model =
{ model with
ManualFillData =
{ model.ManualFillData with
newFills = list.Empty
updatedFills = list.Empty
}
}
let orderIsEqual (order1:OrdersSummaryUnit) (order2:OrdersSummaryUnit) =
(order1.account = order2.account)
@@ -353,8 +356,11 @@ let modifyProductPositionRow limits (oldRow:AccountProductPositionLimitUnit) (ne
let right = limits.[1+ind..]
Array.concat [left; right]
let clearValidNewFills model =
model.ManualFillData.newFills |> List.filter (validateManualFill >> not)
let clearManualFill model =
{model with ManualFillData = {model.ManualFillData with newFills = []; updatedFills = []; deletedFills = {manualFill = Array.empty}}}
{model with ManualFillData = {model.ManualFillData with newFills = clearValidNewFills model; updatedFills = []; deletedFills = {manualFill = Array.empty}}}
let update msg (model:Model) : Model * Cmd<Msg> =
match msg with
@@ -392,7 +398,7 @@ let update msg (model:Model) : Model * Cmd<Msg> =
scratch = account
ManualFillData = {
fills = { manualFill = (Array.empty: bts.api.position.ManualFill [])}
newFills = list.Empty
newFills = clearValidNewFills model
updatedFills = list.Empty
deletedFills = { manualFill = (Array.empty: bts.api.position.ManualFill [])}
tempSODFillData = emptyTempManualFill
+19 -10
View File
@@ -141,7 +141,7 @@ let marginView model dispatch =
div [][
TableControl.createDataTable (Some headerRow) [rws] (span [][])
Fields.checkbox "Enforce Margin Limit" "" (model.marginScratch.shouldEnforceMargin) [] (SetEnforceMargin >> dispatch)
Fields.number "Leverage Factor:" (string model.marginScratch.leverageFactor) [Disabled disabled] (double >> SetMarginCashFactor >> dispatch)
Fields.number "Leverage Factor:" (string model.marginScratch.leverageFactor) [Disabled disabled] (fun _ -> true) (double >> SetMarginCashFactor >> dispatch)
Fields.intNumber "Cash Balance:" (string model.marginScratch.cashBalance) [Disabled disabled] (double >> SetMarginCashBalance >> dispatch)
accountControls model dispatch
]
@@ -825,8 +825,8 @@ let DayPositionView model dispatch =
TableControl.Cell (str "Security")
TableControl.Cell (str "User")
TableControl.Cell (str "Side")
TableControl.Cell (str "Qty")
TableControl.Cell (str "Price")
{ content = (str "Qty"); className = "is-100-width"; isHeader = false; colSpan = 1 }
{ content = (str "Price"); className = "is-100-width"; isHeader = false; colSpan = 1 }
TableControl.Cell (str "")
]
className = ""
@@ -895,7 +895,7 @@ let DayPositionView model dispatch =
)
TableControl.Cell (Fields.simpleSelect "" extantUsersMap model.ManualFillData.tempDayFillData.user ((fun v -> (v, "user", false)) >> UpdateTempManualFill >> dispatch))
TableControl.Cell (Fields.simpleSelect "" ["Buy"; "Sell"] model.ManualFillData.tempDayFillData.side ((fun v -> (v, "side", false)) >> UpdateTempManualFill >> dispatch))
TableControl.Cell (Fields.intNumber
TableControl.Cell (Fields.positiveIntNumber
""
(model.ManualFillData.tempDayFillData.qty)
[ ]
@@ -905,6 +905,7 @@ let DayPositionView model dispatch =
""
(model.ManualFillData.tempDayFillData.price)
[ ]
(fun _ -> true)
((fun v -> (v, "price", false)) >> UpdateTempManualFill >> dispatch)
)
TableControl.Cell (Button.addButton (Button.boolToDisabledConverter disableAdd) (fun _ -> AddManualFill <| false |> dispatch))
@@ -955,7 +956,7 @@ let DayPositionView model dispatch =
(fun v -> (ulimit.id, v, "SecurityId", false) |> UpdateManualFill |> dispatch))
TableControl.Cell (Fields.simpleSelect "" extantUsersMap ulimit.user (fun v -> (ulimit.id, v, "user", false) |> UpdateManualFill |> dispatch))
TableControl.Cell (Fields.simpleSelect "" ["Buy"; "Sell"] ulimit.side (fun v -> (ulimit.id, v, "side", false) |> UpdateManualFill |> dispatch))
TableControl.Cell (Fields.intNumber
TableControl.Cell (Fields.positiveIntNumber
""
ulimit.qty
[ ]
@@ -965,6 +966,7 @@ let DayPositionView model dispatch =
""
ulimit.price
[ ]
(fun _ -> true)
(fun v -> (ulimit.id, v, "price", false) |> UpdateManualFill |> dispatch)
)
TableControl.Cell (str "")
@@ -1009,12 +1011,15 @@ let DayPositionView model dispatch =
(limit.venue)
(limit.symbol)
)
(Some securityMap.[uint32 limit.SecurityId].securityName)
(match limit.SecurityId with
| "0" -> None
| _ -> Some securityMap.[uint32 limit.SecurityId].securityName
)
(Some limit.SecurityId)
(fun v -> (limit.newId, v, "SecurityId", true) |> UpdateManualFill |> dispatch))
TableControl.Cell (Fields.simpleSelect "" extantUsersMap limit.user (fun v -> (limit.newId, v, "user", true) |> UpdateManualFill |> dispatch))
TableControl.Cell (Fields.simpleSelect "" ["Buy"; "Sell"] limit.side (fun v -> (limit.newId, v, "side", true) |> UpdateManualFill |> dispatch))
TableControl.Cell (Fields.intNumber
TableControl.Cell (Fields.positiveIntNumber
""
limit.qty
[ ]
@@ -1024,6 +1029,7 @@ let DayPositionView model dispatch =
""
limit.price
[ ]
(fun _ -> true)
(fun v -> (limit.newId, v, "price", true) |> UpdateManualFill |> dispatch)
)
TableControl.Cell (str "")
@@ -1033,7 +1039,7 @@ let DayPositionView model dispatch =
onClick = None
}]
let rws:TableControl.row list = fillRows @ newRows @ [footerRow]
let rws:TableControl.row list = fillRows @ newRows
div []
[
@@ -1042,7 +1048,10 @@ let DayPositionView model dispatch =
div [ ClassName "column is-size-7 has-text-grey-mid is-help-text"; ]
[str "Manually add fills for the Day position"]
]
TableControl.createDataTableWithStyle (Some headerRow) rws "" [Width "inherit"] (span [][])
TableControl.createDataTableWithStyle (Some headerRow) rws "" [MinWidth 824] (
Button.fabutton "Add" "plus" "" (Button.boolToDisabledConverter false) (fun _ -> AddManualFill <| false |> dispatch)
)
]
let PositionUploadView model dispatch =
@@ -1337,7 +1346,7 @@ let root (model:Model) dispatch =
// tabHeader CreditLimits model.tab dispatch
(if (Array.length data.accounts > 0) then (tabHeader ExchangeSettingsTab model.tab dispatch) else span [][] )
(if (Array.length data.accounts > 0) then (tabHeader OrdersTab model.tab dispatch) else span [][] )
//(if (Array.length data.accounts > 0) then (tabHeader PositionManagementTab model.tab dispatch) else span [][] )
(if (Array.length data.accounts > 0) then (tabHeader PositionManagementTab model.tab dispatch) else span [][] )
(if (Array.length data.accounts > 0) then (tabHeader MarginTab model.tab dispatch) else span [][] )
]
]
+18 -19
View File
@@ -151,11 +151,10 @@ let password (lbl:string) (dv:string) (attrs:IHTMLProp list) onchange =
]
]
let intNumber (lbl:string) (dv:string) (attrs:IHTMLProp list) onchange =
let errorClass = match System.Int32.TryParse dv with
| true, _ -> ""
| false, _ -> "is-danger"
let number (lbl:string) (dv:string) (attrs:IHTMLProp list) (validate: string -> bool) onchange =
let errorClass = match dv |> validate with
| true -> ""
| false -> "is-danger"
div [ ClassName "field" ]
[
@@ -166,23 +165,23 @@ let intNumber (lbl:string) (dv:string) (attrs:IHTMLProp list) onchange =
Type "number"
Value (string dv)
OnChange (fun ev -> !!ev.target?value |> onchange)
] @ attrs)
] @ attrs)
]
]
let number (lbl:string) (dv:string) (attrs:IHTMLProp list) onchange =
div [ ClassName "field" ]
[
Label lbl
div [ ClassName "control" ]
[ input ([
ClassName "input"
Type "number"
Value (string dv)
OnChange (fun ev -> !!ev.target?value |> onchange)
] @ attrs)
]
]
let intNumber (lbl:string) (dv:string) (attrs:IHTMLProp list) onchange =
let validate value = fst <| System.Int32.TryParse value
number lbl dv attrs validate onchange
let positiveIntNumber (lbl:string) (dv:string) (attrs:IHTMLProp list) onchange =
let validate value =
let itp = System.Int32.TryParse value
fst itp && snd itp >= 0
number lbl dv attrs validate onchange
let double (lbl:string) (dv:double) (attrs:IHTMLProp list) onchange =