diff --git a/src/web/ui/src/Accounts/State.fs b/src/web/ui/src/Accounts/State.fs index b0d9490b6..4d5ae15ea 100644 --- a/src/web/ui/src/Accounts/State.fs +++ b/src/web/ui/src/Accounts/State.fs @@ -20,6 +20,8 @@ let init (context:ServiceContext.ServiceContext) = mdRelayProductData = [||] mdRelayExpNameData = Array.empty scratch = emptyAccount + AllValue = " " + AllValueDisplay = "All" }, Access.getAdminData admin UpdateAdminData NoAdminData let existingSelection (scratch:BTSAccount) (data:AdminData) = @@ -140,6 +142,18 @@ let update msg (model:Model) : Model * Cmd = | DeleteSecurityLimit i -> let limits = erase model.scratch.securityPositionLimits i { model with scratch = { model.scratch with securityPositionLimits = limits } }, Cmd.Empty + | AddConnection conId -> + //ExchangeConnection + let cons = match model.adminData with + | None -> Array.empty + | Some data -> data.connections + let newNameArr = Array.filter (fun a -> a.id.ToString() = conId) cons + let newName = newNameArr.[0].name + let newCons = Array.append model.scratch.connections.exchangeConnectionNames [| newName |] + { model with scratch = { model.scratch with connections = { model.scratch.connections with exchangeConnectionNames = newCons }}}, Cmd.Empty + | RemoveConnection conName -> + let newCons = erase model.scratch.connections.exchangeConnectionNames (Array.findIndex (fun a -> a = conName) model.scratch.connections.exchangeConnectionNames) + { model with scratch = { model.scratch with connections = { model.scratch.connections with exchangeConnectionNames = newCons }}}, Cmd.Empty // // Exchange data | UpdateCME field -> diff --git a/src/web/ui/src/Accounts/Types.fs b/src/web/ui/src/Accounts/Types.fs index 203e99ed2..3fcec4787 100644 --- a/src/web/ui/src/Accounts/Types.fs +++ b/src/web/ui/src/Accounts/Types.fs @@ -28,6 +28,8 @@ type Model = { mdRelayProductData: Product[] mdRelayExpNameData: ExpirationNameList[] scratch : BTSAccount + AllValue: string + AllValueDisplay: string } type AccountField = @@ -71,4 +73,6 @@ type Msg = | UpdateProducts of Product[] | RequestExpirationNames | UpdateExpirationNames of ExpirationNameList[] + | AddConnection of string + | RemoveConnection of string diff --git a/src/web/ui/src/Accounts/View.fs b/src/web/ui/src/Accounts/View.fs index f2e6e4dff..2034275d2 100644 --- a/src/web/ui/src/Accounts/View.fs +++ b/src/web/ui/src/Accounts/View.fs @@ -11,6 +11,7 @@ open bts.api.orderman open EnumUtils open Fable open System +open bts.co2 let selectedAccount model = @@ -84,16 +85,25 @@ let clipLimitsView model dispatch = header = None } - let symbolArray = Array.map (fun a -> a.symbol ) model.mdRelayProductData + let symbolArray = Array.concat [| [| model.AllValueDisplay |]; Array.map (fun a -> a.symbol ) model.mdRelayProductData |] let getSecurityMap (limit:AccountSecurityClipLimitUnit) = - Array.filter (fun (x:bts.co2.ExpirationNameList) -> ( - x.product.exchange = limit.security.exchange - && x.product.``type`` = limit.security.securityType - && x.product.symbol = limit.security.securitySymbol + let allOption = { + product = { + exchange = bts.api.Venue.UNSET + ``type`` = bts.api.SecurityType.UNSET + symbol = model.AllValueDisplay + }; + names = (JSMap.add "0" model.AllValueDisplay JSMap.empty) + }:ExpirationNameList + + Array.concat [ [| allOption |]; model.mdRelayExpNameData] + |> Array.filter (fun (x:bts.co2.ExpirationNameList) -> ( + ((x.product.exchange = limit.security.exchange) || (x.product.exchange = bts.api.Venue.UNSET)) + && ((x.product.``type`` = limit.security.securityType) || (x.product.``type`` = bts.api.SecurityType.UNSET)) + && ((x.product.symbol = limit.security.securitySymbol) || (x.product.symbol = model.AllValueDisplay)) ) ) - model.mdRelayExpNameData |> Seq.map (fun x -> x.names ) |> JSMap.concat let modifyRow (oldRow:AccountSecurityClipLimitUnit) (newRow:AccountSecurityClipLimitUnit) = @@ -113,7 +123,10 @@ let clipLimitsView model dispatch = modifyRow oldRow newRow let changeSymbol (oldRow:AccountSecurityClipLimitUnit) (value:string) = - modifyRow oldRow { oldRow with security = { oldRow.security with securitySymbol = value } } + let v = match (value = model.AllValueDisplay) with + | false -> value + | true -> model.AllValue + modifyRow oldRow { oldRow with security = { oldRow.security with securitySymbol = v } } let changeSecurityId (oldRow:AccountSecurityClipLimitUnit) (value:string) = modifyRow oldRow { oldRow with security = { oldRow.security with securityId = (uint32 value) } } @@ -146,8 +159,8 @@ let clipLimitsView model dispatch = } { content = Fields.enumSelect "" - (EnumUtils.toHuman false symbolArray limit.security.securitySymbol) - (EnumUtils.allToHuman false symbolArray) + limit.security.securitySymbol + symbolArray [] ((changeSymbol limit) >> ClipLimits >> dispatch) className = "" @@ -156,7 +169,7 @@ let clipLimitsView model dispatch = { content = Fields.mapSelect "" (JSMap.toMap (getSecurityMap limit)) - (Some "*") + None (Some (sprintf "%i" limit.security.securityId)) ((changeSecurityId limit) >> ClipLimits >> dispatch) className = "" @@ -203,7 +216,7 @@ let productLimits model dispatch = header = None } - let symbolArray = Array.map (fun a -> a.symbol ) model.mdRelayProductData + let symbolArray = Array.concat [| [| model.AllValueDisplay |]; Array.map (fun a -> a.symbol ) model.mdRelayProductData |] let modifyRow (oldRow:AccountProductPositionLimitUnit) (newRow:AccountProductPositionLimitUnit) = let i = Array.findIndex (fun l -> oldRow = l) model.scratch.productPositionLimits @@ -222,7 +235,10 @@ let productLimits model dispatch = modifyRow oldRow newRow let changeSymbol (oldRow:AccountProductPositionLimitUnit) (value:string) = - modifyRow oldRow { oldRow with product = { oldRow.product with securitySymbol = value } } + let v = match (value = model.AllValueDisplay) with + | false -> value + | true -> model.AllValue + modifyRow oldRow { oldRow with product = { oldRow.product with securitySymbol = v } } let changeLongPositionLimit (oldRow:AccountProductPositionLimitUnit) (value:string) = modifyRow oldRow { oldRow with longPositionLimit = (uint32 value) } @@ -255,8 +271,8 @@ let productLimits model dispatch = } { content = Fields.enumSelect "" - (EnumUtils.toHuman false symbolArray limit.product.securitySymbol) - (EnumUtils.allToHuman false symbolArray) + limit.product.securitySymbol + symbolArray [] ((changeSymbol limit) >> ProductLimits >> dispatch) className = "" @@ -265,7 +281,7 @@ let productLimits model dispatch = { content = Fields.text "" (sprintf "%i" limit.longPositionLimit) - [ Style [Width "4em"]] + [ Style [Width "10em"]] ((changeLongPositionLimit limit) >> ProductLimits >> dispatch) className = "" isHeader = false @@ -273,7 +289,7 @@ let productLimits model dispatch = { content = Fields.text "" (sprintf "%i" limit.shortPositionLimit) - [ Style [Width "4em"]] + [ Style [Width "10em"]] ((changeShortPositionLimit limit) >> ProductLimits >> dispatch) className = "" isHeader = false @@ -287,7 +303,7 @@ let productLimits model dispatch = product = { exchange = bts.api.Venue.GLBX securityType = bts.api.SecurityType.FUTURE - securitySymbol = "For All" + securitySymbol = model.AllValueDisplay } longPositionLimit = 0u shortPositionLimit = 0u @@ -297,7 +313,7 @@ let productLimits model dispatch = let addRow _ = Array.append model.scratch.productPositionLimits [| emptyLimit |] |> (ProductLimits >> dispatch) div [] [ - h1 [ ClassName "is-size-4" ][str "Product Limits"] + h1 [ ClassName "is-size-4" ][str "Product Limits"; span [ClassName "is-size-7 has-text-grey-light"][ str " This is a limit for products"] ] TableControl.createTableWithStyle (Some headerRow) rws [Width "100%"; Border "1px solid lightgray"] span [ClassName "is-pulled-right"] [ Button.fabutton "Add Row" "plus" Button.Enabled addRow ] ] @@ -319,7 +335,7 @@ let securityLimits model dispatch = header = None } - let symbolArray = Array.map (fun a -> a.symbol ) model.mdRelayProductData + let symbolArray = Array.concat [| [| model.AllValueDisplay |]; Array.map (fun a -> a.symbol ) model.mdRelayProductData |] let modifyRow (oldRow:AccountSecurityPositionLimitUnit) (newRow:AccountSecurityPositionLimitUnit) = let i = Array.findIndex (fun l -> oldRow = l) model.scratch.securityPositionLimits @@ -338,7 +354,10 @@ let securityLimits model dispatch = modifyRow oldRow newRow let changeSymbol (oldRow:AccountSecurityPositionLimitUnit) (value:string) = - modifyRow oldRow { oldRow with security = { oldRow.security with securitySymbol = value } } + let v = match (value = model.AllValueDisplay) with + | false -> value + | true -> model.AllValue + modifyRow oldRow { oldRow with security = { oldRow.security with securitySymbol = v } } let changeLongPositionLimit (oldRow:AccountSecurityPositionLimitUnit) (value:string) = modifyRow oldRow { oldRow with longPositionLimit = (uint32 value) } @@ -371,8 +390,8 @@ let securityLimits model dispatch = } { content = Fields.enumSelect "" - (EnumUtils.toHuman false symbolArray limit.security.securitySymbol) - (EnumUtils.allToHuman false symbolArray) + limit.security.securitySymbol + symbolArray [] ((changeSymbol limit) >> SecurityLimits >> dispatch) className = "" @@ -381,7 +400,7 @@ let securityLimits model dispatch = { content = Fields.text "" (sprintf "%i" limit.longPositionLimit) - [ Style [Width "4em"]] + [ Style [Width "10em"]] ((changeLongPositionLimit limit) >> SecurityLimits >> dispatch) className = "" isHeader = false @@ -389,7 +408,7 @@ let securityLimits model dispatch = { content = Fields.text "" (sprintf "%i" limit.shortPositionLimit) - [ Style [Width "4em"]] + [ Style [Width "10em"]] ((changeShortPositionLimit limit) >> SecurityLimits >> dispatch) className = "" isHeader = false @@ -409,7 +428,7 @@ let securityLimits model dispatch = let addRow _ = Array.append model.scratch.securityPositionLimits [| emptyLimit |] |> (SecurityLimits >> dispatch) div [] [ - h1 [ ClassName "is-size-4" ][str "Security Limits"] + h1 [ ClassName "is-size-4" ][str "Security Limits"; span [ClassName "is-size-7 has-text-grey-light"][ str " This is a limit for Securities"]] TableControl.createTableWithStyle (Some headerRow) rws [Width "100%"; Border "1px solid lightgray"] span [ClassName "is-pulled-right"] [ Button.fabutton "Add Row" "plus" Button.Enabled addRow ] @@ -422,11 +441,47 @@ let positionLimitsView model dispatch = securityLimits model dispatch ] -let ConnectionsView model dispatch = - div [] [ - str "will come back to this" - ] +let ConnectionsView (model:Accounts.Types.Model) dispatch = + let conNames = model.scratch.connections.exchangeConnectionNames + + let rws:TableControl.row list = + [for name in conNames do yield { + cells = [ + { + content = str name + className = "" + isHeader = false + } + { + content = Button.button "" "is-light" "times" Button.Enabled (fun _ -> name |> ( RemoveConnection >> dispatch)) + className = "" + isHeader = false + } + ] + className="" + header = None + } + ] + + let cons = match model.adminData with + | None -> Array.empty + | Some data -> data.connections + let conMap = + cons + |> Array.filter (fun a -> not <| (Array.contains a.name conNames)) + |> Array.map (fun a -> a.id.ToString(), a.name) + |> Map.ofArray + + let rows = + if not (Map.isEmpty conMap) then + rws @ [{cells = [ {content = Fields.mapSelect "" conMap (Some "Add Connection") None (fun v -> v |> (AddConnection >> dispatch)); className = ""; isHeader = true } ]; className = ""; header = None }] + else rws + div [] + [ + TableControl.createTable None rows + ] + let creditLimitsView model dispatch = div [] [str "lorem ipsum"] let exchangeSettings model dispatch = @@ -500,6 +555,7 @@ let tabName = function | ClipLimitsTab -> "Clip Limits" | PositionLimitsTab -> "Position Limits" | CreditLimitsTab -> "Credit Limits" + | ConnectionsTab -> "Connections" | ExchangeSettingsTab -> "Exchange Settings" | other -> string other