diff --git a/src/web/ui/src/Accounts/State.fs b/src/web/ui/src/Accounts/State.fs index adf2d7d4d..d139f0056 100644 --- a/src/web/ui/src/Accounts/State.fs +++ b/src/web/ui/src/Accounts/State.fs @@ -132,6 +132,42 @@ let positionSub model dispatch = |> SetUnsub |> dispatch +let marginSub model dispatch = + match model.unsub with + | Some (unsub) -> unsub.Dispose() + | None -> () + let svc = model.marginService + svc.subscribe_excess_liquidity_report "" ( + fun (subUpdate:StreamUtils.IUpdate) -> + (* + The update does not seem to contain any data + and there is no way to specify the account. + this should be revisited + *) + + //subUpdate.all + //|> JSMap.toArray + //|> Array.map snd + //|> UpdateMarginData + //|> dispatch + + GetMarginData |> dispatch + ) + |> SetUnsub + |> dispatch + + +let selectSub (tab:Tab option) model = + match tab, model.tab with + | Some PositionManagementTab, _ | None, PositionManagementTab -> Cmd.ofSub (positionSub model) + | Some MarginTab, _ | None, MarginTab -> Cmd.ofMsg GetMarginData //Cmd.ofSub (marginSub model) + | _ -> + match model.unsub with + | Some (unsub) -> unsub.Dispose() + | None -> + System.Console.WriteLine "...?" + () + Cmd.none let existingSelection (scratch:BTSAccount) (previousScratch:BTSAccount) (data:AdminData) = List.choose id [ @@ -295,7 +331,6 @@ let modifyProductPositionRow limits (oldRow:AccountProductPositionLimitUnit) (ne let clearManualFill model = {model with ManualFillData = {model.ManualFillData with newFills = []; updatedFills = []; deletedFills = {manualFill = Array.empty}}} - let update msg (model:Model) : Model * Cmd = match msg with | UpdateAdminData data -> @@ -339,14 +374,13 @@ let update msg (model:Model) : Model * Cmd = tempDayFillData = emptyTempManualFill } marginScratch = emptyMargin - }, Cmd.batch [ - Cmd.ofSub (positionSub model) - GetMarginData |> Cmd.ofMsg - ] + }, selectSub None model | GetMarginData -> { model with ShowLoading = false}, (getMarginData model.marginService model.scratch.name UpdateMarginData (box>>ErrorOccured)) | UpdateMarginData newData -> - let cmd = Cmd.ofPromise (fun _ -> promise { do! Promise.sleep 10000 } ) () (fun _ -> GetMarginData) (fun _ -> GetMarginData) + let cmd = match model.tab with + | MarginTab -> Cmd.ofPromise (fun _ -> promise { do! Promise.sleep 10000 } ) () (fun _ -> GetMarginData) (fun _ -> GetMarginData) + | _ -> Cmd.none match (model.marginScratch = emptyMargin || model.marginScratch.account <> model.scratch.name), (compareDouble model.marginData.leverageFactor model.marginScratch.leverageFactor 10000u), (compareDouble model.marginData.cashBalance model.marginScratch.cashBalance 10000u), @@ -388,13 +422,17 @@ let update msg (model:Model) : Model * Cmd = | SelectTab tab -> match tab with | OrdersTab -> - { (clearSelection model) with tab = tab }, Cmd.ofMsg GetOrdersData + { (clearSelection model) with tab = tab }, Cmd.batch [ + Cmd.ofMsg GetOrdersData + selectSub (Some OrdersTab) model + ] | PositionManagementTab -> - { (clearSelection model) with tab = tab }, Cmd.Empty + { (clearSelection model) with tab = tab }, selectSub (Some PositionManagementTab) model | MarginTab -> - { (clearSelection model) with tab = tab }, Cmd.ofMsg GetMarginData + { (clearSelection model) with tab = tab }, selectSub (Some MarginTab) model | _ -> - { (clearSelection model) with tab = tab }, Cmd.Empty + { (clearSelection model) with tab = tab }, selectSub (Some tab) model + | Update field -> { model with scratch = applyUpdate model.scratch field }, Cmd.Empty | ClipLimits (oldLimit, newLimit) -> @@ -502,10 +540,7 @@ let update msg (model:Model) : Model * Cmd = | RequestExpirationNames -> model, Cmd.ofExistingPromise (requestExpNames model.mdRelay) id (box>>ErrorOccured) | UpdateExpirationNames (data:ExpirationNameList[]) -> - { (clearManualFill model) with mdRelayExpNameData = data }, Cmd.batch [ - Cmd.ofSub (positionSub model) - Cmd.ofMsg GetMarginData - ] + { (clearManualFill model) with mdRelayExpNameData = data }, selectSub None model | OpenOptionsMenu acc -> {model with OptionsMenuOpen = acc}, Cmd.Empty | OpenConfirmModal (title, okMessage) -> diff --git a/src/web/ui/src/Accounts/View.fs b/src/web/ui/src/Accounts/View.fs index c32e38150..4e9c78493 100644 --- a/src/web/ui/src/Accounts/View.fs +++ b/src/web/ui/src/Accounts/View.fs @@ -999,7 +999,7 @@ let DayPositionView model dispatch = cells = [ TableControl.Cell (Button.deleteButton Button.IsDisabled.Enabled (fun _ -> ((limit.newId |> int), true) |> RemoveManualFill |> dispatch)) - TableControl.Cell (span [Style [Color "green"]][str (sprintf "NEW(%i)" limit.newId)]) + TableControl.Cell (span [Style [Color "green"]][str "NEW"]) TableControl.Cell (Fields.simpleSelect "" venueList (limit.venue) (fun v -> (limit.newId, v, "venue", true) |> UpdateManualFill |> dispatch)) TableControl.Cell (Fields.simpleSelect "" (getSymbolList model limit.venue) (limit.symbol) (fun v -> (limit.newId, v, "symbol", true) |> UpdateManualFill |> dispatch)) TableControl.Cell (Fields.mapSelect