1356 lines
63 KiB
FSharp
1356 lines
63 KiB
FSharp
module Accounts.View
|
|
|
|
open Accounts.Types
|
|
open Accounts.State
|
|
open Fable.Helpers.React
|
|
open Fable.Helpers.React.Props
|
|
open bts.api.admin
|
|
open bts.api.orderman
|
|
open EnumUtils
|
|
open Fable
|
|
open System
|
|
open bts.co2
|
|
open Elmish.React.Common
|
|
open System.Collections.Generic
|
|
open Fable.Core.JsInterop
|
|
open Fable.Core
|
|
|
|
let accountIsSelected (initialState:BTSAccount) (scratch:BTSAccount) = scratch <> initialState
|
|
|
|
[<Emit("$0.toLocaleString('en-US')")>]
|
|
let withCommas (n:float) : string = jsNative
|
|
|
|
[<Emit("$0.toLocaleString('en-US', {maximumFractionDigits: 2})")>]
|
|
let withCommasAndTwoDigits (n:float) : string = jsNative
|
|
|
|
let selectedAccount model =
|
|
match model.adminData with
|
|
| Some data ->
|
|
data.accounts |>
|
|
Array.tryFind (fun a -> a.id = model.scratch.id)
|
|
| None -> None
|
|
|
|
let isDirty model =
|
|
let marginDirty = model.marginData.cashBalance <> model.marginScratch.cashBalance ||
|
|
model.marginData.leverageFactor <> model.marginScratch.leverageFactor ||
|
|
model.marginData.shouldEnforceMargin <> model.marginScratch.shouldEnforceMargin
|
|
match selectedAccount model with
|
|
| Some account ->
|
|
account <> model.scratch
|
|
|| model.ManualFillData.newFills.Length > 0
|
|
|| model.ManualFillData.updatedFills.Length > 0
|
|
|| model.ManualFillData.deletedFills.manualFill.Length > 0
|
|
|| marginDirty
|
|
| None -> false
|
|
|
|
let saveButton (model:Model) dispatch =
|
|
let isNew = isNewAccount model.scratch
|
|
let buttonText = if isNew then "Create" else "Save"
|
|
let dirty = isDirty model || isNew
|
|
let enabled = if dirty then Button.Enabled else Button.Disabled
|
|
let flavor = if dirty then "is-success" else ""
|
|
Button.button buttonText flavor "" enabled (fun _ -> dispatch SaveScratch)
|
|
|
|
let accountControls model (dispatch:Msg->unit) =
|
|
let revertFun =
|
|
match (selectedAccount model) with
|
|
| Some acc -> fun _ -> (dispatch <| SelectAccount acc)
|
|
| None -> ignore
|
|
|
|
div [ClassName "is-main-control-bar"] [
|
|
saveButton model dispatch
|
|
Button.button "Revert" "" "" (if isDirty model then Button.Enabled else Button.Disabled) revertFun
|
|
]
|
|
|
|
//
|
|
// General
|
|
//
|
|
let generalView (model:Model) dispatch =
|
|
let account = model.scratch
|
|
|
|
|
|
let revertFun =
|
|
match model.adminData with
|
|
| Some data -> fun _ -> (dispatch <| SelectAccount (State.existingSelection model.scratch model.previousScratch data))
|
|
| None -> fun _ -> (dispatch <| SelectAccount emptyAccount)
|
|
|
|
let modal = Modal.showCreate
|
|
"Create Account"
|
|
(div [] [
|
|
Fields.text "Name" account.name [] (AccountName >> Update >> dispatch)
|
|
Fields.text "Description" account.description [] (Description >> Update >> dispatch)
|
|
Fields.checkbox "Open For Trading?" "Unchecking this stops all users from entering orders into the account" account.isActive [] (IsActive >> Update >> dispatch)
|
|
])
|
|
(fun _ -> dispatch SaveScratch)
|
|
revertFun
|
|
|
|
div [] [
|
|
p [ Style [FontWeight "Bold"] ] [ str ("ID: " + (string account.id))]
|
|
br []
|
|
Fields.text "Name" account.name [] (AccountName >> Update >> dispatch)
|
|
Fields.text "Description" account.description [] (Description >> Update >> dispatch)
|
|
Fields.checkbox "Open For Trading" "Unchecking this stops all users from entering orders into the account" account.isActive [] (IsActive >> Update >> dispatch)
|
|
(if (State.isNewAccount account && model.can_create) then modal else span[][])
|
|
|
|
accountControls model dispatch
|
|
]
|
|
|
|
let marginView model dispatch =
|
|
let disabled = not model.marginScratch.shouldEnforceMargin
|
|
|
|
let headerRow:TableControl.row =
|
|
{
|
|
cells =
|
|
[
|
|
TableControl.Cell (div [Style [MinWidth "3em"]][str "Time"])
|
|
TableControl.Cell (str "Account")
|
|
TableControl.Cell (str "Leverage Factor")
|
|
TableControl.Cell (str "Cash Balance")
|
|
TableControl.Cell (str "Non Opt Value")
|
|
TableControl.Cell (str "Opt Value")
|
|
TableControl.Cell (str "Initial Margin")
|
|
TableControl.Cell (str "Maint. Margin")
|
|
TableControl.Cell (str "Day PnL")
|
|
TableControl.Cell (str "Excess Liquidity")
|
|
]
|
|
className = ""
|
|
header = None
|
|
onClick = None
|
|
}
|
|
|
|
let rws:TableControl.row =
|
|
{
|
|
cells =
|
|
[
|
|
TableControl.Cell (str model.marginData.marginResult.asOfTime.[0..9])
|
|
TableControl.Cell (str model.marginData.account)
|
|
TableControl.Cell (Fields.disabledSpan (withCommas model.marginData.leverageFactor) disabled)
|
|
TableControl.Cell (Fields.disabledSpan (withCommas model.marginData.cashBalance) disabled)
|
|
TableControl.Cell (str (withCommasAndTwoDigits model.marginData.marginResult.nonoptValue))
|
|
TableControl.Cell (str (withCommasAndTwoDigits model.marginData.marginResult.optValue))
|
|
TableControl.Cell (str (withCommasAndTwoDigits model.marginData.marginResult.initialMargin))
|
|
TableControl.Cell (str (withCommasAndTwoDigits model.marginData.marginResult.maintMargin))
|
|
TableControl.Cell (str (withCommasAndTwoDigits model.marginData.accountPnl.dayPnl))
|
|
TableControl.Cell (str (withCommasAndTwoDigits model.marginData.excessLiquidity))
|
|
]
|
|
className = ""
|
|
header = None
|
|
onClick = None
|
|
}
|
|
|
|
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] (fun _ -> true) (double >> SetMarginCashFactor >> dispatch)
|
|
Fields.intNumber "Cash Balance:" (string model.marginScratch.cashBalance) [Disabled disabled] (double >> SetMarginCashBalance >> dispatch)
|
|
accountControls model dispatch
|
|
]
|
|
|
|
|
|
let GetSymbolArray (model:Model) =
|
|
Array.map<bts.api.Product, string> (fun a -> a.symbol ) model.mdRelayProductData
|
|
|> Array.distinct
|
|
|
|
let GetFilteredSymbolArray (model:Model) (remove:string []) =
|
|
let a = (Array.map<bts.api.Product, string> (fun a -> a.symbol ) model.mdRelayProductData
|
|
|> Array.filter (fun elm -> (not <| Array.exists (fun e -> elm = e) remove))
|
|
|> Array.distinct)
|
|
[ [|model.AllValueDisplay|]; a ] |> Array.concat
|
|
|
|
|
|
let ordersView (model:Model) dispatch =
|
|
let ordersList = List.filter (fun (elm:OrdersSummaryUnit) -> elm.account = model.scratch.name) model.ordersData
|
|
|
|
let headerRow:TableControl.row =
|
|
{
|
|
cells =
|
|
[
|
|
TableControl.controlCell (Fields.checkbox "" ""
|
|
(model.SelectedOrders.Length = ordersList.Length)
|
|
[]
|
|
(fun chckd -> ((chckd, ordersList) |> SelectOrder |> dispatch)))
|
|
TableControl.Cell (str "User")
|
|
TableControl.Cell (str "Total Contracts")
|
|
TableControl.Cell (str "Total Orders")
|
|
]
|
|
className = ""
|
|
header = None
|
|
onClick = None
|
|
}
|
|
|
|
let rws:TableControl.row list =
|
|
[ for od in ordersList do yield {
|
|
cells =
|
|
[
|
|
TableControl.controlCell (Fields.checkbox "" ""
|
|
(List.exists (fun (elm:OrdersSummaryUnit) -> State.orderIsEqual elm od) model.SelectedOrders)
|
|
[]
|
|
(fun chckd -> ((chckd, [od]) |> SelectOrder |> dispatch)))
|
|
TableControl.Cell (str od.user)
|
|
TableControl.Cell (str (sprintf "%i" od.totalContracts))
|
|
TableControl.Cell (str (sprintf "%i" od.totalOrders))
|
|
]
|
|
className = ""
|
|
header = None
|
|
onClick = None
|
|
}
|
|
]
|
|
|
|
let enableCancel =
|
|
match model.SelectedOrders.Length with
|
|
| 0 -> Button.Disabled
|
|
| _ -> Button.boolToDisabledConverter model.ShowLoading
|
|
|
|
let addLoadingString s b =
|
|
match b with
|
|
| true -> sprintf "is-loading %s" s
|
|
| _ -> s
|
|
|
|
let cancelMessage = model.SelectedOrders |> CancelOrders
|
|
let confirmText = sprintf "Are you sure you want to cancel all orders in %s for users: %s?" model.scratch.name (String.concat ", " (List.map (fun (elm:OrdersSummaryUnit) -> elm.user) model.SelectedOrders))
|
|
let cancelButton = Button.button "Cancel Selected Orders" (addLoadingString "is-danger" model.ShowLoading) "times" enableCancel (fun _ -> OpenConfirmModal (confirmText, cancelMessage) |> dispatch)
|
|
let reloadFun = fun _ -> dispatch (SelectTab model.tab)
|
|
|
|
div [][
|
|
TableControl.createDataTable (Some headerRow) rws (span [][ (Button.button "Refresh" "" "exchange" (Button.boolToDisabledConverter model.ShowLoading) reloadFun); nbsp.element; cancelButton ])
|
|
]
|
|
|
|
let limitFilter (positionLimit:AccountSecurityPositionLimitUnit option) (clipLimit:AccountSecurityClipLimitUnit option) allValueDisplay (array:ExpirationNameList []) =
|
|
match positionLimit, clipLimit with
|
|
| Some limit, None ->
|
|
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 = allValueDisplay))
|
|
))
|
|
array
|
|
| None, Some limit ->
|
|
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 = allValueDisplay))
|
|
))
|
|
array
|
|
| _ , _ -> array
|
|
|
|
let getSecurityMap (model:Model) (positionLimit:AccountSecurityPositionLimitUnit option) (clipLimit:AccountSecurityClipLimitUnit option) =
|
|
let allOption = { product = {
|
|
exchange = bts.api.Venue.UNSET
|
|
``type`` = bts.api.SecurityType.UNSET
|
|
symbol = model.AllValueDisplay
|
|
};
|
|
names = (JSMap.add<string> "0" model.AllValueDisplay JSMap.empty<string>)
|
|
}:ExpirationNameList
|
|
|
|
Array.concat [ [| allOption |]; model.mdRelayExpNameData]
|
|
|> (limitFilter positionLimit clipLimit model.AllValueDisplay)
|
|
|> Seq.map (fun x -> x.names ) |> JSMap.concat
|
|
|
|
|
|
|
|
let clipLimitsView model dispatch =
|
|
let headerRow:TableControl.row =
|
|
{
|
|
cells =
|
|
[
|
|
TableControl.Cell (str "")
|
|
TableControl.controlCell (Fields.checkbox "" ""
|
|
(model.SelectedClipLimits.Length = model.scratch.securityClipLimits.limit.Length)
|
|
[]
|
|
(fun chckd -> ((chckd, model.scratch.securityClipLimits.limit) |> SelectClipLimit |> dispatch)))
|
|
TableControl.Cell (str "Exchange")
|
|
TableControl.Cell (str "Security Type")
|
|
TableControl.Cell (str "Symbol")
|
|
//TableControl.Cell (str "Security")
|
|
TableControl.Cell (str "Clip Size")
|
|
]
|
|
className = ""
|
|
header = None
|
|
onClick = None
|
|
}
|
|
let footerRow:TableControl.row =
|
|
{
|
|
cells =
|
|
[
|
|
{ content = span [Class "nbsp"] [str "Apply to Selected Rows:"]
|
|
className = "has-text-right"
|
|
isHeader = false
|
|
colSpan = 5
|
|
}
|
|
TableControl.Cell (Fields.text
|
|
""
|
|
(sprintf "%i" (match (List.tryHead model.SelectedClipLimits) with
|
|
| Some r -> r.clipSize
|
|
| None -> 0u
|
|
))
|
|
[ ]
|
|
((fun value -> (value, (Array.ofList model.SelectedClipLimits))) >> ChangeMultipleClipLimits >> dispatch)
|
|
)
|
|
]
|
|
className = match (model.SelectedClipLimits.Length > 0) with
|
|
| true -> ""
|
|
| false -> "is-hidden-touch is-hidden-desktop"
|
|
header = None
|
|
onClick = None
|
|
}
|
|
|
|
let changeVenue (oldRow:AccountSecurityClipLimitUnit) (value:string) =
|
|
let venueValue = EnumUtils.fromHuman<bts.api.Venue> venues value
|
|
{ oldRow with security = { oldRow.security with exchange = venueValue } }
|
|
|
|
let changeType (oldRow:AccountSecurityClipLimitUnit) (value:string) =
|
|
let typeValue = EnumUtils.fromHuman<bts.api.SecurityType> securityTypes value
|
|
{ oldRow with security = { oldRow.security with securityType = typeValue } }
|
|
|
|
let changeSymbol (oldRow:AccountSecurityClipLimitUnit) (value:string) =
|
|
let v = match (value = model.AllValueDisplay) with
|
|
| false -> value
|
|
| true -> model.AllValue
|
|
{ oldRow with security = { oldRow.security with securitySymbol = v } }
|
|
|
|
let changeSecurityId (oldRow:AccountSecurityClipLimitUnit) (value:string) =
|
|
{ oldRow with security = { oldRow.security with securityId = (uint32 value) } }
|
|
|
|
let changeClipSize (oldRow:AccountSecurityClipLimitUnit) (value:string) =
|
|
{ oldRow with clipSize = (uint32 value) }
|
|
|
|
let limitIsDuplicate exchange secType symbol (limits:AccountSecurityClipLimitUnit []) =
|
|
Array.exists<AccountSecurityClipLimitUnit>
|
|
(fun elem -> (
|
|
elem.security.exchange = exchange &&
|
|
elem.security.securityType = secType &&
|
|
elem.security.securitySymbol = symbol
|
|
)
|
|
)
|
|
limits
|
|
|
|
let isSelected limit =
|
|
List.exists (fun (elm:AccountSecurityClipLimitUnit) -> State.ClipLimitIsEqual elm limit) model.SelectedClipLimits
|
|
|
|
let usedSymbolNames = (Array.map (fun (elm:AccountSecurityClipLimitUnit) -> elm.security.securitySymbol) model.scratch.securityClipLimits.limit)
|
|
|
|
let getUsedSymbolNames (limit: AccountSecurityClipLimitUnit) =
|
|
Array.filter (fun (elm:AccountSecurityClipLimitUnit) -> (
|
|
elm.security.exchange = limit.security.exchange)
|
|
&& (elm.security.securityType = limit.security.securityType)
|
|
)
|
|
model.scratch.securityClipLimits.limit
|
|
|> Array.map (fun (elm:AccountSecurityClipLimitUnit) ->
|
|
match (elm.security.securitySymbol = model.AllValue) with
|
|
| true -> model.AllValueDisplay
|
|
| false -> elm.security.securitySymbol
|
|
)
|
|
|
|
|
|
|
|
|
|
let rws:TableControl.row list =
|
|
[ for limit in model.scratch.securityClipLimits.limit do yield {
|
|
cells =
|
|
[
|
|
TableControl.controlCell (Button.deleteButton Button.Enabled (fun _ -> (Array.findIndex (fun l -> limit = l) model.scratch.securityClipLimits.limit) |> DeleteClipLimit |> dispatch))
|
|
TableControl.controlCell (Fields.checkbox "" ""
|
|
(List.exists (fun (elm:AccountSecurityClipLimitUnit) -> State.ClipLimitIsEqual elm limit) model.SelectedClipLimits)
|
|
[]
|
|
(fun chckd -> ((chckd, [|limit|]) |> SelectClipLimit |> dispatch)))
|
|
TableControl.Cell (Fields.enumSelect<string>
|
|
""
|
|
(EnumUtils.toHuman<bts.api.Venue> false venues limit.security.exchange)
|
|
(EnumUtils.allToHuman<bts.api.Venue> false venues)
|
|
[Class ""]
|
|
(fun value -> ((limit, (changeVenue limit value)) |> ClipLimits |> dispatch))
|
|
)
|
|
TableControl.Cell (Fields.enumSelect<string>
|
|
""
|
|
(EnumUtils.toHuman<bts.api.SecurityType> false securityTypes limit.security.securityType)
|
|
(EnumUtils.allToHuman<bts.api.SecurityType> false (Array.filter (fun a -> a <> bts.api.SecurityType.SYNTHETIC) securityTypes))
|
|
[]
|
|
(fun value -> ((limit, (changeType limit value)) |> ClipLimits |> dispatch))
|
|
)
|
|
TableControl.Cell (Fields.enumSelect<string>
|
|
""
|
|
(match (limit.security.securitySymbol = model.AllValue) with | true -> model.AllValueDisplay | false -> limit.security.securitySymbol)
|
|
(GetFilteredSymbolArray model <| (getUsedSymbolNames limit))
|
|
[]
|
|
(fun value -> ((limit, (changeSymbol limit value)) |> ClipLimits |> dispatch))
|
|
)
|
|
(*TableControl.Cell (Fields.mapSelect
|
|
""
|
|
(JSMap.toMap (getSecurityMap model None (Some limit)))
|
|
None
|
|
(Some (sprintf "%i" limit.security.securityId))
|
|
((changeSecurityId limit) >> ClipLimits >> dispatch)
|
|
)*)
|
|
TableControl.Cell (Fields.text
|
|
""
|
|
(sprintf "%i" limit.clipSize)
|
|
[ ]
|
|
(fun value -> ((limit, (changeClipSize limit value)) |> ClipLimits |> dispatch))
|
|
)
|
|
]
|
|
className = match (isSelected limit) with
|
|
| false -> ""
|
|
| true -> "is-selected"
|
|
header = None
|
|
onClick = None
|
|
}
|
|
yield footerRow
|
|
]
|
|
|
|
let tempSec = { SecurityScope.empty with securitySymbol =
|
|
match GetFilteredSymbolArray model usedSymbolNames |> Array.tryHead with
|
|
| None -> ""
|
|
| Some "All" -> "*"
|
|
| Some h -> h
|
|
}
|
|
|
|
let emptyLimit = {
|
|
security = tempSec
|
|
clipSize = 0u
|
|
}
|
|
|
|
let addRow _ = emptyLimit |> AddClipLimit |> dispatch
|
|
div []
|
|
[
|
|
div [ ClassName "columns" ][
|
|
h1 [ ClassName "is-size-3 column is-narrow" ][str "Clip Limits" ]
|
|
div [ ClassName "column is-size-7 has-text-grey-mid is-help-text"; ]
|
|
[str "Clip limits can be set for one security, for all securities in a product (by selecting \"All\" for securities), or for all products within a security type (by selecting \"All\" for both symbol and security)"]
|
|
]
|
|
TableControl.createDataTable (Some headerRow) rws (Button.button "Add" "" "plus-circle" Button.Enabled addRow)
|
|
]
|
|
|
|
let lazyClipLimitsView model dispatch =
|
|
lazyView2With (fun a b ->
|
|
LanguagePrimitives.PhysicalEquality a.SelectedClipLimits b.SelectedClipLimits &&
|
|
LanguagePrimitives.PhysicalEquality a.scratch.securityClipLimits b.scratch.securityClipLimits)
|
|
clipLimitsView
|
|
model dispatch
|
|
|
|
let productLimits model dispatch =
|
|
let headerRow:TableControl.row =
|
|
{
|
|
cells =
|
|
[
|
|
TableControl.Cell (str "")
|
|
TableControl.controlCell (Fields.checkbox "" ""
|
|
(model.SelectedPositionLimits.Length = model.scratch.productPositionLimits.Length)
|
|
[]
|
|
(fun chckd -> ((chckd, model.scratch.productPositionLimits) |> SelectProductLimit |> dispatch)))
|
|
TableControl.Cell (str "Exchange")
|
|
TableControl.Cell (str "Security Type")
|
|
TableControl.Cell (str "Symbol")
|
|
TableControl.Cell (str "Max Long Position")
|
|
TableControl.Cell (str "Max Short Position")
|
|
]
|
|
className = ""
|
|
header = None
|
|
onClick = None
|
|
}
|
|
|
|
let footerRow:TableControl.row =
|
|
{
|
|
cells =
|
|
[
|
|
{ content = span [Class "nbsp"] [str "Apply to Selected Rows:"]
|
|
className = "has-text-right"
|
|
isHeader = false
|
|
colSpan = 5
|
|
}
|
|
TableControl.Cell (Fields.text
|
|
""
|
|
(sprintf "%i" (match (List.tryHead model.SelectedPositionLimits) with
|
|
| Some r -> r.longPositionLimit
|
|
| None -> 0u
|
|
))
|
|
[ ]
|
|
((fun value -> ("long", value, (Array.ofList model.SelectedPositionLimits))) >> ChangeMultipleProductLimits >> dispatch)
|
|
)
|
|
TableControl.Cell (Fields.text
|
|
""
|
|
(sprintf "%i" (match (List.tryHead model.SelectedPositionLimits) with
|
|
| Some r -> r.shortPositionLimit
|
|
| None -> 0u
|
|
))
|
|
[ ]
|
|
((fun value -> ("short", value, (Array.ofList model.SelectedPositionLimits))) >> ChangeMultipleProductLimits >> dispatch)
|
|
)
|
|
]
|
|
className = match (model.SelectedPositionLimits.Length > 0) with
|
|
| true -> ""
|
|
| false -> "is-hidden-touch is-hidden-desktop"
|
|
header = None
|
|
onClick = None
|
|
}
|
|
|
|
let changeVenue (oldRow:AccountProductPositionLimitUnit) (value:string) =
|
|
let venueValue = EnumUtils.fromHuman<bts.api.Venue> venues value
|
|
{ oldRow with product = { oldRow.product with exchange = venueValue } }
|
|
|
|
|
|
let changeType (oldRow:AccountProductPositionLimitUnit) (value:string) =
|
|
let typeValue = EnumUtils.fromHuman<bts.api.SecurityType> securityTypes value
|
|
{ oldRow with product = { oldRow.product with securityType = typeValue } }
|
|
|
|
|
|
let changeSymbol (oldRow:AccountProductPositionLimitUnit) (value:string) =
|
|
let v = match (value = model.AllValueDisplay) with
|
|
| false -> value
|
|
| true -> model.AllValue
|
|
{ oldRow with product = { oldRow.product with securitySymbol = v } }
|
|
|
|
let changeLongPositionLimit (oldRow:AccountProductPositionLimitUnit) (value:string) =
|
|
{ oldRow with longPositionLimit = (uint32 value) }
|
|
|
|
let changeShortPositionLimit (oldRow:AccountProductPositionLimitUnit) (value:string) =
|
|
{ oldRow with shortPositionLimit = (uint32 value) }
|
|
|
|
let limitIsDuplicate exchange secType symbol (limits:AccountProductPositionLimitUnit []) =
|
|
Array.exists<AccountProductPositionLimitUnit>
|
|
(fun elem -> (
|
|
elem.product.exchange = exchange &&
|
|
elem.product.securityType = secType &&
|
|
elem.product.securitySymbol = symbol
|
|
)
|
|
)
|
|
limits
|
|
|
|
let isSelected limit =
|
|
List.exists (fun (elm:AccountProductPositionLimitUnit) -> State.PositionLimitIsEqual elm limit) model.SelectedPositionLimits
|
|
|
|
let usedSymbolNames = (Array.map (fun (elm:AccountProductPositionLimitUnit) -> elm.product.securitySymbol) model.scratch.productPositionLimits)
|
|
|
|
let getUsedSymbolNames (limit: AccountProductPositionLimitUnit) =
|
|
Array.filter (fun (elm:AccountProductPositionLimitUnit) -> (
|
|
elm.product.exchange = limit.product.exchange)
|
|
&& (elm.product.securityType = limit.product.securityType)
|
|
)
|
|
model.scratch.productPositionLimits
|
|
|> Array.map (fun (elm:AccountProductPositionLimitUnit) ->
|
|
match (elm.product.securitySymbol = model.AllValue) with
|
|
| true -> model.AllValueDisplay
|
|
| false -> elm.product.securitySymbol
|
|
)
|
|
|
|
|
|
let rws:TableControl.row list =
|
|
[ for limit in model.scratch.productPositionLimits do yield {
|
|
cells =
|
|
[
|
|
TableControl.Cell (Button.deleteButton Button.Enabled (fun _ -> (Array.findIndex (fun l -> limit = l) model.scratch.productPositionLimits) |> DeleteProductLimit |> dispatch))
|
|
TableControl.controlCell (Fields.checkbox "" ""
|
|
(List.exists (fun (elm:AccountProductPositionLimitUnit) -> State.PositionLimitIsEqual elm limit) model.SelectedPositionLimits)
|
|
[]
|
|
(fun chckd -> ((chckd, [|limit|]) |> SelectProductLimit |> dispatch)))
|
|
TableControl.Cell (Fields.enumSelect<string>
|
|
""
|
|
(EnumUtils.toHuman<bts.api.Venue> false venues limit.product.exchange)
|
|
(EnumUtils.allToHuman<bts.api.Venue> false venues)
|
|
[]
|
|
(fun value -> ((limit, (changeVenue limit value)) |> ProductLimits |> dispatch))
|
|
)
|
|
TableControl.Cell (Fields.enumSelect<string>
|
|
""
|
|
(EnumUtils.toHuman<bts.api.SecurityType> false securityTypes limit.product.securityType)
|
|
(EnumUtils.allToHuman<bts.api.SecurityType> false (Array.filter (fun a -> a <> bts.api.SecurityType.SYNTHETIC) securityTypes))
|
|
[]
|
|
(fun value -> ((limit, (changeType limit value)) |> ProductLimits |> dispatch))
|
|
)
|
|
TableControl.Cell (Fields.enumSelect<string>
|
|
""
|
|
(match (limit.product.securitySymbol = model.AllValue) with | true -> model.AllValueDisplay | false -> limit.product.securitySymbol)
|
|
(GetFilteredSymbolArray model (getUsedSymbolNames limit))
|
|
[]
|
|
(fun value -> ((limit, (changeSymbol limit value)) |> ProductLimits |> dispatch))
|
|
)
|
|
TableControl.Cell (Fields.text
|
|
""
|
|
(sprintf "%i" limit.longPositionLimit)
|
|
[ ]
|
|
(fun value -> ((limit, (changeLongPositionLimit limit value)) |> ProductLimits |> dispatch))
|
|
)
|
|
TableControl.Cell (Fields.text
|
|
""
|
|
(sprintf "%i" limit.shortPositionLimit)
|
|
[ ]
|
|
(fun value -> ((limit, (changeShortPositionLimit limit value)) |> ProductLimits |> dispatch))
|
|
)
|
|
]
|
|
className = match (isSelected limit) with
|
|
| false -> ""
|
|
| true -> "is-selected"
|
|
header = None
|
|
onClick = None
|
|
}
|
|
] @ [footerRow]
|
|
|
|
let tempSec = match GetFilteredSymbolArray model usedSymbolNames |> Array.tryHead with
|
|
| None -> ""
|
|
| Some "All" -> "*"
|
|
| Some h -> h
|
|
|
|
|
|
let emptyLimit = {
|
|
product = {
|
|
exchange = bts.api.Venue.GLBX
|
|
securityType = bts.api.SecurityType.FUTURE
|
|
securitySymbol = tempSec
|
|
}
|
|
longPositionLimit = 0u
|
|
shortPositionLimit = 0u
|
|
netPositionLimit = 0u
|
|
}
|
|
|
|
let addRow _ = emptyLimit |> AddProductLimit |> dispatch
|
|
div []
|
|
[
|
|
div [ ClassName "columns" ][
|
|
h1 [ ClassName "is-size-3 column is-narrow" ][str "Position Limits" ]
|
|
div [ ClassName "column is-size-7 has-text-grey-mid is-help-text" ]
|
|
[str "This limits the net position for a product (i.e. accumulated position over all securities belonging to a product). This can be set for one product, or for all products within a security type by selecting \"All\" for symbol. (Note that \"All\" applies the same limits to each symbol, not the combiled position of all symbols)"]
|
|
]
|
|
div [][
|
|
Fields.radioButton "Use Net Contracts" "" model.scratch.riskLimitEnforcement.productLimitInNetTerms [] (EnforceProductLimitInNetTerms >> dispatch)
|
|
Fields.radioButton "Use Absolute Contracts" "" (not model.scratch.riskLimitEnforcement.productLimitInNetTerms) [] (not >> EnforceProductLimitInNetTerms >> dispatch)
|
|
]
|
|
TableControl.createDataTable (Some headerRow) rws (Button.button "Add" "" "plus-circle" Button.Enabled addRow)
|
|
br []
|
|
]
|
|
|
|
let lazyProductLimitsView model dispatch =
|
|
lazyView2With (fun a b ->
|
|
LanguagePrimitives.PhysicalEquality a.SelectedPositionLimits b.SelectedPositionLimits &&
|
|
LanguagePrimitives.PhysicalEquality a.scratch.productPositionLimits b.scratch.productPositionLimits &&
|
|
a.scratch.riskLimitEnforcement = b.scratch.riskLimitEnforcement)
|
|
productLimits
|
|
model dispatch
|
|
|
|
let lossLimitView (model:Model) dispatch =
|
|
div [] [
|
|
div [ ClassName "columns" ][
|
|
h1 [ ClassName "is-size-3 column is-narrow" ][str "Loss Limit" ]
|
|
div [ ClassName "column is-size-7 has-text-grey-mid is-help-text" ]
|
|
[str "If Enabled, this limits the account's loss."]
|
|
]
|
|
div [][
|
|
Fields.checkbox "Enable Loss Limit" "" model.scratch.accountLossLimit.enforce [] (EnforceLossLimit >> dispatch)
|
|
Fields.inlineText "Total Loss Limit" (string model.scratch.accountLossLimit.totalLossLimit) [] (not model.scratch.accountLossLimit.enforce) (TotalLossLimit >> dispatch)
|
|
]
|
|
]
|
|
|
|
let securityLimitsView (model:Model) dispatch =
|
|
let headerRow:TableControl.row =
|
|
{
|
|
cells =
|
|
[
|
|
TableControl.Cell (str "")
|
|
TableControl.Cell (str "Exchange")
|
|
TableControl.Cell (str "Security Type")
|
|
TableControl.Cell (str "Symbol")
|
|
TableControl.Cell (str "Security")
|
|
TableControl.Cell (str "Max Long Position")
|
|
TableControl.Cell (str "Max Short Position")
|
|
]
|
|
className = ""
|
|
header = None
|
|
onClick = None
|
|
}
|
|
|
|
let modifyRow (oldRow:AccountSecurityPositionLimitUnit) (newRow:AccountSecurityPositionLimitUnit) =
|
|
let i = Array.findIndex (fun l -> oldRow = l) model.scratch.securityPositionLimits
|
|
let left = Array.append (model.scratch.securityPositionLimits.[..i-1]) [| newRow |]
|
|
let right = model.scratch.securityPositionLimits.[1+i..]
|
|
Array.concat [left; right]
|
|
|
|
let changeVenue (oldRow:AccountSecurityPositionLimitUnit) (value:string) =
|
|
let venueValue = EnumUtils.fromHuman<bts.api.Venue> venues value
|
|
let newRow = { oldRow with security = { oldRow.security with exchange = venueValue } }
|
|
modifyRow oldRow newRow
|
|
|
|
let changeType (oldRow:AccountSecurityPositionLimitUnit) (value:string) =
|
|
let typeValue = EnumUtils.fromHuman<bts.api.SecurityType> securityTypes value
|
|
let newRow = { oldRow with security = { oldRow.security with securityType = typeValue } }
|
|
modifyRow oldRow newRow
|
|
|
|
let changeSymbol (oldRow:AccountSecurityPositionLimitUnit) (value:string) =
|
|
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:AccountSecurityPositionLimitUnit) (value:string) =
|
|
modifyRow oldRow { oldRow with security = { oldRow.security with securityId = (uint32 value) } }
|
|
|
|
let changeLongPositionLimit (oldRow:AccountSecurityPositionLimitUnit) (value:string) =
|
|
modifyRow oldRow { oldRow with longPositionLimit = (uint32 value) }
|
|
|
|
let changeShortPositionLimit (oldRow:AccountSecurityPositionLimitUnit) (value:string) =
|
|
modifyRow oldRow { oldRow with shortPositionLimit = (uint32 value) }
|
|
|
|
let rws:TableControl.row list =
|
|
[ for limit in model.scratch.securityPositionLimits do yield {
|
|
cells =
|
|
[
|
|
TableControl.Cell (Button.deleteButton Button.Enabled (fun _ -> (Array.findIndex (fun l -> limit = l) model.scratch.securityPositionLimits) |> DeleteSecurityLimit |> dispatch))
|
|
TableControl.Cell (Fields.enumSelect<string>
|
|
""
|
|
(EnumUtils.toHuman<bts.api.Venue> false venues limit.security.exchange)
|
|
(EnumUtils.allToHuman<bts.api.Venue> false venues)
|
|
[]
|
|
((changeVenue limit) >> SecurityLimits >> dispatch)
|
|
)
|
|
TableControl.Cell (Fields.enumSelect<string>
|
|
""
|
|
(EnumUtils.toHuman<bts.api.SecurityType> false securityTypes limit.security.securityType)
|
|
(EnumUtils.allToHuman<bts.api.SecurityType> false (Array.filter (fun a -> a <> bts.api.SecurityType.SYNTHETIC) securityTypes))
|
|
[]
|
|
((changeType limit) >> SecurityLimits >> dispatch)
|
|
)
|
|
TableControl.Cell (Fields.enumSelect<string>
|
|
""
|
|
limit.security.securitySymbol
|
|
(GetSymbolArray model)
|
|
[]
|
|
((changeSymbol limit) >> SecurityLimits >> dispatch)
|
|
)
|
|
TableControl.Cell (Fields.mapSelect
|
|
""
|
|
(JSMap.toMap (getSecurityMap model (Some limit) None))
|
|
None
|
|
(Some (sprintf "%i" limit.security.securityId))
|
|
((changeSecurityId limit) >> SecurityLimits >> dispatch)
|
|
)
|
|
TableControl.Cell (Fields.text
|
|
""
|
|
(sprintf "%i" limit.longPositionLimit)
|
|
[ ]
|
|
((changeLongPositionLimit limit) >> SecurityLimits >> dispatch)
|
|
)
|
|
TableControl.Cell (Fields.text
|
|
""
|
|
(sprintf "%i" limit.shortPositionLimit)
|
|
[ ]
|
|
((changeShortPositionLimit limit) >> SecurityLimits >> dispatch)
|
|
)
|
|
]
|
|
className = ""
|
|
header = None
|
|
onClick = None
|
|
}
|
|
]
|
|
let emptyLimit = {
|
|
security = { SecurityScope.empty with securitySymbol = model.AllValue }
|
|
longPositionLimit = 0u
|
|
shortPositionLimit = 0u
|
|
netPositionLimit = 0u
|
|
}
|
|
|
|
let addRow _ = Array.append model.scratch.securityPositionLimits [| emptyLimit |] |> (SecurityLimits >> dispatch)
|
|
div []
|
|
[
|
|
div [ ClassName "columns" ][
|
|
h1 [ ClassName "is-size-3 column is-narrow" ][str "Security Limits" ]
|
|
div [ ClassName "column is-size-7 has-text-grey-mid is-help-text" ]
|
|
[str "Optionally, the net position for one or more securities can also be limited. For example, the Product Limits can be set to restrict the Max Net Long Position across all ES futures to 10,000 contracts, but Security Limits can be used to restrict the ES Jun future to 500 only"]
|
|
]
|
|
TableControl.createDataTable (Some headerRow) rws (Button.button "Add" "" "plus-circle" Button.Enabled addRow)
|
|
]
|
|
|
|
let LimitsView (model:Model) dispatch =
|
|
div [ Class "limits-container"] [
|
|
lossLimitView model dispatch
|
|
br []
|
|
lazyClipLimitsView model dispatch
|
|
lazyProductLimitsView model dispatch
|
|
//securityLimitsView model dispatch
|
|
|
|
accountControls model dispatch
|
|
]
|
|
|
|
let venueToString (venue:bts.api.Venue) =
|
|
match venue with
|
|
| bts.api.Venue.UNSET -> "Unset"
|
|
| bts.api.Venue.BTS -> "BTS"
|
|
| bts.api.Venue.SIM -> "SIM"
|
|
| bts.api.Venue.CBOE -> "CBOE"
|
|
| bts.api.Venue.CBOECFE -> "CBOECFE"
|
|
| bts.api.Venue.GLBX -> "GLBX"
|
|
| bts.api.Venue.ICE -> "ICE"
|
|
|
|
let exchange_display expirationNameList =
|
|
let s = sprintf "%O" expirationNameList.product.exchange
|
|
s.[6..s.Length]
|
|
|
|
let getVenueList model =
|
|
(Array.toList model.mdRelayExpNameData)
|
|
|> List.map (exchange_display)
|
|
|> List.distinct
|
|
|
|
let getSymbolList model venue =
|
|
(Array.toList model.mdRelayExpNameData)
|
|
|> List.filter (fun (i:ExpirationNameList) -> exchange_display i = venue)
|
|
|> List.map (fun (i:ExpirationNameList) -> sprintf "%O" i.product.symbol)
|
|
|> List.distinct
|
|
|
|
let getPositionSecMap (sList:(uint32 * PositionSecurity) list) venue symbol =
|
|
sList
|
|
|> List.filter (fun i ->
|
|
(venueToString (snd i).venue = venue) &&
|
|
(snd i).symbol = symbol
|
|
)
|
|
|> List.map (fun i -> (sprintf "%O" (fst i)), (snd i).securityName)
|
|
|> List.distinct
|
|
|> Map.ofList
|
|
|
|
|
|
let SODPositionView model dispatch =
|
|
div []
|
|
[
|
|
div [ ClassName "columns" ][
|
|
h1 [ ClassName "is-size-3 column is-narrow" ][str "SOD" ]
|
|
div [ ClassName "column is-size-7 has-text-grey-mid is-help-text"; ]
|
|
[str "Manually add fills for the Start of Day position"]
|
|
]
|
|
]
|
|
|
|
let DayPositionView model dispatch =
|
|
let headerRow:TableControl.row =
|
|
{
|
|
cells =
|
|
[
|
|
TableControl.controlCell (str "")
|
|
TableControl.Cell (str "ID")
|
|
TableControl.Cell (str "Exchange")
|
|
TableControl.Cell (str "Symbol")
|
|
TableControl.Cell (str "Security")
|
|
TableControl.Cell (str "User")
|
|
TableControl.Cell (str "Side")
|
|
{ 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 = ""
|
|
header = None
|
|
onClick = None
|
|
}
|
|
|
|
let usersMap =
|
|
match model.adminData with
|
|
| Some ad -> List.map (fun (i:BTSUser) -> i.name) (List.ofArray ad.users)
|
|
| None -> List.Empty
|
|
|
|
let securityList:(uint32 * PositionSecurity) list =
|
|
model.mdRelayExpNameData
|
|
|> List.ofArray
|
|
|> List.filter (fun i -> i.product.``type`` = bts.api.SecurityType.FUTURE)
|
|
|> List.collect (fun i ->
|
|
JSMap.toList i.names
|
|
|> List.map (fun x ->
|
|
(uint32 <| fst x),
|
|
({ securityName = (snd x)
|
|
venue = i.product.exchange
|
|
symbol = i.product.symbol
|
|
}: PositionSecurity)
|
|
)
|
|
)
|
|
|
|
|
|
let securityMap = securityList |> Map.ofList
|
|
|
|
let venueList = (getVenueList model)
|
|
|
|
let extantUsersMap =
|
|
usersMap |> List.filter (fun (u:string) -> u.[..6] <> "DELETED")
|
|
|
|
let disableAdd =
|
|
model.ManualFillData.tempDayFillData.qty = "" ||
|
|
model.ManualFillData.tempDayFillData.price = "" ||
|
|
model.ManualFillData.tempDayFillData.side = "" ||
|
|
model.ManualFillData.tempDayFillData.user = "" ||
|
|
model.ManualFillData.tempDayFillData.SecurityId = ""
|
|
|
|
let footerRow:TableControl.row =
|
|
{
|
|
cells =
|
|
[
|
|
{ content = span [Class "nbsp"; Style [FontWeight "bold"]] [str "Add Trade:"]
|
|
className = ""
|
|
isHeader = false
|
|
colSpan = 2
|
|
}
|
|
TableControl.Cell (Fields.simpleSelect "" venueList model.ManualFillData.tempDayFillData.venue ((fun v -> (v, "venue", false)) >> UpdateTempManualFill >> dispatch))
|
|
TableControl.Cell (Fields.simpleSelect "" (getSymbolList model model.ManualFillData.tempDayFillData.venue) model.ManualFillData.tempDayFillData.symbol ((fun v -> (v, "symbol", false)) >> UpdateTempManualFill >> dispatch))
|
|
TableControl.Cell (
|
|
Fields.mapSelect
|
|
""
|
|
(getPositionSecMap securityList model.ManualFillData.tempDayFillData.venue model.ManualFillData.tempDayFillData.symbol)
|
|
(
|
|
match model.ManualFillData.tempDayFillData.SecurityId, (Map.exists (fun (x:uint32) y -> string x = model.ManualFillData.tempDayFillData.SecurityId) securityMap) with
|
|
| "", _ -> None
|
|
| _, false -> None
|
|
| _, true -> Some securityMap.[uint32 model.ManualFillData.tempDayFillData.SecurityId].securityName
|
|
)
|
|
(Some model.ManualFillData.tempDayFillData.SecurityId)
|
|
((fun v -> (v, "SecurityId", false)) >> UpdateTempManualFill >> 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.positiveIntNumber
|
|
""
|
|
(model.ManualFillData.tempDayFillData.qty)
|
|
[ ]
|
|
((fun v -> (v, "qty", false)) >> UpdateTempManualFill >> dispatch)
|
|
)
|
|
TableControl.Cell (Fields.number
|
|
""
|
|
(model.ManualFillData.tempDayFillData.price)
|
|
[ ]
|
|
(fun _ -> true)
|
|
((fun v -> (v, "price", false)) >> UpdateTempManualFill >> dispatch)
|
|
)
|
|
TableControl.Cell (Button.addButton (Button.boolToDisabledConverter disableAdd) (fun _ -> AddManualFill <| false |> dispatch))
|
|
]
|
|
className = ""
|
|
header = None
|
|
onClick = None
|
|
}
|
|
|
|
let filtered = Array.filter (fun (i:bts.api.position.ManualFill) -> i.fillType = bts.api.position.ManualFill.FillType.AdminDay && i.accountId = model.scratch.id) model.ManualFillData.fills.manualFill
|
|
|
|
let fillRows:TableControl.row list =
|
|
[ for limit in filtered do
|
|
match (List.tryFind (fun (l:TempFillData) -> l.id = uint32 limit.recordId) model.ManualFillData.updatedFills),
|
|
(Array.tryFind (fun (l:bts.api.position.ManualFill) -> l.recordId = limit.recordId) model.ManualFillData.deletedFills.manualFill),
|
|
(securityMap |> Map.exists (fun i q -> i = limit.securityKey)) with
|
|
| _, _, false ->
|
|
yield {
|
|
cells = []
|
|
className = ""
|
|
header = None
|
|
onClick = None
|
|
}
|
|
| _, Some _, _ ->
|
|
yield {
|
|
cells = []
|
|
className = ""
|
|
header = None
|
|
onClick = None
|
|
}
|
|
| Some ulimit, None, _ ->
|
|
yield {
|
|
cells =
|
|
[
|
|
TableControl.Cell (Button.deleteButton Button.IsDisabled.Enabled (fun _ -> ((ulimit.id |> int), false)|> RemoveManualFill |> dispatch))
|
|
TableControl.Cell (span [Style [Color "green"]][str (sprintf "%i" ulimit.id)])
|
|
TableControl.Cell (Fields.simpleSelect "" venueList (ulimit.venue) (fun v -> (ulimit.id, v, "venue", false) |> UpdateManualFill |> dispatch))
|
|
TableControl.Cell (Fields.simpleSelect "" (getSymbolList model ulimit.venue) (ulimit.symbol) (fun v -> (ulimit.id, v, "symbol", false) |> UpdateManualFill |> dispatch))
|
|
TableControl.Cell (Fields.mapSelect
|
|
""
|
|
(getPositionSecMap
|
|
securityList
|
|
(ulimit.venue)
|
|
(ulimit.symbol)
|
|
)
|
|
(Some securityMap.[uint32 ulimit.SecurityId].securityName)
|
|
(Some ulimit.SecurityId)
|
|
(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.positiveIntNumber
|
|
""
|
|
ulimit.qty
|
|
[ ]
|
|
(fun v -> (ulimit.id, v, "qty", false) |> UpdateManualFill |> dispatch)
|
|
)
|
|
TableControl.Cell (Fields.number
|
|
""
|
|
ulimit.price
|
|
[ ]
|
|
(fun _ -> true)
|
|
(fun v -> (ulimit.id, v, "price", false) |> UpdateManualFill |> dispatch)
|
|
)
|
|
TableControl.Cell (str "")
|
|
]
|
|
className = ""
|
|
header = None
|
|
onClick = None
|
|
}
|
|
| None, None, _ ->
|
|
yield {
|
|
cells =
|
|
[
|
|
TableControl.Cell (Button.deleteButton Button.IsDisabled.Enabled (fun _ -> ((limit.recordId |> int), false) |> RemoveManualFill |> dispatch))
|
|
TableControl.Cell (str (sprintf "%i" limit.recordId))
|
|
TableControl.Cell (str (venueToString securityMap.[limit.securityKey].venue))
|
|
TableControl.Cell (str securityMap.[limit.securityKey].symbol)
|
|
TableControl.Cell (str securityMap.[limit.securityKey].securityName)
|
|
TableControl.Cell (str (idToUser limit.userId model))
|
|
TableControl.Cell (str (match limit.side with | bts.api.Side.BUY -> "Buy" | bts.api.Side.SELL -> "Sell" | _ -> ""))
|
|
TableControl.Cell (str (sprintf "%i" limit.quantity))
|
|
TableControl.Cell (str (sprintf "%f" limit.price))
|
|
TableControl.Cell (str "")
|
|
]
|
|
className = ""
|
|
header = None
|
|
onClick = Some (fun _ -> (uint32 limit.recordId, (venueToString securityMap.[limit.securityKey].venue), securityMap.[limit.securityKey].symbol) |> CreateManualFillUpdate |> dispatch)
|
|
}
|
|
|
|
]
|
|
let newRows:TableControl.row list =
|
|
[ for limit in (List.filter (fun (i:TempFillData) -> i.fillType = bts.api.position.ManualFill.FillType.AdminDay) model.ManualFillData.newFills) do yield {
|
|
cells =
|
|
[
|
|
TableControl.Cell (Button.deleteButton Button.IsDisabled.Enabled (fun _ -> ((limit.newId |> int), true) |> RemoveManualFill |> dispatch))
|
|
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
|
|
""
|
|
(getPositionSecMap
|
|
securityList
|
|
(limit.venue)
|
|
(limit.symbol)
|
|
)
|
|
(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.positiveIntNumber
|
|
""
|
|
limit.qty
|
|
[ ]
|
|
(fun v -> (limit.newId, v, "qty", true) |> UpdateManualFill |> dispatch)
|
|
)
|
|
TableControl.Cell (Fields.number
|
|
""
|
|
limit.price
|
|
[ ]
|
|
(fun _ -> true)
|
|
(fun v -> (limit.newId, v, "price", true) |> UpdateManualFill |> dispatch)
|
|
)
|
|
TableControl.Cell (str "")
|
|
]
|
|
className = ""
|
|
header = None
|
|
onClick = None
|
|
}]
|
|
|
|
let rws:TableControl.row list = fillRows @ newRows
|
|
|
|
div []
|
|
[
|
|
div [ ClassName "columns" ][
|
|
h1 [ ClassName "is-size-3 column is-narrow" ][str "Day" ]
|
|
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 "" [MinWidth 824] (
|
|
Button.fabutton "Add" "plus" "" (Button.boolToDisabledConverter false) (fun _ -> AddManualFill <| false |> dispatch)
|
|
)
|
|
|
|
]
|
|
|
|
let PositionUploadView model dispatch =
|
|
div []
|
|
[
|
|
div [ ClassName "columns" ][
|
|
h1 [ ClassName "is-size-3 column is-narrow" ][str "Upload" ]
|
|
div [ ClassName "column is-size-7 has-text-grey-mid is-help-text"; ]
|
|
[str "Add fills from a file for the Day position"]
|
|
]
|
|
Fields.fileUpload false (fun f -> (ParseCSV (FileType.GMI, f)) |> dispatch)
|
|
br []
|
|
]
|
|
|
|
|
|
let PositionManagementView model dispatch =
|
|
div [] [
|
|
PositionUploadView model dispatch
|
|
//SODPositionView model dispatch
|
|
DayPositionView model dispatch
|
|
accountControls model dispatch
|
|
]
|
|
|
|
let ConnectionsView (model:Accounts.Types.Model) dispatch =
|
|
let conNames = model.scratch.connections.exchangeConnectionNames
|
|
|
|
let cons = match model.adminData with
|
|
| None -> Array.empty<ExchangeConnection>
|
|
| Some data -> data.connections
|
|
|
|
let conMap =
|
|
cons
|
|
|> Array.map (fun a -> a.id.ToString(), a.name)
|
|
|> Map.ofArray
|
|
|
|
let rows:TableControl.row list =
|
|
[for c in conMap do yield {
|
|
cells = [
|
|
{ content = str c.Value
|
|
className = "is-narrow"
|
|
isHeader = false
|
|
colSpan = 1
|
|
|
|
}
|
|
{ content = (Fields.checkbox "" "" (
|
|
Array.contains c.Value conNames)
|
|
[]
|
|
(fun _ -> (
|
|
let message:Msg = c.Value |> (RemoveConnection)
|
|
match (Array.contains c.Value conNames) with
|
|
| true -> (OpenConfirmModal ((sprintf "Are you sure you want to remove the %s connection from this account?" c.Value), message))
|
|
| false -> (c.Key |> (AddConnection))
|
|
|> dispatch
|
|
)
|
|
)
|
|
);
|
|
className = "";
|
|
isHeader = false;
|
|
colSpan = 0
|
|
}
|
|
]
|
|
className=""
|
|
header = None
|
|
onClick = None
|
|
}
|
|
]
|
|
|
|
let headerRow:TableControl.row = {
|
|
cells =
|
|
[
|
|
TableControl.Cell(str "Connection")
|
|
TableControl.Cell(str "Enabled")
|
|
]
|
|
className = ""
|
|
header = None
|
|
onClick = None
|
|
}
|
|
|
|
div [ ]
|
|
[
|
|
TableControl.createSelectorTable (Some headerRow) rows
|
|
|
|
accountControls model dispatch
|
|
]
|
|
|
|
let creditLimitsView model dispatch = div [] [str "lorem ipsum"]
|
|
|
|
let exchangeSettings (model:Model) dispatch =
|
|
let cme = model.scratch.exchangeAccountData.cmeAccountData
|
|
let sim = model.scratch.exchangeAccountData.simAccountData
|
|
let send = UpdateCME>>dispatch
|
|
let sendSim = UpdateSIM>>dispatch
|
|
div [] [
|
|
h2 [Class "is-size-3"] [ str "CME" ]
|
|
Fields.enumSelect "CTI" (toHuman false CTICode.values cme.cti) (allToHuman false CTICode.values) [] (fromHuman CTICode.values>>CMEExchangeField.CTI>>send)
|
|
Fields.enumSelect "Origin" (toHuman false CustomerOrFirm.values cme.origin) (allToHuman false CustomerOrFirm.values) [] (fromHuman CustomerOrFirm.values>>CMEExchangeField.Origin>>send)
|
|
//Fields.text "Takeup Member Code" cme.takeupMemberCode [] (TakeupMember>>send)
|
|
Fields.text "Clearing Account" cme.clearingAccount [MaxLength 12.0] (CMEExchangeField.ClearingAccount>>send)
|
|
//Fields.text "Direct Electronic Access" cme.directElectronicAccess [] (DirectElectronicAccess>>send)
|
|
//Fields.text "Trading Capacity" cme.tradingCapacity [] (TradingCapacity>>send)
|
|
//Fields.text "Liquidity Provision" cme.liquidityProvision [] (LiquidityProvision>>send)
|
|
//Fields.map "Misc Tag Mapping" cme.miscTags [] (MiscTagMapping>>send)
|
|
h2 [Class "is-size-3"] [ str "SIM" ]
|
|
Fields.enumSelect "CTI" (toHuman false CTICode.values sim.cti) (allToHuman false CTICode.values) [] (fromHuman CTICode.values>>SIMExchangeField.CTI>>sendSim)
|
|
Fields.enumSelect "Origin" (toHuman false CustomerOrFirm.values sim.origin) (allToHuman false CustomerOrFirm.values) [] (fromHuman CustomerOrFirm.values>>SIMExchangeField.Origin>>sendSim)
|
|
Fields.text "Clearing Account" sim.clearingAccount [MaxLength 12.0] (SIMExchangeField.ClearingAccount>>sendSim)
|
|
|
|
accountControls model dispatch
|
|
]
|
|
|
|
let tabContent (model:Model) dispatch =
|
|
div [Key (string model.scratch.id); ClassName "is-tab-content"] [
|
|
// (match model.tab with
|
|
(match model.tab, (accountIsSelected model.scratch Access.Accounts.empty) with
|
|
| _ , false -> p [Style [ Color "Red" ]] [ str "You are not authorized to view this data" ]
|
|
| General, _ -> generalView model dispatch
|
|
| LimitsTab, _ -> LimitsView model dispatch
|
|
| ConnectionsTab, _ -> ConnectionsView model dispatch
|
|
| CreditLimitsTab, _ -> creditLimitsView model dispatch
|
|
| ExchangeSettingsTab, _ -> exchangeSettings model dispatch
|
|
| OrdersTab, _ -> ordersView model dispatch
|
|
| PositionManagementTab, _ -> PositionManagementView model dispatch
|
|
| marginTab, _ -> marginView model dispatch)
|
|
]
|
|
|
|
let isActive account = function
|
|
| Some a when a = account -> "is-active"
|
|
| _ -> ""
|
|
|
|
let isOptionsMenuOpen accountName openName =
|
|
match accountName = openName with
|
|
| true -> "is-active"
|
|
| false -> ""
|
|
|
|
let isActiveItem a b = if a = b then "is-active" else ""
|
|
|
|
let accountsMenu (accounts:BTSAccount[]) selectedAccount dispatch =
|
|
div [ClassName "column is-narrow"] [
|
|
aside [ ClassName "menu box" ] [
|
|
p [ ClassName "menu-label has-text-centered" ] [
|
|
str "Select Account"
|
|
]
|
|
ul [ClassName "menu-list"] [
|
|
for account in accounts do
|
|
yield li [] [
|
|
a [
|
|
ClassName (isActive account selectedAccount)
|
|
OnClick (fun _ -> SelectAccount account |> dispatch) ] [
|
|
str account.name]
|
|
]
|
|
]
|
|
]
|
|
]
|
|
|
|
let accountSelectionGrid (accountList:BTSAccount list) (currentAccount:BTSAccount) (dispatch:Msg->Unit) =
|
|
let activeAccounts =
|
|
accountList |> List.sortBy (fun u -> u.name.ToLower())
|
|
|
|
let headerRow:TableControl.row =
|
|
{
|
|
cells =
|
|
[
|
|
TableControl.Cell (str "Account Name")
|
|
TableControl.Cell (str "Active")
|
|
TableControl.Cell (str "Description")
|
|
]
|
|
className = ""
|
|
header = None
|
|
onClick = None
|
|
}
|
|
let rws:TableControl.row list =
|
|
[ for acc in activeAccounts do yield {
|
|
cells =
|
|
[
|
|
TableControl.Cell (a [ OnClick (fun _ -> (acc |> SelectAccount |> dispatch))][
|
|
str acc.name
|
|
])
|
|
TableControl.Cell (str (sprintf "%b" acc.isActive))
|
|
TableControl.Cell (str acc.description)
|
|
]
|
|
className = ""
|
|
header = None
|
|
onClick = None
|
|
}
|
|
]
|
|
div[][
|
|
TableControl.createSelectorTable (Some headerRow) rws
|
|
]
|
|
|
|
|
|
let menuItem account selectedAccount model dispatch =
|
|
a [ ClassName (isActive account selectedAccount)
|
|
OnClick (fun _ -> SelectAccount account |> dispatch)
|
|
] [
|
|
span [] [ str account.name ]
|
|
(if model.can_create then
|
|
span [ Class "is-pulled-right menu-icon" ]
|
|
[
|
|
div [ Class (sprintf "dropdown %s" (isOptionsMenuOpen account.name model.OptionsMenuOpen)) ]
|
|
[ div [ Class "dropdown-trigger" ]
|
|
[ button [ Class "button"
|
|
AriaHasPopup true
|
|
OnClick (fun _ -> account.name |> OpenOptionsMenu |> dispatch)
|
|
HTMLAttr.Custom ("aria-controls", (sprintf "dropdown-menu-%s" account.name)) ]
|
|
[ span [ Class "icon is-small" ]
|
|
[ i [ Class "fa fa-ellipsis-v"
|
|
HTMLAttr.Custom ("aria-hidden", "true") ][ ]
|
|
]
|
|
]
|
|
]
|
|
div [ Class "dropdown-menu"
|
|
Id (sprintf "dropdown-menu-%s" account.name)
|
|
Role "menu"
|
|
|
|
]
|
|
[ div [ Class "dropdown-content" ]
|
|
[ //hr [ Class "dropdown-divider" ]
|
|
a [ Class "dropdown-item"
|
|
OnClick (fun _ -> dispatch <| DeleteAccount account)
|
|
]
|
|
[ str "Remove" ]
|
|
]
|
|
]
|
|
]
|
|
]
|
|
else span[][])
|
|
]
|
|
|
|
let NavRoot (accounts:BTSAccount[]) selectedAccount model dispatch =
|
|
div [ Class "column is-narrow is-sidebar-menu" ]
|
|
[ aside [ Class "menu" ]
|
|
[ p [ Class "menu-label" ] [
|
|
span [Class "is-size-4"] [str "Accounts"]
|
|
span [ Class "is-pulled-right circle-icon" ]
|
|
(if model.can_create then
|
|
[ Button.fabutton
|
|
"Add Account"
|
|
"plus-circle"
|
|
""
|
|
Button.Enabled
|
|
(fun _ -> dispatch AddAccount) ]
|
|
else [])
|
|
]
|
|
|
|
ul [ Class "menu-list" ]
|
|
[
|
|
for account in accounts do
|
|
yield li [] [ menuItem account selectedAccount model dispatch ]
|
|
]
|
|
]
|
|
]
|
|
|
|
let tabName = function
|
|
| LimitsTab -> "Limits"
|
|
| CreditLimitsTab -> "Credit Limits"
|
|
| ConnectionsTab -> "Connections"
|
|
| ExchangeSettingsTab -> "Exchange Settings"
|
|
| OrdersTab -> "Orders"
|
|
| PositionManagementTab -> "Position Management"
|
|
| MarginTab -> "Margin"
|
|
| other -> string other
|
|
|
|
let tabHeader tab currentTab dispatch =
|
|
li [ ClassName (isActiveItem tab currentTab) ] [
|
|
a [ OnClick (fun _ -> dispatch (SelectTab tab)) ] [ str <| tabName tab ]
|
|
]
|
|
|
|
let root (model:Model) dispatch =
|
|
let modal = match (fst model.ConfirmModal) with
|
|
| "" -> span [] []
|
|
| _ -> Modal.showConfirm (fst model.ConfirmModal) (fun () -> (snd model.ConfirmModal) |> dispatch) (fun _ -> OpenConfirmModal ("", Msg.SelectTab model.tab ) |> dispatch)
|
|
match model.adminData with
|
|
| None -> div[][str "Loading account list..."]
|
|
| Some data ->
|
|
div
|
|
[ Class "columns is-fullheight"
|
|
OnClick (fun _ ->
|
|
match model.OptionsMenuOpen.Length > 0 with
|
|
| true -> "" |> OpenOptionsMenu |> dispatch
|
|
| _ -> ()
|
|
)
|
|
]
|
|
[ NavRoot data.accounts (selectedAccount model) model dispatch
|
|
div [ Class "column is-main-content" ]
|
|
[
|
|
|
|
div [ ClassName "tabs is-boxed" ] [
|
|
ul [] [
|
|
(if (Array.length data.accounts > 0) then (tabHeader General model.tab dispatch) else span [][] )
|
|
(if (Array.length data.accounts > 0) then (tabHeader LimitsTab model.tab dispatch) else span [][] )
|
|
(if (Array.length data.accounts > 0) then (tabHeader ConnectionsTab model.tab dispatch) else span [][] )
|
|
// 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 MarginTab model.tab dispatch) else span [][] )
|
|
]
|
|
]
|
|
tabContent model dispatch
|
|
modal
|
|
]
|
|
] |