diff --git a/CMakeLists.txt b/CMakeLists.txt index 534050f90..a4395bfcf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,7 @@ else () -Wno-missing-braces -Wno-ignored-qualifiers \ --std=c++17 -fdiagnostics-color") set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -DNDEBUG -O3") + set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wno-undef") add_subdirectory(src/server/sparkd) add_subdirectory(src/lib) add_subdirectory(src/web) @@ -51,7 +52,6 @@ else () add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/server COMMAND mkdir -p ${CMAKE_BINARY_DIR}/server COMMAND ln ARGS -sf ${CMAKE_BINARY_DIR}/src/server/sparkd/sparkd ${CMAKE_BINARY_DIR}/server - COMMAND ln ARGS -sf ${CMAKE_BINARY_DIR}/src/server/sparkd/defaults ${CMAKE_BINARY_DIR}/server COMMAND ln ARGS -sf ${CMAKE_BINARY_DIR}/web ${CMAKE_BINARY_DIR}/server COMMAND ln ARGS -sf ${CMAKE_BINARY_DIR}/data_files ${CMAKE_BINARY_DIR}/server COMMAND ln ARGS -sf ${CMAKE_BINARY_DIR}/src/lib/libspark.so ${CMAKE_BINARY_DIR}/server diff --git a/doc/dev/dev_process.md b/doc/dev/dev_process.md new file mode 100644 index 000000000..20e02e94d --- /dev/null +++ b/doc/dev/dev_process.md @@ -0,0 +1,71 @@ +# The BTS Development Process # + +## The Big Picture ## + +Our development work is organized in projects. A project is an effort +to specifiy, develop and validate a related set of additions to our +Spark platform. A project can be assigned to one more developers and a +developer might concurrently be assigned to multiple +projects. Projects typically start out with specification work, +proceed to implementation and finish with validation efforts. At any +given time there will be multiple projects being worked on +concurrently. A project is concluded when the features it implements +are merged into the product and deployed to customers. + +## The Details ## +Typically project ideas come from sales interactions, opposition +research and customer feedback, alltough on occasion development or +operational requirements will also suggest potentially valuable +ideas. Whatever the source of a project idea the final decision of +which projects to pursue is always done by management. Once a project +idea has been selected for implementation the corresponding project +will go through several phases: inception, specification, development +and merge. We detail each of these phases below. + +* Inception. In this phase we create the infrastructure for the +project. Typically this means selecting a team, creating a project +case in Jira (that is a case assigned to the team@bluetradesys.com +Jira user) and possibly creating a new branch for the project. This +phase is mostly mechanical and the responsibility of Pedro. + +* Specification. The specification phase turns a usually vague and +ill-considered idea project idea into a concrete, implementable +specification that attempts to maximize the value/cost ratio of the +project. It is hard to exaggerate the impact of a this phase on the +rest of the project. *Nothing* has more impact on our ability to +quickly deliver value to customers than good specification +work. Specification typically take the form of shared google docs, +using a mix of text and UI mockups to capture both user requirements +and suggested implementation strategies. Taha is responsible for this +phase. + +* Development. Once a specification is complete, a team of developers +will use a project specific branch to implement the +specification. Periodically, typically once a week, progress on the +project is assessed by Pedro, possibly with the help of others. This +assessment takes the form of code reviews, demos, or just one-on-one +conversations. To ensure development does not go off on sub-optimal +tangents, developers are expected to continuously merge master into +the project branch as well as encouraged to create Pull Requests (PRs) +early in the project implementation, so that their work is kept +visible and integrated with that of the rest of the group. During the +implementation phase developers should reach out to Pedro for UI +reviews, architecture and design concerns as well as specification +trade off concerns. + +* Merge. Once a project is considered complete by developers, a PR +that includes Pedro should be created (unless, as mentioned above, an +early PR was already created in the development phase). Whether the PR +already existed or not, its description should be changed to start +with the "Ready To Merge" statement. This marks the project as ready +to be merged into master. Once a week, typically on Mondays, Pedro +will go through every PR marked as "Ready To Merge", build it, check +it out and if everything looks good merge it to master. At the end of +the day the resulting master will be tagged with a new version +number. This version will be go through some additional testing by +Brian and will then be deployed by Karl and Pete to customers +throughout the rest of the week. + +## Tools ## + * Pre-Merge checklist + * Code Review tutorial diff --git a/doc/user/docs/Help.md b/doc/user/docs/Help.md index 2fd019cd3..594a87461 100644 --- a/doc/user/docs/Help.md +++ b/doc/user/docs/Help.md @@ -1,5 +1,9 @@ #Help +
+ +
+ ##Report a Problem If there is any issue at all, you can click here and it’ll bring up a “Report a Problem” window, which you can type diff --git a/doc/user/docs/Launcher.md b/doc/user/docs/Launcher.md index f29d017cf..455db1286 100644 --- a/doc/user/docs/Launcher.md +++ b/doc/user/docs/Launcher.md @@ -1,5 +1,9 @@ #Module Launcher +
+ +
+ - The module launcher is the first item that will come up after logging in to Spark. - This is your central control for all modules @@ -9,7 +13,7 @@ ![](images/image38.png) -- If you right click anywhere on the launcher you can modify +- If you right-click anywhere on the launcher you can modify various display settings including: - Vertical layout, instead of horizontal - Showing the text of the individual modules @@ -25,5 +29,5 @@ Some common features within BTS Spark - All Windows are tabbed so they can be combined or separated to organize your workspace -- Some Spark windows have a menu on the left hand side where you can launch related modules or change settings. You can see the menu item names either by hovering your mouse over the icon, or clicking on the right edge of the menu (a blue bar will appear). +- Some Spark windows have a menu on the left-hand side where you can launch related modules or change settings. You can see the menu item names either by hovering your mouse over the icon or clicking on the right edge of the menu (a blue bar will appear). -  Some table columns have filtering capabilities, where if you hover over the column header, it will display a filter icon, which enables you to filter the table based on the information in that column. diff --git a/doc/user/docs/Market.md b/doc/user/docs/Market.md index 6a6168f68..be33a04a4 100644 --- a/doc/user/docs/Market.md +++ b/doc/user/docs/Market.md @@ -9,6 +9,10 @@ ##Market View +
+ +
+ - This provides a grid of outright, spread, and synthetic products showing real-time market data all in one place - You can create multiple market view grids and customize the @@ -29,7 +33,7 @@ and all securities will be displayed.  This will show up in the selected securities window as “<symbol> future at <exchange>” -- Synthetic’s can be displayed by clicking on exchange “BTS”, then +- Synthetics can be displayed by clicking on exchange “BTS”, then synthetic, symbol, and finally under the securities window. - Below is an example of an outright, spread, all futures, and synthetic chosen: @@ -98,10 +102,10 @@ either the Bid or Ask price and volume. - Highlighting a single security and clicking on the order ticket ![](images/image23.png) icon - on the left hand browser window of the market view + on the left-hand browser window of the market view - Launch a ladder for 1 security - - You can double click on any security in the market view, besides + - You can double-click on any security in the market view, besides the Bid Qty, Bid Price, Ask Price, or Ask Qty columns to launch a ladder for that Security. @@ -110,7 +114,7 @@ - If you hold down the Ctrl key and select multiple securities, you can then click on the ladder icon ![](images/image69.png) on - the left hand side to bring up the selected ladders all at + the left-hand side to bring up the selected ladders all at once. - Launching a Fills window for 1 or many securities @@ -118,7 +122,7 @@ - This is done by either highlighting 1 or many securities and then clicking on the Fills icon ![](images/image20.png) on - the left hand side to bring up a fill window for the selected + the left-hand side to bring up a fill window for the selected securities.   - Please note - If there haven’t been any fills for the day in that @@ -129,14 +133,14 @@ - This is accomplished by highlighting 1 or many securities and then clicking on the time and sales icon ![](images/image49.png) on - the left hand side + the left-hand side - Launching the synthetic window to create a synthetic product - This is accomplished by highlighting either 1 or 2 securities and clicking on the Synthetic icon ![](images/image34.png) on - the lower left hand side + the lower left-hand side - Please note - If only 1 security is chosen, a create synthetic window will appear, and you will be required to add another leg from @@ -144,7 +148,11 @@ ##Time and Sales -- Provides a display of real time fills as they happen for 1 or many +
+ +
+ +- Provides a display of real-time fills as they happen for 1 or many securities - You can create multiple time and sale windows and customize the security selection to fit your needs diff --git a/doc/user/docs/My-Windows.md b/doc/user/docs/My-Windows.md index 2d1af5d34..ab283b6b5 100644 --- a/doc/user/docs/My-Windows.md +++ b/doc/user/docs/My-Windows.md @@ -1,5 +1,9 @@ #My Windows +
+ +
+ This is the housing of the windows that you have manually named and creates a place where you can quickly and easily launch windows which you’ve customized. @@ -18,9 +22,9 @@ section of the module launcher. ![](images/image15.png) -Right clicking on a tab that has already had its default title modified +Right-clicking on a tab that has already had its default title modified will show the following which will allow you to rename the modified -title or remove it from the my windows, which will then restore the +title or remove it from the My Windows, which will then restore the default standard title. ![](images/image37.png) diff --git a/doc/user/docs/Settings.md b/doc/user/docs/Settings.md index 3b8aa0477..da6755fab 100644 --- a/doc/user/docs/Settings.md +++ b/doc/user/docs/Settings.md @@ -1,6 +1,10 @@ #Settings +
+ +
+ ##Workspaces This is where your workspaces can be saved or switched diff --git a/doc/user/docs/Spreader.md b/doc/user/docs/Spreader.md index 4f8460967..dc9a84ec9 100644 --- a/doc/user/docs/Spreader.md +++ b/doc/user/docs/Spreader.md @@ -1,14 +1,35 @@ #Spreader +
+ +
+ +
+ +
+ + +
+ +
+ +
+ +
+ +
+ +
+ - Launching the spreader from the module launcher will bring up the synthetic management browser which appears like below: ![](images/image35.png) -- From this window it’ll show any synthetics that you have already +- From this window, it will show any synthetics that you have already created as well as various other options of both managing the - synthetics and other tasks all from the left hand side pane within + synthetics and other tasks all from the left-hand side pane within the window, including: - Adding a new synthetic ![](images/image8.png) @@ -30,7 +51,7 @@ - From the main module launcher, you can go to spreader, then synthetics, then click add - Highlighting one or more securities in a market view and clicking - on create synthetic + on Create Synthetic - Cloning an existing security - An empty synthetic browser will look like below without any legs @@ -43,10 +64,10 @@ - Upon adding legs, you can then go through each of the parameters to customize how you would like the spread to be worked in the market -- We’ll start at the top of create synthetic window and work our way +- We will start at the top of the Create Synthetic window and work our way down: - - At the very top of the create synthetic window you will have to + - At the very top of the Create Synthetic window you will have to name your synthetic product.  By default, it will auto-populate based on the symbols you have chosen: @@ -73,16 +94,15 @@ exchange - Furthermore, if you are ever unsure of what a parameter’s function is and how it is controlled you can hover over the parameter’s title - and a “?” will be shown.  Clicking on this will expand built in + and a “?” will be shown.  Clicking on this will expand built-in details of how that parameter functions.  Below is an example of the throttle details displayed: ![](images/image56.png) - - Main parameters - these are the top 4 rows in the create synthetic + - Main parameters - these are the top 4 rows in the Create Synthetic window which all synthetics will be required to have set. -  Everything below these are custom to a traders needs, however the - top 4 are the main foundational aspects used for the calculation of +  Everything below these can be customized to a trader's needs, however, the top 4 are the main foundational aspects used for the calculation of the synthetic: ![](images/image10.png) @@ -95,7 +115,7 @@ be priced, by default, it’ll be based on the same as the quantity of the synthetic produced, but you can change it to modify the balance of the price, giving more weighting to one leg over another. - - Enable quoting - This parameter is in the form of a check box, + - Enable quoting - This parameter is in the form of a checkbox, where if the box is checked the leg will be quoted versus not checked, it will not be shown in the market.  If it is not actively quoted in the market, the leg will still be used for calculation of @@ -107,7 +127,7 @@  If your Hedge Ratio is 3 on the NQ leg, then you’ll work the ES order based on where you could fill 6 (2 (Qty of NQ) \* 3 (Hedge Ratio)). - - The next 6 parameters are all completely custom to a traders needs + - The next 6 parameters are all completely custom to a trader's needs and can further define how a synthetic is worked.  As previously mentioned, if you hover over any of these parameters a “?” will be displayed and click on such will display further details on how this @@ -118,7 +138,7 @@ - Quote - Throttle - This can be enabled or disabled based on if the box is - checked per leg.  It’s main function is to reduce re-quoting updates + checked per leg.  Its main function is to reduce re-quoting updates by defining a region on either side of the working quote order, inside which quote updates will not be sent: @@ -148,8 +168,8 @@ ![](images/image70.png) - - Time Based Cross - Basically the exact same as ticks away cross, - however this is based on time (in ms) on when to automatically cross + - Time Based Cross - Basically the same as Ticks Away Cross, + however, this is based on time (in ms) on when to automatically cross (fill) the market if they get too far away from the opposite inside market.  If a legged hedge order’s price gets X amount of “ticks” away from the opposite inside market, it is re-priced to cross the diff --git a/doc/user/docs/Trading.md b/doc/user/docs/Trading.md index 9a7472a88..b31151ce0 100644 --- a/doc/user/docs/Trading.md +++ b/doc/user/docs/Trading.md @@ -9,7 +9,11 @@ ##Order Book -- This provides list of all orders a user has placed, by default it +
+ +
+ +- This provides a list of all orders a user has placed, by default it will display only working orders - You can create multiple order books filtered however you would like @@ -44,13 +48,13 @@ - Anytime - Today - Since Open -- A specific user defined period of time +- A specific user-defined period of time ![](images/image25.png) -- The left hand box within an order book provides users with further +- The left-hand box within an order book provides users with further functionality to quickly perform various tasks with live orders as - well as launch other modules.  It’s appears like the below: + well as launch other modules.  It appears like the below: ![](images/image4.png) @@ -62,7 +66,7 @@ - ![](images/image73.png)Cancel selected - clicking on this will cancel the selected orders you have highlighted in the order book.  You can choose more than one by - holding hold the Ctrl key when click on each row of orders + holding hold the Ctrl key when clicking on each row of orders - ![](images/image74.png)Cancel buys - clicking on this will cancel all the buy orders you have in the order book @@ -75,8 +79,8 @@ ##Fills -- This provides list of all fills a user has had for a given time - period, by default it will open up with “since open” time frame +- This provides a list of all fills a user has had for a given time + period, by default it will open up with “since open” timeframe selected showing you fills on the day thus far - You can create multiple fill windows, filtered however you like @@ -85,8 +89,12 @@ ##P&L +
+ +
+ - This provides a running ledger of a users account(s) profit and - loss broken down per symbol + loss, broken down per symbol - You can create multiple P&L windows, filtered however you would like - All P&L windows are brought up as tabs and can be combined with all @@ -101,6 +109,10 @@ ##Ladder +
+ +
+ - The ladder was designed to be the most logically produced ladder on the market, engineered and designed by professional traders for professional traders @@ -112,8 +124,8 @@ ![](images/image36.png) -- The ladder consist of 2 major parts, the Ladder itself and the - information and control section on the left hand side +- The ladder consists of 2 major parts, the Ladder itself and the + information and control section on the left-hand side - The information section on the left contains the following:   ![](images/image1.png) - Day - showing the current price of the security on the day @@ -126,17 +138,17 @@ - The control section right underneath the information section on the - left hand side offers the following: + left-hand side offers the following: ![](images/image62.png) -- Account in which the orders will flow into when trading this +- The account in which the orders will flow into when trading this security -- Length of time the order will remain in market, either DAY or +- Length of time the order will remain in the market, either DAY or GTC -- Order type, by default orders will go in as Limit, however all of +- Order type, by default, orders will go in as Limit, however all of the following are offered out of the box.  The top 5 are all fairly - standard order types, however the bottom 5 are all specialized + standard order types, however, the bottom 5 are all specialized algos.  They are only offered by BTS and require specialized parameters.  Please see below for each order type: @@ -147,8 +159,8 @@ - Limit - - This is a buy or sell order designed to take place on the exact - price level you have entered the order at. + - This is a buy or sell order designed to take place on the + price level where you entered the order. - Stop @@ -218,8 +230,7 @@ market flips and has at least threshold size as defined. - “Flip” refers to the event where the best offer becomes the best bid or the market trades away from you, i.e. the line moves up in - the GUI.  This is all true in the reverse way as well if - selling. + the GUI.  The reverse is true if selling. ![](images/image41.png) @@ -241,7 +252,7 @@ - You can manually type in a quantity here as well - Furthermore, if you have a value in the volume bar, you can - increase this size by right clicking and the value will increase + increase this size by right-clicking and the value will increase incrementally by 1.  The same is true if you would like to decrease this value by left click and the value will decrease. - By having the auto clear box checked, it will bring the value back @@ -252,12 +263,12 @@ -  The bottom section of the control area of a ladder has 4 aspects to it - - Cancel Buys - which will cancel all buys currently working on the + - Cancel Buys, which will cancel all buys currently working on the ladder - - Cancel Sells - which will cancel all sells currently working on the + - Cancel Sells, which will cancel all sells currently working on the ladder - - Cancel All - which will cancel all orders on the ladder - - Settings - this will launch the ladder settings window which + - Cancel All, which will cancel all orders on the ladder + - Settings, which will launch the ladder settings window which appears like below ![](images/image71.png) @@ -269,27 +280,26 @@ - There are 5 main columns - - Orders - which display current orders working in the market - - Bid - which displays the current bid volumes at each price + - Orders, which display current orders working in the market + - Bid, which displays the current bid volumes at each price level - - Price - which displays the price levels of the symbol shown - - Ask - which displays the current ask volumes at each price + - Price, which displays the price levels of the symbol shown + - Ask, which displays the current ask volumes at each price level - - Last Trade - which displays where the price level and volume of + - Last Trade, which displays the price level and volume where the last trade occurred - Functionality of the ladder - To enter an order directly by clicking in the ladder, left click on either the bid or ask volume with a volume greater than 0 on the - predefined value box on the left hand section + predefined value box on the left-hand section - A badge will be displayed within the orders column of the value you have chosen and the quantity filled as displayed below ![](images/image46.png) -- To change the price level you wish to work the order, you can right - click and hold on the badge to move it up or down the ladder for the +- To change the price level you wish to work the order, you can right-click and hold on the badge to move it up or down the ladder for the desired price - To cancel the order, left click on the badge - Furthermore, you can click down on the scroll wheel of your mouse @@ -298,6 +308,10 @@ ## Order Ticket +
+ +
+ - The order ticket was designed to provide another means other than the ladder to enter orders into the market - You can bring up an order ticket directly from the module launcher, @@ -307,7 +321,7 @@ ![](images/image27.png) -- On the top left you have the price for the order as well as the +- On the top left, you have the price for the order as well as the volume - Beneath are the predefined volumes as well as a clear button to clear out the volume diff --git a/doc/user/docs/index.md b/doc/user/docs/index.md index 7a754bb34..e97ff09b5 100644 --- a/doc/user/docs/index.md +++ b/doc/user/docs/index.md @@ -1,3 +1,3 @@ -Click on the headings on the the left to expand their contents. If you need specific information quickly use the Search button in the top right of this page. +Click on the headings on the left to expand their contents. If you need specific information quickly use the Search button in the top right of this page. diff --git a/doc/user/docs/release_notes.md b/doc/user/docs/release_notes.md index f2204ae6e..c4a49f9b5 100644 --- a/doc/user/docs/release_notes.md +++ b/doc/user/docs/release_notes.md @@ -1,13 +1,31 @@ # Release Notes +## 1.4.2 + +### User Interface Improvements + - When creating a synthetic from the Market View window, securities are now added to the Create Synthetic dialog in the same sort order as they appear in grid +### Bug Fixes + - Shell no longer crashes when removing a security from the synthetics window + - It is now possible to create a new synthetic using the same name as a previously deleted synthetic +### SDK Improvements + - Improved Client and Server SDK clarity and documentation +### Performance Improvements + - Synthetic calculation speed was improved by 400%. +### Risk / Entitlement System + - Risk Admin UI + - Spark users now have separate Trading, RiskAdmin, and/or MDAdmin permissions + - Spark users can now only add other users or accounts if permissioned to do so. + - Market Data Entitlement + - Automated market data reporting + ## 1.4.1 -### Tabs +### Tabs - Tabs now shrink and expand to make better use of horizontal space ### Bug Fixes - Fixed a bug that could cause excessive CPU usage when a connection broke - - Fixed a layout bug in hedging/requoting performance reports - - Fixed account name mismatching bug for old fills + - Fixed a layout bug in hedging/requoting performance reports + - Fixed account name mismatching bug for old fills ### Absolute Position limits - Positions can now be netted or absolute for purposes of limit enforcing @@ -17,7 +35,7 @@ - Improved requoting and hedging performance - Improved order book form performance ### Server Side SDK - - Added beta version of the server side SDK + - Added a beta version of the server side SDK ### Front End - Added status bars to all UI grids ### Reporting @@ -29,7 +47,7 @@ - Further speed enhancements ### Conditional (new quoting parameter) - Reduces re-quoting updates by only quoting if N ticks away from the opposite inside market. - - Quotes are cancelled when it gets further away. + - Quotes are canceled when it gets further away. - "Price Type" dictates if this logic applies to the quoting market or to the synthetic spread market. ## 1.3.7 @@ -53,7 +71,7 @@ ### Synthetic creation option to choose Merged or Direct - The ability to choose Merged or Direct per leg when creating a synthetic ### Volume at price - - Within a ladder you can now see a volume at price graph + - Within a ladder, you can now see a volume at price graph - This is configurable from a ladder's settings as well ### Customized settings in all windows - All windows now contain a settings page where grid settings (font color, size, etc) are applied @@ -71,7 +89,7 @@ ### Order Book - Many visual facets of the Order Book grid can now be customized - - The Order Book settings page can be access from the gears icon in the Order Book toolbar or from the right-click menu + - The Order Book settings page can be accessed from the gears icon in the Order Book toolbar or from the right-click menu - The Expand/Collapse All button has been separated into two different buttons on the toolbar ### Sound Alerts @@ -107,13 +125,13 @@ ### Synthetics - Hedge Ratio parameter has been renamed to Lean Qty Factor - Spreader now includes a Hidden mode parameter - - A quoting leg can be hidden, ie an order will not sent out until the market crosses the computed quoting price. When that happens, the quote is sent out as an IOC order. + - A quoting leg can be hidden, ie an order will not be sent out until the market crosses the computed quoting price. When that happens, the quote is sent out as an IOC order. ### Algos - Trigger orders now can contain a Trigger Exit parameter based on time or price; once the exit condition has been met the Trigger order will cancel - IOC/FAK order type added - Cover order type added - - Cancelling a synthetic order no longer cancels any working hedge orders + - Canceling a synthetic order no longer cancels any working hedge orders ### General - A manual page has been added to the launcher Help menu @@ -121,18 +139,18 @@ - Various cash per point values updated - Time-based grid filters now have tick up/down buttons - Numerous performance improvements and stability enhancements - - Automated position and orderbook maintenance during daily recycle - - Individual fills be compacted into start of day position records + - Automated position and Order Book maintenance during daily recycle + - Individual fills will be compacted into the Start of Day position records - Orders from the day before the recycle will be deleted ##1.1 ###1.1.22 -- Orderbook: Orders in Error status can now be recreated -- Orderbook: Orders containing child orders will now be collapsed by default. -- Orderbook: Expand / Collapse All button added to the right-click menu and window action pane, denoted by ▲ icon -- Orderbook: Symbol column added to allow for filtering based on group symbol +- Order Book: Orders in Error status can now be recreated +- Order Book: Orders containing child orders will now be collapsed by default. +- Order Book: Expand / Collapse All button added to the right-click menu and window action pane, denoted by ▲ icon +- Order Book: Symbol column added to allow for filtering based on group symbol - Time filters now have a quick Set Last Hour hyperlink which will set the Period Begin filter to (Now - 1 hour) ###1.1.20 @@ -151,15 +169,15 @@ - Fixed occasional crash when filtering fills - Fixed several cash per point multipliers - Colored time of sales row with aggressor side -- Iceberg orders now cancel (rathern than error) when a child is canceled +- Iceberg orders now cancel (rather than an error) when a child is canceled ###1.1.0 - Added per user self match protection, location and self match protection FIX tag settings - Implemented a new "Trigger Order" algo - Corrected tick formatting for a number of products -- Added the hability to recreate canceled orders -- Added leg fills to facilitate futured based PnL -- PnL report now has PnL columns calculated based on your start of day, current day, and total position +- Added the ability to recreate canceled orders +- Added leg fills to facilitate futures based PnL +- PnL report now has PnL columns calculated based on your Start of Day, current day, and total position - Start, Day and Total PnL columns are painted with a red or green background color based on if the pnl value is negative or positive respectively - Corrected cash per point values, used in pnl calculations, for a number of products - PnL report will now remember any customizations you make to filtering and/or sorting criteria diff --git a/ops_notes.txt b/ops_notes.txt index 6d1493c4b..1975dd799 100644 --- a/ops_notes.txt +++ b/ops_notes.txt @@ -1,3 +1,10 @@ +1.4.2 +- Be sure the system has a bts user before deployment. bts is the superuser, he has all permissions and can see all market data +- After deployment re-permission all existing users for trading, riskadmin, and/or md admin permissions as appropriate +- Also note which users can add other users and accounts and permission them appropriately (Can Add?) +- Permission users for appropriate market data entitlements; this has monetary consequences so ask Kevin if you aren't sure. +- MIC reporting needs to be added to audit Jenkins job (https://bluetradesys.atlassian.net/browse/SPARK-1900) + 1.3.5 - Change in market data wire format. Old shell will get only direct market data instead of merged which may not match what the servers is driving from. diff --git a/src/client/spark/Admin/AdminModel.cs b/src/client/spark/Admin/AdminModel.cs index ebf235a1c..da1ae42f4 100644 --- a/src/client/spark/Admin/AdminModel.cs +++ b/src/client/spark/Admin/AdminModel.cs @@ -36,7 +36,7 @@ namespace mbts.spark { IEnumerable active_accounts = from admin_data in update.all from bts_account in admin_data.Accounts - where bts_account.IsPresent + where bts_account.IsPresent && _wrapper_subject.Value.can_view_account(bts_account.Name) join account_id in ( from bts_user in active_users from account_id in bts_user.UserData.AccountPermissions.AccountPermissions.Keys diff --git a/src/client/spark/Admin/AdminModelWrapper.cs b/src/client/spark/Admin/AdminModelWrapper.cs index eedc3c0b3..62895933c 100644 --- a/src/client/spark/Admin/AdminModelWrapper.cs +++ b/src/client/spark/Admin/AdminModelWrapper.cs @@ -16,26 +16,26 @@ namespace mbts.spark { _admin_data = admin_data; _user_name = user_name ?? string.Empty; - _allowed_accounts = search_admin(u => u.Name == _user_name).Select(x => x.Item1).ToList(); - foreach(var val in _allowed_accounts) + _allowed_accounts = search_admin(u => u.Name == _user_name).Where(x => + { + return x.Item2.HasPermissions || x.Item3.HasPermissions; + }).Select(xx => xx.Item1).ToList(); + foreach (var val in _allowed_accounts) _allowed_account_dict[val.Name] = val.Name; } - public IEnumerable> get_trading_permissions(UInt32 user_id) - { - return search_admin(u => u.Id == user_id); - } public IEnumerable viewable_accounts() { return _allowed_accounts; } public bool can_view_account(string account) { - return _allowed_account_dict.ContainsKey(account) || _user_name.ToLower() == "bts"; + return _allowed_account_dict.ContainsKey(account) || _user_name.ToLower().Equals("bts"); } - IEnumerable> search_admin(Func predicate) + IEnumerable> + search_admin(Func predicate) { - var rv = new List>(); + var rv = new List>(); if (_admin_data.HasValue) { var users = _admin_data.Value.Users.Where(predicate); @@ -51,9 +51,7 @@ namespace mbts.spark if (accounts != null && accounts.Count() == 1) { var account = accounts.ElementAt(0); - var tp = kv.Value.TradingPermission; - var rv_val = new TradingPermissionUnitImmutable(tp); - rv.Add(Tuple.Create(account, rv_val)); + rv.Add(Tuple.Create(account, kv.Value.TradingPermission, kv.Value.AdminPermission)); } } } diff --git a/src/client/spark/Daemons/MDDaemon.cs b/src/client/spark/Daemons/MDDaemon.cs index 7274b28ad..76c89157f 100644 --- a/src/client/spark/Daemons/MDDaemon.cs +++ b/src/client/spark/Daemons/MDDaemon.cs @@ -49,7 +49,7 @@ namespace bts { .Subscribe(t => { var deleted_synthetic_keys = new HashSet(t.Where(kv => kv.Value.Deleted).Select(kv => kv.Key)); // add back 'undeleted' synthetics - foreach (var kvp in _deleted_synthetics) { + foreach (var kvp in _deleted_synthetics.ToList()) { if (!deleted_synthetic_keys.Contains(kvp.Key)) { _exchange_sec_map.TryAdd(kvp.Key, kvp.Value); _deleted_synthetics.Remove(kvp.Key); diff --git a/src/client/spark/Modules/Market/MarketView/MarketViewWindow.cs b/src/client/spark/Modules/Market/MarketView/MarketViewWindow.cs index a61249130..383d31a7c 100644 --- a/src/client/spark/Modules/Market/MarketView/MarketViewWindow.cs +++ b/src/client/spark/Modules/Market/MarketView/MarketViewWindow.cs @@ -65,7 +65,7 @@ namespace mbts.spark { }) ), SparkCommands.ShowTimeAndSales.complete(_vm.selected_securities_observable(), _ => true, secs => secs.Count > 0 ? new SecurityCriteria(secs) : _state.security_criteria), - SparkCommands.ShowSyntheticCreate.complete(_vm.selected_securities_observable(), secs => secs.Count > 0 && secs.Count <= 24, secs => new SecurityCriteria(secs)), + SparkCommands.ShowSyntheticCreate.complete(_vm.sorted_selected_securities_observable(), secs => secs.Count > 0 && secs.Count <= 24, secs => new SecurityCriteria(secs)), SparkCommands.change_securities_command(() => (update_securities_cmd, _state.security_criteria)), // wrap the grid settings view factory in a dialogCommand here since the vm is destroyed/recreated when the security criteria changes SparkCommands.window_settings_command(new DialogCommand(() => { diff --git a/src/client/spark/Modules/Spreader/ShowSyntheticEditorHandler.cs b/src/client/spark/Modules/Spreader/ShowSyntheticEditorHandler.cs index a301d3c22..404e72e3e 100644 --- a/src/client/spark/Modules/Spreader/ShowSyntheticEditorHandler.cs +++ b/src/client/spark/Modules/Spreader/ShowSyntheticEditorHandler.cs @@ -6,6 +6,7 @@ using mbts.ui; using mbts.ui.spark; using mbts.ui.utility; using System; +using System.Collections; using System.Collections.Generic; using System.ComponentModel.Composition; using System.Linq; @@ -43,8 +44,23 @@ namespace bts.shell { name + "(1)"; } - async void _show_synthetic_create(SecurityCriteria security_criteria) => - _show_synthetic_create((await security_criteria.securities(_bus)).ToList()); + async void _show_synthetic_create(SecurityCriteria security_criteria) { + var found_securities = await security_criteria.securities(_bus); + var respect_clause_security_ordering_is_possible = security_criteria.clauses.Any(clause => clause.security_keys != null && clause.security_keys.Count > 0); + if (!respect_clause_security_ordering_is_possible) { + _show_synthetic_create(found_securities.Values.ToList()); + } else { + List ordered_security_list = new List(); + foreach (var clause in security_criteria.clauses) { + foreach (var sec_key in clause.security_keys) { + if (found_securities.TryGetValue(sec_key, out SecurityImmutable found_result)) { + ordered_security_list.Add(found_result); + } + } + _show_synthetic_create(ordered_security_list); + } + } + } void _show_synthetic_create(IReadOnlyCollection securities) { if (securities.Count == 1) { diff --git a/src/client/spark/Orders/OrderRecordTupleSource.cs b/src/client/spark/Orders/OrderRecordTupleSource.cs index 51ffa7f78..0c8aeaccf 100644 --- a/src/client/spark/Orders/OrderRecordTupleSource.cs +++ b/src/client/spark/Orders/OrderRecordTupleSource.cs @@ -95,7 +95,7 @@ namespace mbts.spark { /// Warning: must NOT be reassigned with ; the latter is always the same object. /// This would mean that the /// call above would literally be calculating the difference between the keys of the same dictionary! - foreach (var k in removed_keys) { + foreach (var k in removed_keys.ToList()) { if (_security_orders.try_lookup(k, out ISet order_keys)) { SecurityMD old_sec_md = _security_md_cache[k]; removed_securities.Add(k, old_sec_md); @@ -109,7 +109,7 @@ namespace mbts.spark { } _security_md_cache.Remove(k); } - foreach (var k in added_keys) { + foreach (var k in added_keys.ToList()) { SecurityMD new_sec_md = securities[k]; if (_security_orders.try_lookup(k, out ISet order_keys)) { added_securities.Add(k, new_sec_md); diff --git a/src/client/spark/Orders/OrderTypeVMs/LeanOrderVM.cs b/src/client/spark/Orders/OrderTypeVMs/LeanOrderVM.cs index 0c436a742..3b884d8ff 100644 --- a/src/client/spark/Orders/OrderTypeVMs/LeanOrderVM.cs +++ b/src/client/spark/Orders/OrderTypeVMs/LeanOrderVM.cs @@ -25,7 +25,7 @@ namespace mbts.spark cross_threshold = new InlineUserProperty( new bts.spark.QuantityMeasure() { Ratio = 1.0, Absolute = 1}, false); max_chase_ticks = new InlineUserProperty(2, false); - trade_toward_behavior = new InlineUserProperty(LeanOrderDefinition.Types.OnToward.Cancel, false); + trade_toward_behavior = new InlineUserProperty(LeanOrderDefinition.Types.OnToward.NoChange, false); } public readonly InlineUserProperty selected_child_order_type; public readonly InlineUserProperty> child_order_types; @@ -47,7 +47,7 @@ namespace mbts.spark public bts.spark.QuantityMeasure cross_threshold { get; set; } = new bts.spark.QuantityMeasure() { Ratio = 1.0, Absolute = 1 }; public uint max_chase_ticks { get; set; } = 2; - public LeanOrderDefinition.Types.OnToward trade_toward_behavior { get; set; } = LeanOrderDefinition.Types.OnToward.Cancel; + public LeanOrderDefinition.Types.OnToward trade_toward_behavior { get; set; } = LeanOrderDefinition.Types.OnToward.NoChange; public LeanOrderVM(OrdersModel model, IObservable security_md_source, string id, string display_name) : this(model, security_md_source, security_md_source.Select(smd => diff --git a/src/client/spark/Spark.csproj b/src/client/spark/Spark.csproj index b6f3b57a2..f3579dcd9 100644 --- a/src/client/spark/Spark.csproj +++ b/src/client/spark/Spark.csproj @@ -82,9 +82,4 @@ - - - - - diff --git a/src/client/spark/view/Spark/ContractPicker/SecurityCriteriaExtensions.cs b/src/client/spark/view/Spark/ContractPicker/SecurityCriteriaExtensions.cs index 76a467176..11449a01f 100644 --- a/src/client/spark/view/Spark/ContractPicker/SecurityCriteriaExtensions.cs +++ b/src/client/spark/view/Spark/ContractPicker/SecurityCriteriaExtensions.cs @@ -18,10 +18,10 @@ namespace mbts.spark { return self == null ? all.Values : all.Values.Where(md => ContractPickerModel.security_in_criteria(self, md.security)); } - public static async Task> securities(this SecurityCriteria self, IBus bus) { + public static async Task> securities(this SecurityCriteria self, IBus bus) { var md_map = await bus.subscribe(SparkTags.SecuritiesTag).FirstAsync(); - var all_secs = md_map.Values.Select(md => md.security); - return self == null ? all_secs : all_secs.Where(s => ContractPickerModel.security_in_criteria(self, s)); + var all_secs = md_map.Values.Select(md => md.security).ToDictionary(key => key.Id); + return self == null ? all_secs : all_secs.Values.Where(s => ContractPickerModel.security_in_criteria(self, s)).ToDictionary(key => key.Id); } public static IObservable> subscribe(this SecurityCriteria self, IBus bus) { diff --git a/src/client/spark/view/Spark/Grid/SecurityGrid.cs b/src/client/spark/view/Spark/Grid/SecurityGrid.cs index b690b88ca..562e91fd6 100644 --- a/src/client/spark/view/Spark/Grid/SecurityGrid.cs +++ b/src/client/spark/view/Spark/Grid/SecurityGrid.cs @@ -122,6 +122,21 @@ namespace mbts.spark where TRow : class, ISecurityRow => security_grid.selected_securities.ObserveSelf(); + public static IObservable> sorted_selected_securities_observable(this SecurityGridBase security_grid) + where TRow : class, ISecurityRow => + security_grid.selected_rows + .ObserveSelf() + .Select(rows => + rows.Select( + row => (security: row.security, row_index: security_grid.rows_view.indexOf(row)) + ) + .OrderBy(sec_vs_index => sec_vs_index.row_index) + .Select(sec_vs_index => sec_vs_index.security) + .ToReadOnlyList() + ); + + + public static IObservable> selected_security_mds_observable(this SecurityMDGrid security_md_grid) where TRow : class, ISecurityMDRow => security_md_grid.selected_rows.ObserveSelf(true).Select(rows => rows.Select(r => r.md).ToReadOnlyList()); diff --git a/src/client/spark_api/md/Authenticator.cs b/src/client/spark_api/md/Authenticator.cs new file mode 100644 index 000000000..34aca3bfc --- /dev/null +++ b/src/client/spark_api/md/Authenticator.cs @@ -0,0 +1,23 @@ +using System; +using System.Threading.Tasks; +using bts.api; +using bts.api.core; + +namespace bts.api +{ + public class Authenticator + { + readonly static Lazy _auth = new Lazy(() => Locator.locate(), true); + user.AuthToken _token = null; + public Authenticator() { } + + public user.AuthToken last_token => _token; + public async Task login(string login, string password) + { + var res = await _auth.Value.authenticate_login_async(new user.AuthenticateLoginRequest { Login = login, Password = password }); + if (res.success) + _token = res.value.Token; + return _token; + } + } +} \ No newline at end of file diff --git a/src/client/spark_api/md/LazyAsync.cs b/src/client/spark_api/md/LazyAsync.cs new file mode 100644 index 000000000..c83dd4095 --- /dev/null +++ b/src/client/spark_api/md/LazyAsync.cs @@ -0,0 +1,17 @@ + +using System; +using System.Threading.Tasks; + +namespace bts +{ + public class AsyncLazy : Lazy> + { + public AsyncLazy(Func valueFactory) : + base(() => Task.Factory.StartNew(valueFactory)) + { } + + public AsyncLazy(Func> taskFactory) : + base(() => Task.Factory.StartNew(() => taskFactory()).Unwrap()) + { } + } +} \ No newline at end of file diff --git a/src/client/spark_api/md/Locator.cs b/src/client/spark_api/md/Locator.cs new file mode 100644 index 000000000..e86c98a05 --- /dev/null +++ b/src/client/spark_api/md/Locator.cs @@ -0,0 +1,16 @@ +using System; +using System.Threading.Tasks; +using bts.api; +using bts.api.core; + +namespace bts.api +{ + public static class Locator + { + readonly static Lazy _context = new Lazy(() => new ServiceContext(), true); + public static T locate(string qualifier="") where T : class, IApiClient + { + return _context.Value.locate(qualifier); + } + } +} diff --git a/src/client/spark_api/md/MarketDataClient.cs b/src/client/spark_api/md/MarketDataClient.cs index 748ffdea8..9f06f6aeb 100644 --- a/src/client/spark_api/md/MarketDataClient.cs +++ b/src/client/spark_api/md/MarketDataClient.cs @@ -33,49 +33,48 @@ namespace bts.api.md readonly ConcurrentDictionary _data = new ConcurrentDictionary(); readonly ConcurrentDictionary _security_key_to_desc= new ConcurrentDictionary(); readonly ConcurrentDictionary _security_desc_to_key = new ConcurrentDictionary(); - readonly Lazy _subscription; + readonly MDRequest _subscription; readonly Venue _venue; - readonly static Lazy _md = new Lazy(() => locate(), true); + readonly static Lazy _md = new Lazy(() => Locator.locate(), true); readonly static ConcurrentDictionary _venue_cache = new ConcurrentDictionary(); static readonly List _all_products; static MarketDataClient() { _all_products = _md.Value.request_products(new VoidMessage()).Products.ToList(); } - public static bool create_or_get(api.Venue exchange, out MarketDataClient md) + + public static IEnumerable cached_exchanges => _venue_cache.Keys; + public static bool create_or_get(api.Venue exchange, out MarketDataClient md, user.AuthToken token = null) { if (!_venue_cache.TryGetValue(exchange, out md)) { - _venue_cache[exchange] = md = new MarketDataClient(exchange); + _venue_cache[exchange] = md = new MarketDataClient(exchange, token); return true; } return false; } - public MarketDataClient(bts.api.Venue exchange = Venue.Unset) + public MarketDataClient(bts.api.Venue exchange = Venue.Unset, user.AuthToken token = null) { _venue = exchange; - _subscription = new Lazy(() => load_request(exchange)); + _subscription = load_request(exchange, token); } - MDRequest load_request(bts.api.Venue exchange) + public void set_auth_token(user.AuthToken toke) { - var req = new MDRequest(); + _subscription.Token = toke?.Token ?? string.Empty; + } + + MDRequest load_request(bts.api.Venue exchange, user.AuthToken token) + { + var req = new MDRequest() { Token = token?.Token ?? string.Empty } ; var prods = _all_products.Where(x=>x.Exchange == exchange || exchange == bts.api.Venue.Unset); foreach(var prod in prods) req.Channels.Add(new SecurityChannel() { Exchange = prod.Exchange, Type = prod.Type, Symbol = prod.Symbol, Flags = 0 }); return req; } - static MarketDataRelay locate() - { - using (var ctx = new api.core.ServiceContext()) - { - return ctx.locate(); - } - } - public Security lookup(security_key key) { Data value; @@ -217,7 +216,7 @@ namespace bts.api.md bool check_subscriptions(uint flags, Func selector) { - foreach (var sub in _subscription.Value.Channels) + foreach (var sub in _subscription.Channels) { if (selector(sub)) { @@ -251,7 +250,7 @@ namespace bts.api.md while (!rep.success && count++ < 5); while (true) { - var reply = await _md.Value.requestmd_async(_subscription.Value); + var reply = await _md.Value.requestmd_async(_subscription); if (reply.success) { foreach (var channel in reply.value.Channels) diff --git a/src/client/spark_api/utils/Log.cs b/src/client/spark_api/utils/Log.cs index d07b338ca..f6eb912e1 100644 --- a/src/client/spark_api/utils/Log.cs +++ b/src/client/spark_api/utils/Log.cs @@ -32,12 +32,14 @@ namespace bts { Testing, Latency, DataFlow, - Plugin + Plugin, + ClientSdk // Please keep this list in sync with logging.h/logging.cpp } - readonly struct Logger { + + public readonly struct Logger { readonly Subsystem _sys; - public Logger(Subsystem sys) { + internal Logger(Subsystem sys) { _sys = sys; } @@ -61,19 +63,20 @@ namespace bts { static extern void Logger_log (Level level, Subsystem subsystem, string message, string file, int line); } - static class Log { - public static Logger Gen => new Logger(Subsystem.gen); - public static Logger Config => new Logger(Subsystem.Config); - public static Logger QBus => new Logger(Subsystem.QBus); - public static Logger Md => new Logger(Subsystem.md); - public static Logger Api => new Logger(Subsystem.Api); - public static Logger Persist => new Logger(Subsystem.Persist); - public static Logger User => new Logger(Subsystem.User); - public static Logger OrderMan => new Logger(Subsystem.OrderMan); - public static Logger Assert => new Logger(Subsystem.Assert); - public static Logger Ui => new Logger(Subsystem.Ui); - public static Logger Testing => new Logger(Subsystem.Testing); - public static Logger DataFlow => new Logger(Subsystem.DataFlow); + public static class Log { + internal static Logger Gen => new Logger(Subsystem.gen); + internal static Logger Config => new Logger(Subsystem.Config); + internal static Logger QBus => new Logger(Subsystem.QBus); + internal static Logger Md => new Logger(Subsystem.md); + internal static Logger Api => new Logger(Subsystem.Api); + internal static Logger Persist => new Logger(Subsystem.Persist); + internal static Logger User => new Logger(Subsystem.User); + internal static Logger OrderMan => new Logger(Subsystem.OrderMan); + internal static Logger Assert => new Logger(Subsystem.Assert); + internal static Logger Ui => new Logger(Subsystem.Ui); + internal static Logger Testing => new Logger(Subsystem.Testing); + internal static Logger DataFlow => new Logger(Subsystem.DataFlow); + public static Logger ClientSdk => new Logger(Subsystem.ClientSdk); [Conditional("DEBUG")] @@ -99,10 +102,10 @@ namespace bts { assert(o == null); } delegate void on_crash_callback([MarshalAs(UnmanagedType.LPStr)]string msg, [MarshalAs(UnmanagedType.LPStr)] string details); - public static void system_is_crashing(string message, object details) { + internal static void system_is_crashing(string message, object details) { OnSystemCrashing?.Invoke(message, details); } - public static event Action OnSystemCrashing; + internal static event Action OnSystemCrashing; - } + } } diff --git a/src/client/spark_excel/ExcelAddin.cs b/src/client/spark_excel/ExcelAddin.cs index 60e03aa99..421639146 100644 --- a/src/client/spark_excel/ExcelAddin.cs +++ b/src/client/spark_excel/ExcelAddin.cs @@ -69,5 +69,21 @@ namespace bts.excel Utilities.bts_load_assembly(ass); } } + + public static void calculate_full_rebuild() + { + object app = ExcelDnaUtil.Application; + var mi = app?.GetType().GetMethod("CalculateFullRebuild", BindingFlags.Instance | BindingFlags.Public); + if(mi != null) + mi.Invoke(app, null); + } + + public static void calculate_full() + { + object app = ExcelDnaUtil.Application; + var mi = app?.GetType().GetMethod("CalculateFull", BindingFlags.Instance | BindingFlags.Public); + if (mi != null) + mi.Invoke(app, null); + } } } \ No newline at end of file diff --git a/src/client/spark_excel/Properties/ExcelDna.Build.props b/src/client/spark_excel/Properties/ExcelDna.Build.props index 0f536a88f..cb4657bfb 100644 --- a/src/client/spark_excel/Properties/ExcelDna.Build.props +++ b/src/client/spark_excel/Properties/ExcelDna.Build.props @@ -38,7 +38,7 @@ - false + true + + + + + + + - + + + + + + + + + + + + + + + + + ..\..\lib\net471\spark_api.dll + + + + + + + ..\..\lib\netcoreapp2.1\spark_api.dll + + + + + + + + + + + + + + + diff --git a/src/client/sparkcmd/Cmd/ConsoleCommandEx.cs b/src/client/sparkcmd/Cmd/ConsoleCommandEx.cs new file mode 100644 index 000000000..18c73075d --- /dev/null +++ b/src/client/sparkcmd/Cmd/ConsoleCommandEx.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ManyConsole { + public static class ConsoleCommandEx { + public static string get_argument(this ConsoleCommand _, string arg_name) { + var arg = Environment.GetCommandLineArgs().FirstOrDefault(str => str.StartsWith("--"+arg_name)); + if (arg != null) { + var parts = arg.Split(new[] { '=' }, 2); + if (parts.Length > 1) { + return parts[1]; + } + } + return ""; + } + } +} diff --git a/src/client/sparkcmd/Cmd/ServiceTail.cs b/src/client/sparkcmd/Cmd/ServiceTail.cs new file mode 100644 index 000000000..316d52071 --- /dev/null +++ b/src/client/sparkcmd/Cmd/ServiceTail.cs @@ -0,0 +1,78 @@ +using bts.api.core; +using bts.test; +using ManyConsole; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace bts { + class TailService : ConsoleCommand { + static bool _all = false; + static bool _timestamp = false; + public TailService() { + void ignore(string _) { } + IsCommand("tailservice", "Tail updates to named service api. Ex: tail --method=SyntheticSecurityService.metadata"); + HasRequiredOption("method", "Service.method to tail", ignore); + HasOption("time", "Include timestamp", _ => _timestamp = true); + // The following are not implemented. If you need them get to work. + HasOption("path", "Path inside the row to use for display. Ex: 'Id' or 'Name' ", ignore); + HasOption("all", "Invlude 'all' rows on every print", _ => _all = true); + } + public override int Run(string[] remainingArguments) { + var arg = this.get_argument("method"); + var split = arg.Split('.'); + if (split.Length != 2) { + Console.WriteLine("Try --method=[ServiceName].[Method]"); + return -1; + } + tail(split[0], split[1]); + return 0; + } + class SubscriptionLogger : IObserver { + public void OnCompleted() { + ConsoleEx.WriteLine("Completed.", ConsoleColor.Yellow); + } + + public void OnError(Exception error) { + ConsoleEx.WriteLine($"Error. '{error}'", ConsoleColor.Red); + } + + public void OnNext(T value) { + if (_timestamp) { + Console.Write(DateTime.Now.ToString("HH:mm:ss.fff")); + Console.Write(" "); + } + if (_all) { } + Console.WriteLine(value); + } + } + private static void tail(string service_name, string method_name) { + var spark_api = typeof(ServiceContext).Assembly; + var service_type = spark_api.GetExportedTypes().FirstOrDefault(t => t.Name == service_name); + if (service_type == null) { + Console.WriteLine($"Could not find service type {service_name} in spark_api.dll"); + return; + } + var subscribe_method = service_type.GetMethod("subscribei_" + method_name); + using (var ctx = new ServiceContext()) { + var locate = typeof(ServiceContext).GetMethod("locate").MakeGenericMethod(service_type); + var service = locate.Invoke(ctx, new[] { "" }); + // Subscribe with null qualifier + object observable = subscribe_method.Invoke(service, new object[] { null }); + Type update_type = observable.GetType().GetGenericArguments().First(arg => arg.Name.StartsWith("Update")); + Type observer_type = typeof(SubscriptionLogger<>).MakeGenericType(update_type); + object observer = Activator.CreateInstance(observer_type); + + var subscribe = observable.GetType().GetMethod("Subscribe", new[] { observer_type }); + var dispose = subscribe.Invoke(observable, new[] { observer }); + + while (true) { + System.Threading.Thread.Sleep(1000); + } + } + } + + } +} diff --git a/src/client/sparkcmd/Cmd/ServiceTestCommand.cs b/src/client/sparkcmd/Cmd/ServiceTestCommand.cs index dfad6cc5d..f9e105b22 100644 --- a/src/client/sparkcmd/Cmd/ServiceTestCommand.cs +++ b/src/client/sparkcmd/Cmd/ServiceTestCommand.cs @@ -1,8 +1,10 @@ using bts.api; using bts.api.core; using bts.api.synthetic; +using bts.test; using ManyConsole; using System; +using System.Linq; namespace bts { public class ServiceTest : ConsoleCommand { @@ -28,6 +30,8 @@ namespace bts { } return 0; } + + private static void synthetic_test() { using (var ctx = new ServiceContext()) { var security = new Security { diff --git a/src/data_files/files/cert_secure_logon.txt b/src/data_files/files/cert_secure_logon.txt index 04b43a8df..3987786a0 100644 --- a/src/data_files/files/cert_secure_logon.txt +++ b/src/data_files/files/cert_secure_logon.txt @@ -1,12 +1,6 @@ Session ID Access ID Secret Key Creation Date Expiration Date Environment -1U7 i9pLY5mVhWLXs7FWNb9X 8esbwiaHaqmR2rXZMkJRHt00fW6l_-ppCGoheWWuBZQ 2018-04-05 2019-04-05 CERT -1U7 ozXmORijPtJriTg6Wwny A1KOwrhH8GojNotjkCfVwHRSi_OS280xihaRZwJLFKo 2018-04-03 2018-05-03 CERT -ANS 6ogfYoF54g695tqaHsFC CtDkFnuDuStB1S05nC_pWvANb6FWsV2IMNKkmM3EcP4 2018-04-05 2019-04-05 NEWRELEASE -KTK IrUp518ekr8SzbfJGdPZ QmilC-cKgqlIiIBs_BV59fowbPfuBWn0QjeEc1dYj38 2018-04-05 2019-04-05 NEWRELEASE -M5Y bUFtyvZgPhZFCYa434ap rfZ2XLLwtHt26szWwMxYRw9uPb7jE4evEWaKuKf2uyU 2018-04-05 2019-04-05 CERT -MBX tbna9JLxT4Jlrzj0wtSS EcYqrLmR4ysSIT_NCBeC2AjDo7IAHsVZ0rOZ0cpAh_o 2018-04-05 2019-04-05 CERT MC1 0N10hKkE2B2KUt86ewd8 dJ5I52JNA-6aZZ8hnO0byVKcyqA8Of6kkstfIF89AAM 2018-04-05 2019-04-05 CERT MC5 e4uBmhQ1ebaXAeWHa7HK PNOM86eofsiCwzzKUsB5yAmrNoyZypnYD72pT2A8zgc 2018-04-05 2019-04-05 CERT MC7 S6KfCnay5UJ67P55ibHd 5lSs1TbX7N0p6Duu63_JDMghPUqBAWacvkM91MUv1uM 2018-04-05 2019-04-05 CERT MC8 AbEEtBn63WIAuItPDz1c n3ndjYb03Hx6wBO3me35HoONyDgO5TZKWk0tDSaX9KA 2018-04-05 2019-04-05 CERT -T39 UWggBgHWAe07aqW3ps2I tbb3it0rUQSSTa0TC9QcRwkrHEMDLWhaJH4VQ0FqGB4 2018-04-05 2019-04-05 NEWRELEASE +V06 WOC3GVA6l8ffrcOKUT9P Az1TJc2XHJyZ4C0S1bG_p5eWPQlVYUYhfjmdPqSGJ8o 2018-11-26 2019-11-26 NEWRELEASE diff --git a/src/lib/CMakeDeps.cmake b/src/lib/CMakeDeps.cmake index 06d5cbeda..cd221187f 100644 --- a/src/lib/CMakeDeps.cmake +++ b/src/lib/CMakeDeps.cmake @@ -1 +1 @@ -set(sources api/apicore.proto;api/apigateway.proto;api/apioptions.proto;api/core/ApiClientInterop.cpp;api/core/ApiServerInterop.cpp;api/public/ApiServer.cpp;api/public/ClientChannel.cpp;api/public/QuickbusClientChannel.cpp;api/public/ServerChannel.cpp;api/public/ServiceContext.cpp;api/service_helpers/AdminServiceUtils.cpp;api/services/AdminService.proto;api/services/ApiUnitTestService.proto;api/services/ErrorReportService.proto;api/services/HelloService.proto;api/services/MarketDataAuxiliaryService.proto;api/services/MarketDataRelay.proto;api/services/OrderService.proto;api/services/OutOfProcessURLListener.proto;api/services/PersistenceService.proto;api/services/PositionService.proto;api/services/ShellDiagnosticService.proto;api/services/ShellLatencyService.proto;api/services/SyntheticSecurityService.proto;api/services/UserService.proto;api/test/ApiTests.cpp;api/test/HelloServiceServer.cpp;config/ConfigCheck.cpp;config/ConfigDownloader.cpp;config/ConfigErrorCollector.cpp;config/ConfigLog.cpp;config/ConfigPropertyEvaluator.cpp;config/ConfigValueQueue.cpp;config/ConfigurationException.cpp;config/ConfigurationState.cpp;config/PreprocessInputStream.cpp;config/config.cpp;config/defaults/Executor.conf;config/defaults/MarketData.conf;config/defaults/Ports.conf;config/defaults/Symbols.conf;config/defaults/cme_reference_data.conf;config/defaults/edge.conf;config/defaults/jetfix.conf;config/defaults/logging.conf;config/defaults/orderman_cfg.conf;config/defaults/orders_fills_cleanup.conf;config/defaults/spreader.conf;config/defaults/testkeys.conf;config/defaults/threads.conf;config/defaults/toggles.conf;config/extensions/extensions.proto;config/invalid/invalid.proto;config/protos/ExchangeSimCfg.proto;config/protos/MarketData.proto;config/protos/Ports.proto;config/protos/Symbols.proto;config/protos/UI.proto;config/protos/cme_reference_data.proto;config/protos/jetfix.proto;config/protos/logging.proto;config/protos/mercury_cfg.proto;config/protos/orderman_cfg.proto;config/protos/orders_fills_cleanup.proto;config/protos/quickbus_cfg.proto;config/protos/spreader.proto;config/protos/system.proto;config/protos/testkeys.proto;config/protos/threads.proto;config/protos/toggles.proto;config/tests/HTTPServer.cpp;config/tests/config_ref_tests.cpp;config/tests/config_tests.cpp;config/text_format/text_format.cpp;domain_model/Security.cpp;domain_model/Security.proto;domain_model/SecurityTests.cpp;domain_model/tests/domain_tests.cpp;expression/BooleanGrammar.cpp;expression/ExpressionEvaluator.cpp;expression/ParserExceptions.cpp;expression/Value.cpp;expression/tests/expression_parser_tests.cpp;jetfix/codec/FIXArray.cpp;jetfix/common/OutFIX.cpp;jetfix/connection/AsyncReader.cpp;jetfix/connection/IConnection.cpp;jetfix/connection/SocketConnection.cpp;jetfix/gateway/CoreGateway.cpp;jetfix/gateway/JetFIXGateway.cpp;jetfix/gateway/Session.cpp;jetfix/store/FIXFileStore.cpp;jetfix/store/session_name.cpp;jetfix/tests/async_reader_tests.cpp;jetfix/tests/decoding_tests.cpp;jetfix/tests/fix_encoding_stream_tests.cpp;jetfix/tests/fix_fragment_tests.cpp;jetfix/tests/jetfix_performance_tests.cpp;jetfix/tests/sample_fix.cpp;jetfix/tests/store_tests.cpp;logging/LoggerHub.cpp;logging/Sink.cpp;logging/logging.cpp;logging/tests/logging_tests.cpp;md/Diag/MDPeriodicDumper.cpp;md/Diag/ShmDumper.cpp;md/MDConsumer.cpp;md/MDConsumerHandle.cpp;md/MDConsumerInterop.cpp;md/MDProducer.cpp;md/MDProducerHandle.cpp;md/MDRecoverableConsumer.cpp;md/MemorySegmentUtils.cpp;md/PlatformLoader.cpp;md/PriceSize.cpp;md/SecurityDB.cpp;md/SecurityIDRecorder.cpp;md/SettlementRecorder.cpp;md/Shm/FixedSecurity.cpp;md/SyntheticSecurityService.cpp;md/cme/MDP3Utils.cpp;md/common.cpp;md/protos/co2.proto;md/relay/QueryServer.cpp;md/relay/RelayClient.cpp;md/relay/RelayRecorder.cpp;md/test/Co2ManagedTestHelper.cpp;md/test/Co2TestInstrument.cpp;md/test/md2_tests.cpp;md/test/synthetic_book_merge_tests.cpp;mercury/actors/IPollableActor.cpp;mercury/broker/Broker.cpp;mercury/broker/BrokerProxy.cpp;mercury/broker/ILocalBroker.cpp;mercury/broker/IRemoteBroker.cpp;mercury/common/mercury_common.cpp;mercury/events/TimerEvent.cpp;mercury/executor/Executor.cpp;mercury/topics/Topic.cpp;metrics/metrics.cpp;metrics/system_metrics.cpp;orderman/actors/AsyncFactory.cpp;orderman/actors/ExecutionGateway.cpp;orderman/actors/FillStore.cpp;orderman/actors/MDSupplementarySource.cpp;orderman/actors/OrderStore.cpp;orderman/actors/SODPosition.cpp;orderman/actors/SecuritySrc.cpp;orderman/actors/ServiceBridge.cpp;orderman/actors/order_manager/OrderBuilder.cpp;orderman/actors/order_manager/OrderManager.cpp;orderman/actors/order_manager/OrderServicesData.cpp;orderman/events/CancelRejectEvent.cpp;orderman/events/NewExecutionReportEvent.cpp;orderman/limiter/LimitStore.cpp;orderman/limiter/Limiter.cpp;orderman/limiter/ProductLimitNode.cpp;orderman/limiter/ProductLimitTree.cpp;orderman/limiter/SecurityLimitNode.cpp;orderman/limiter/SecurityLimitTree.cpp;orderman/limiter/tests/limit_tests.cpp;orderman/order_factory/DynamicOrderRegistry.cpp;orderman/order_factory/OrderFactory.cpp;orderman/order_router/OrderRouter.cpp;orderman/orderman_utils/PerfTraceLog.cpp;orderman/orderman_utils/fix_order_codec.cpp;orderman/orders/DynamicOrder.cpp;orderman/orders/IcebergOrder.cpp;orderman/orders/NativeOrder.cpp;orderman/orders/Order.cpp;orderman/orders/TimeBoxOrder.cpp;orderman/orders/TriggerOrder.cpp;orderman/orders/book_algos/BookAlgo.cpp;orderman/orders/book_algos/CoverOrder.cpp;orderman/orders/book_algos/JoinOrder.cpp;orderman/orders/book_algos/LeanOrder.cpp;orderman/orders/book_algos/OffsetOrder.cpp;orderman/orders/book_algos/TickOrder.cpp;orderman/orders/book_algos/TopOrder.cpp;orderman/orders/spreader_orders/SpreaderOrder.cpp;orderman/orders/spreader_orders/spreader/LegPropertyData.cpp;orderman/orders/spreader_orders/spreader/QuoteLegPriceQuantityState.cpp;orderman/orders/spreader_orders/spreader/SingleFillHedger.cpp;orderman/orders/spreader_orders/spreader/SingleLegQuoter.cpp;orderman/orders/spreader_orders/spreader/SpreaderBookkeepingData.cpp;orderman/orders/spreader_orders/spreader/SpreaderChildOrderState.cpp;orderman/orders/spreader_orders/spreader/SpreaderLegData.cpp;orderman/orders/spreader_orders/spreader/SpreaderUtils.cpp;orderman/orders/spreader_orders/spreader/external_interfacing/SpreaderOrderBuilder.cpp;orderman/orders/spreader_orders/spreader/external_interfacing/SpreaderOrderServices.cpp;orderman/orders/spreader_orders/spreader/external_interfacing/SpreaderPreActivationOrderServices.cpp;orderman/orders/spreader_orders/spreader/hedger/UnhedgedDelta.cpp;orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerEndStateWorker.cpp;orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerStartStateWorker.cpp;orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerWaitingForCancelAckStateWorker.cpp;orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerWaitingForFirstAckCancelledStateWorker.cpp;orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerWaitingForFirstAckStateWorker.cpp;orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerWorkingStateWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/QuoteDriverSet.cpp;orderman/orders/spreader_orders/spreader/quoter/QuoteDriverSetHistory.cpp;orderman/orders/spreader_orders/spreader/quoter/QuoteLegDriver.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterEndStateWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterStartStateWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWaitingForCancelAckStateWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWaitingForFirstAckCancelledWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWaitingForFirstAckWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWaitingForIOCWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWaitingForSizeStateWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWorkingStateWorker.cpp;orderman/orders/spreader_orders/spreader_states/SpreaderEndStateWorker.cpp;orderman/orders/spreader_orders/spreader_states/SpreaderStartStateWorker.cpp;orderman/orders/spreader_orders/spreader_states/SpreaderWaitingForCancelAllStateWorker.cpp;orderman/orders/spreader_orders/spreader_states/SpreaderWaitingForInitialDataStateWorker.cpp;orderman/orders/spreader_orders/spreader_states/SpreaderWorkingStateWorker.cpp;orderman/orders/spreader_orders/tests/spreader_tests.cpp;orderman/server/OrderServiceServer.cpp;orderman/tests/fat_wrapper_tests.cpp;orderman2/orders/NativeOrder.cpp;orderman2/orders/Order.cpp;os/os.cpp;os/tests/os_tests.cpp;persistence/IStore.cpp;persistence/PersistenceServiceServer.cpp;persistence/SqliteStore.cpp;persistence/persistence_utils.cpp;persistence/tests/PersistenceServiceTests.cpp;plugin/SparkServices.cpp;plugin/plugin.cpp;quickbus/core/LocalNode.cpp;quickbus/core/Quickbus.cpp;quickbus/core/SubscriptionID.cpp;quickbus/core/TableID.cpp;quickbus/message_model/Update.cpp;quickbus/message_model/merge_updates.cpp;quickbus/network/QBConnection.cpp;quickbus/network/QBConnectionManager.cpp;quickbus/network/endpoint_description.cpp;quickbus/network/quickbus_msgs.proto;quickbus/pubsub/TablePublisher.cpp;quickbus/pubsub/TableSubscriber.cpp;quickbus/pubsub/tests/qb_pubsub_tests.cpp;quickbus/routing/INode.cpp;quickbus/routing/NodeID.cpp;quickbus/routing/Router.cpp;quickbus/rpc/RPCClient.cpp;quickbus/rpc/RPCServer.cpp;quickbus/rpc/RPCSessionID.cpp;quickbus/rpc/rpc_utils.cpp;quickbus/rpc/tests/qb_rpc_tests.cpp;quickbus/tests/quickbus_tests.cpp;sparkproto/SparkProtos.proto;testing/catch_test_runner.cpp;tracing/PerfLog.cpp;utils/AuthToken.cpp;utils/Dispatcher.cpp;utils/GrowableSPSCQueue.cpp;utils/HTTPStream.cpp;utils/PBUtils.cpp;utils/Puid.cpp;utils/SecureLogon.cpp;utils/SharedMemory.cpp;utils/Sqlite_utils.cpp;utils/Uuid.cpp;utils/datetime.cpp;utils/download.cpp;utils/file_utils.cpp;utils/init_spark_lib.cpp;utils/is_unittest_environment.cpp;utils/stats.cpp;utils/thread_manager.cpp) \ No newline at end of file +set(sources api/apicore.proto;api/apigateway.proto;api/apioptions.proto;api/core/ApiClientInterop.cpp;api/core/ApiServerInterop.cpp;api/public/ApiServer.cpp;api/public/ClientChannel.cpp;api/public/QuickbusClientChannel.cpp;api/public/ServerChannel.cpp;api/public/ServiceContext.cpp;api/service_helpers/AdminServiceUtils.cpp;api/services/AdminService.proto;api/services/ApiUnitTestService.proto;api/services/ErrorReportService.proto;api/services/HelloService.proto;api/services/MarketDataAuxiliaryService.proto;api/services/MarketDataRelay.proto;api/services/OrderService.proto;api/services/OutOfProcessURLListener.proto;api/services/PersistenceService.proto;api/services/PositionService.proto;api/services/ShellDiagnosticService.proto;api/services/ShellLatencyService.proto;api/services/SyntheticSecurityService.proto;api/services/UserService.proto;api/test/ApiTests.cpp;api/test/HelloServiceServer.cpp;config/ConfigCheck.cpp;config/ConfigDownloader.cpp;config/ConfigErrorCollector.cpp;config/ConfigLog.cpp;config/ConfigPropertyEvaluator.cpp;config/ConfigValueQueue.cpp;config/ConfigurationException.cpp;config/ConfigurationState.cpp;config/PreprocessInputStream.cpp;config/config.cpp;config/defaults/Executor.conf;config/defaults/MarketData.conf;config/defaults/Ports.conf;config/defaults/Symbols.conf;config/defaults/cme_reference_data.conf;config/defaults/edge.conf;config/defaults/jetfix.conf;config/defaults/logging.conf;config/defaults/orderman_cfg.conf;config/defaults/orders_fills_cleanup.conf;config/defaults/spreader.conf;config/defaults/testkeys.conf;config/defaults/threads.conf;config/defaults/toggles.conf;config/extensions/extensions.proto;config/invalid/invalid.proto;config/protos/ExchangeSimCfg.proto;config/protos/MarketData.proto;config/protos/Ports.proto;config/protos/Symbols.proto;config/protos/UI.proto;config/protos/cme_reference_data.proto;config/protos/jetfix.proto;config/protos/logging.proto;config/protos/mercury_cfg.proto;config/protos/orderman_cfg.proto;config/protos/orders_fills_cleanup.proto;config/protos/quickbus_cfg.proto;config/protos/spreader.proto;config/protos/system.proto;config/protos/testkeys.proto;config/protos/threads.proto;config/protos/toggles.proto;config/tests/HTTPServer.cpp;config/tests/config_ref_tests.cpp;config/tests/config_tests.cpp;config/text_format/text_format.cpp;domain_model/Security.cpp;domain_model/Security.proto;domain_model/SecurityTests.cpp;domain_model/tests/domain_tests.cpp;expression/BooleanGrammar.cpp;expression/ExpressionEvaluator.cpp;expression/ParserExceptions.cpp;expression/Value.cpp;expression/tests/expression_parser_tests.cpp;jetfix/codec/FIXArray.cpp;jetfix/common/OutFIX.cpp;jetfix/connection/AsyncReader.cpp;jetfix/connection/IConnection.cpp;jetfix/connection/SocketConnection.cpp;jetfix/gateway/CoreGateway.cpp;jetfix/gateway/JetFIXGateway.cpp;jetfix/gateway/Session.cpp;jetfix/store/FIXFileStore.cpp;jetfix/store/session_name.cpp;jetfix/tests/async_reader_tests.cpp;jetfix/tests/decoding_tests.cpp;jetfix/tests/fix_encoding_stream_tests.cpp;jetfix/tests/fix_fragment_tests.cpp;jetfix/tests/jetfix_performance_tests.cpp;jetfix/tests/sample_fix.cpp;jetfix/tests/store_tests.cpp;logging/LoggerHub.cpp;logging/Sink.cpp;logging/logging.cpp;logging/tests/logging_tests.cpp;md/Diag/MDPeriodicDumper.cpp;md/Diag/ShmDumper.cpp;md/MDConsumer.cpp;md/MDConsumerHandle.cpp;md/MDConsumerInterop.cpp;md/MDProducer.cpp;md/MDProducerHandle.cpp;md/MDRecoverableConsumer.cpp;md/MemorySegmentUtils.cpp;md/PlatformLoader.cpp;md/PriceSize.cpp;md/SecurityDB.cpp;md/SecurityIDRecorder.cpp;md/SettlementRecorder.cpp;md/Shm/FixedSecurity.cpp;md/SyntheticSecurityService.cpp;md/cme/MDP3Utils.cpp;md/common.cpp;md/protos/co2.proto;md/relay/QueryServer.cpp;md/relay/RelayClient.cpp;md/relay/RelayRecorder.cpp;md/test/Co2ManagedTestHelper.cpp;md/test/Co2TestInstrument.cpp;md/test/md2_tests.cpp;md/test/synthetic_book_merge_tests.cpp;mercury/actors/IPollableActor.cpp;mercury/broker/Broker.cpp;mercury/broker/BrokerProxy.cpp;mercury/broker/ILocalBroker.cpp;mercury/broker/IRemoteBroker.cpp;mercury/common/mercury_common.cpp;mercury/events/TimerEvent.cpp;mercury/executor/Executor.cpp;mercury/topics/Topic.cpp;metrics/metrics.cpp;metrics/system_metrics.cpp;orderman/actors/AsyncFactory.cpp;orderman/actors/ExecutionGateway.cpp;orderman/actors/FillStore.cpp;orderman/actors/MDSupplementarySource.cpp;orderman/actors/OrderStore.cpp;orderman/actors/SODPosition.cpp;orderman/actors/SecuritySrc.cpp;orderman/actors/ServiceBridge.cpp;orderman/actors/order_manager/OrderBuilder.cpp;orderman/actors/order_manager/OrderManager.cpp;orderman/actors/order_manager/OrderServicesData.cpp;orderman/events/CancelRejectEvent.cpp;orderman/events/NewExecutionReportEvent.cpp;orderman/limiter/LimitStore.cpp;orderman/limiter/Limiter.cpp;orderman/limiter/ProductLimitNode.cpp;orderman/limiter/ProductLimitTree.cpp;orderman/limiter/SecurityLimitNode.cpp;orderman/limiter/SecurityLimitTree.cpp;orderman/limiter/tests/limit_tests.cpp;orderman/order_factory/DynamicOrderRegistry.cpp;orderman/order_factory/OrderFactory.cpp;orderman/order_router/OrderRouter.cpp;orderman/orderman_utils/PerfTraceLog.cpp;orderman/orderman_utils/fix_order_codec.cpp;orderman/orders/DynamicOrder.cpp;orderman/orders/IcebergOrder.cpp;orderman/orders/NativeOrder.cpp;orderman/orders/Order.cpp;orderman/orders/TimeBoxOrder.cpp;orderman/orders/TriggerOrder.cpp;orderman/orders/book_algos/BookAlgo.cpp;orderman/orders/book_algos/CoverOrder.cpp;orderman/orders/book_algos/JoinOrder.cpp;orderman/orders/book_algos/LeanOrder.cpp;orderman/orders/book_algos/OffsetOrder.cpp;orderman/orders/book_algos/TickOrder.cpp;orderman/orders/book_algos/TopOrder.cpp;orderman/orders/spreader_orders/SpreaderOrder.cpp;orderman/orders/spreader_orders/spreader/LegPropertyData.cpp;orderman/orders/spreader_orders/spreader/QuoteLegPriceQuantityState.cpp;orderman/orders/spreader_orders/spreader/SingleFillHedger.cpp;orderman/orders/spreader_orders/spreader/SingleLegQuoter.cpp;orderman/orders/spreader_orders/spreader/SpreaderBookkeepingData.cpp;orderman/orders/spreader_orders/spreader/SpreaderChildOrderState.cpp;orderman/orders/spreader_orders/spreader/SpreaderLegData.cpp;orderman/orders/spreader_orders/spreader/SpreaderUtils.cpp;orderman/orders/spreader_orders/spreader/external_interfacing/SpreaderOrderBuilder.cpp;orderman/orders/spreader_orders/spreader/external_interfacing/SpreaderOrderServices.cpp;orderman/orders/spreader_orders/spreader/external_interfacing/SpreaderPreActivationOrderServices.cpp;orderman/orders/spreader_orders/spreader/hedger/UnhedgedDelta.cpp;orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerEndStateWorker.cpp;orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerStartStateWorker.cpp;orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerWaitingForCancelAckStateWorker.cpp;orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerWaitingForFirstAckCancelledStateWorker.cpp;orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerWaitingForFirstAckStateWorker.cpp;orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerWorkingStateWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/QuoteDriverSet.cpp;orderman/orders/spreader_orders/spreader/quoter/QuoteDriverSetHistory.cpp;orderman/orders/spreader_orders/spreader/quoter/QuoteLegDriver.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterEndStateWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterStartStateWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWaitingForCancelAckStateWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWaitingForFirstAckCancelledWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWaitingForFirstAckWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWaitingForIOCWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWaitingForSizeStateWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWorkingStateWorker.cpp;orderman/orders/spreader_orders/spreader_states/SpreaderEndStateWorker.cpp;orderman/orders/spreader_orders/spreader_states/SpreaderStartStateWorker.cpp;orderman/orders/spreader_orders/spreader_states/SpreaderWaitingForCancelAllStateWorker.cpp;orderman/orders/spreader_orders/spreader_states/SpreaderWaitingForInitialDataStateWorker.cpp;orderman/orders/spreader_orders/spreader_states/SpreaderWorkingStateWorker.cpp;orderman/orders/spreader_orders/tests/spreader_tests.cpp;orderman/server/OrderServiceServer.cpp;orderman/tests/fat_wrapper_tests.cpp;orderman2/OrderManager2.cpp;os/os.cpp;os/tests/os_tests.cpp;persistence/IStore.cpp;persistence/PersistenceServiceServer.cpp;persistence/SqliteStore.cpp;persistence/persistence_utils.cpp;persistence/tests/PersistenceServiceTests.cpp;plugin/SparkServices.cpp;plugin/plugin.cpp;quickbus/core/LocalNode.cpp;quickbus/core/Quickbus.cpp;quickbus/core/SubscriptionID.cpp;quickbus/core/TableID.cpp;quickbus/message_model/Update.cpp;quickbus/message_model/merge_updates.cpp;quickbus/network/QBConnection.cpp;quickbus/network/QBConnectionManager.cpp;quickbus/network/endpoint_description.cpp;quickbus/network/quickbus_msgs.proto;quickbus/pubsub/TablePublisher.cpp;quickbus/pubsub/TableSubscriber.cpp;quickbus/pubsub/tests/qb_pubsub_tests.cpp;quickbus/routing/INode.cpp;quickbus/routing/NodeID.cpp;quickbus/routing/Router.cpp;quickbus/rpc/RPCClient.cpp;quickbus/rpc/RPCServer.cpp;quickbus/rpc/RPCSessionID.cpp;quickbus/rpc/rpc_utils.cpp;quickbus/rpc/tests/qb_rpc_tests.cpp;quickbus/tests/quickbus_tests.cpp;sparkproto/SparkProtos.proto;testing/catch_test_runner.cpp;utils/AuthToken.cpp;utils/Dispatcher.cpp;utils/GrowableSPSCQueue.cpp;utils/HTTPStream.cpp;utils/PBUtils.cpp;utils/Puid.cpp;utils/SecureLogon.cpp;utils/SharedMemory.cpp;utils/Sqlite_utils.cpp;utils/Uuid.cpp;utils/datetime.cpp;utils/download.cpp;utils/file_utils.cpp;utils/init_spark_lib.cpp;utils/is_unittest_environment.cpp;utils/stats.cpp;utils/thread_manager.cpp) \ No newline at end of file diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 90ed995df..65064d4d2 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -54,11 +54,27 @@ if(NOT old_config_proto_str STREQUAL config_proto_str) file(WRITE "${config_proto_file}" "${config_proto_str}") endif() -# copy defaults to output directory +# generate static defaults +set(config_defaults_file ${CMAKE_CURRENT_BINARY_DIR}/config_defaults.h) +# Defaults cannot be a single string because the compiler complains about a string longer than 65k +set(config_defaults_str "const char * config_static_defaults[] = { ") foreach (cfg_file_path ${Conf_Defaults}) - get_filename_component(cfg_file_name ${cfg_file_path} NAME) - configure_file(${cfg_file_path} ${CMAKE_BINARY_DIR}/src/server/sparkd/defaults/${cfg_file_name}) + file(READ ${cfg_file_path} cfg_file_content) + string(REPLACE "\"" "\\\"" cfg_file_content_escaped ${cfg_file_content}) + string(REPLACE "\n" ";" cfg_lines ${cfg_file_content_escaped}) + foreach(line ${cfg_lines}) + string(APPEND config_defaults_str "\n \"${line}\",") + endforeach(line) endforeach(cfg_file_path) +string(APPEND config_defaults_str "};") +set(old_defaults_str "") +if(EXISTS ${config_defaults_file}) + file(READ ${config_defaults_file} old_defaults_str) +endif() +if(NOT config_defaults_str STREQUAL old_defaults_str) + file(WRITE "${config_defaults_file}" "${config_defaults_str}") +endif() + # lib if (WIN32) @@ -125,4 +141,4 @@ if (WIN32) include(${CMAKE_SOURCE_DIR}/tools/vs_filters.cmake) endif() - + \ No newline at end of file diff --git a/src/lib/api/apigateway.proto b/src/lib/api/apigateway.proto index aa2f10466..f55413bba 100644 --- a/src/lib/api/apigateway.proto +++ b/src/lib/api/apigateway.proto @@ -10,6 +10,7 @@ message GatewayLoginResult { bool is_valid = 1; string reason = 2; string token = 3; + bool can_create = 4; } message GatewayCallHeader { int32 request_id = 1; diff --git a/src/lib/api/service_compiler/templates/excel/excel.pb.cs b/src/lib/api/service_compiler/templates/excel/excel.pb.cs index 1ed7feef3..9bde3fd92 100644 --- a/src/lib/api/service_compiler/templates/excel/excel.pb.cs +++ b/src/lib/api/service_compiler/templates/excel/excel.pb.cs @@ -25,14 +25,9 @@ namespace {{package}} // {{comment}} public partial class {{name}}_Excel : IDisposable { - readonly static Lazy<{{name}}> _service = new Lazy<{{name}}>(() => locate<{{name}}>(), true); - static T locate() where T : class, IApiClient - { - using (var ctx = new api.core.ServiceContext()) - { - return ctx.locate(); - } - } + readonly static object _lock = new object(); + readonly static Lazy<{{name}}> _service = new Lazy<{{name}}>(() => bts.api.Locator.locate<{{name}}>(), true); + public void Dispose() { @@ -80,6 +75,54 @@ public void Dispose() {{#unless skip_excel_generation}} + [ExcelFunction(Category = "BTS", Description = "Call BTS Spark {{../lname}} API Method {{lname}} with parameter {{input_type_full}}")] + async public static void spark_{{../lname}}_{{lname}}_async (object[,] parameters, ExcelAsyncHandle handle, bool show_headers = false, bool display_vertically = false) + { + try + { + Google.Protobuf.IMessage req = null; + {{input_type_full}} casted_req = null; + try + { + if(parameters.Rank == 2 && parameters.GetLength(0) == 1 && parameters.GetLength(1) == 1) + { + if(parameters[0,0] == ExcelMissing.Value) + req = (Google.Protobuf.IMessage) Activator.CreateInstance(typeof({{input_type_full}})); + else if(parameters[0,0] is string json) + req = APIDispatch.generate_imessage(typeof({{input_type_full}}), json); + } + if(req == null) + { + string json = JsonFormatter.parse_json(typeof({{input_type_full}}), parameters); + req = APIDispatch.generate_imessage(typeof({{input_type_full}}), json); + } + casted_req = ({{input_type_full}}) req; + } + catch + { + var members = bts.excel.extensions.ReflectionExtensions + .get_fields_or_properties(typeof({{input_type_full}})) + .Where(x => !DataParser.excluded_member(x)); + handle.SetResult( + "Error in calling method {{lname}}( {{input_type_full}} ), input members are: " + + string.Join(",", members.Select(x => x.Name).ToArray()) + ); + } + + var res = await _service.Value.{{name}}_async( casted_req ); + object res_res = res.value; + object[,] scattered = new JsonFormatter(res_res).format(show_headers); + if(display_vertically) + scattered = bts.excel.Utilities.transpose_keep_dimension(scattered); + handle.SetResult(scattered); + } + catch(Exception ex) + { + Trace.TraceError(ex.ToString()); + handle.SetException(ex); + } + } + [ExcelFunction(Category = "BTS", Description = "Call BTS Spark {{../lname}} API Method {{lname}} with parameter {{input_type_full}}")] public static object spark_{{../lname}}_{{lname}} (object[,] parameters, bool show_headers = false, bool display_vertically = false) { @@ -113,7 +156,7 @@ public void Dispose() .Where(x => !DataParser.excluded_member(x)); return "Error in calling method {{lname}}( {{input_type_full}} ), input members are: " + string.Join(",", members.Select(x => x.Name).ToArray()); - } + } {{/unless}} {{/if}} diff --git a/src/lib/api/service_helpers/AdminServiceUtils.cpp b/src/lib/api/service_helpers/AdminServiceUtils.cpp index 72e559e81..ca30f9f61 100644 --- a/src/lib/api/service_helpers/AdminServiceUtils.cpp +++ b/src/lib/api/service_helpers/AdminServiceUtils.cpp @@ -846,12 +846,35 @@ void AdminServiceUtils::find_user_trading_accounts (const bts::api::admin::Admin const bts::api::admin::UserAccountPermissions* user_perm_ptr = get_user_permissions (admin_data, user_id); if (user_perm_ptr != nullptr) for(auto it=user_perm_ptr->account_permissions().begin(); it!=user_perm_ptr->account_permissions().end(); it++) - if (it->second.has_trading_permission()){ + if (it->second.has_trading_permission() && it->second.trading_permission().has_permissions()){ const api::admin::BTSAccount* account_ptr = find_account(admin_data, it->first); if (account_ptr != nullptr) associated_accounts.push_back(account_ptr); } } + +// for a given account, fills in the associated_users ref arg +// with the users that can trade into the account +void AdminServiceUtils::find_users_for_trading_account (const AdminData& admin_data, + uint32_t account_id, + std::vector& associated_users) +{ + for(const auto& u : AdminServiceUtils::users(admin_data, false)) + { + const auto user_perm_ptr = get_user_permissions (admin_data, u->id()); + if (user_perm_ptr) + { + const auto& permission_unit = user_perm_ptr->account_permissions().find(account_id); + if(permission_unit != user_perm_ptr->account_permissions().end() && permission_unit->second.has_trading_permission() && + permission_unit->second.trading_permission().has_permissions()) + { + associated_users.push_back(u); + } + } + } +} + + void AdminServiceUtils::validate_user_update (const bts::api::admin::AdminData& admin_data, const bts::api::admin::BTSUser& updated_user, bts::api::admin::AdminServiceOperationResult& result){ @@ -891,7 +914,7 @@ void AdminServiceUtils::get_md_entitlement_report(const AdminData& admin_data, admin_data); if(cme_data!=nullptr){ for (const auto& cme_mic_data : cme_data->md_permissions()){ - MDEntitlementReportUnit rv=get_cme_md_entitlement_unit(user.name(), + MDEntitlementReportUnit rv=get_cme_md_entitlement_unit(user, cme_mic_data); entitlements.push_back(rv); } @@ -899,10 +922,11 @@ void AdminServiceUtils::get_md_entitlement_report(const AdminData& admin_data, } } MDEntitlementReportUnit AdminServiceUtils::get_cme_md_entitlement_unit( - const std::string& user, + const BTSUser& user, const CMEMicData& cme_mic_data){ MDEntitlementReportUnit rv; - rv.set_user(user); + rv.set_user(user.name()); + rv.set_user_id(user.id()); rv.set_exchange("GLBX"); switch(cme_mic_data.mic()) { @@ -974,6 +998,8 @@ bts::api::admin::BTSUser* AdminServiceUtils::create_user (bts::api::admin::Admin uint32_t parent_group_id, const std::string& name, const std::string& password, + const std::string& full_name, + const std::string& company, bool is_active, const bts::api::admin::LicenseData& license_data, const bts::api::admin::LicenseEntitlements& license_entitlements, @@ -999,6 +1025,8 @@ bts::api::admin::BTSUser* AdminServiceUtils::create_user (bts::api::admin::Admin new_user_ptr->set_parent_group_id(parent_group_id); new_user_ptr->set_name(name); new_user_ptr->set_password (password); + new_user_ptr->set_full_name (full_name); + new_user_ptr->set_company (company); new_user_ptr->set_is_active(is_active); new_user_ptr->mutable_license_data()->CopyFrom(license_data); new_user_ptr->mutable_license_entitlements()->CopyFrom(license_entitlements); @@ -1268,13 +1296,14 @@ void AdminServiceUtils::bootstrap_data (bts::api::admin::AdminData& data){ auto def_group = create_group(data, 0, std::string("default"), result); // adding users to the group bts::api::admin::LicenseData license_data; - bts::api::admin::LicenseEntitlements license_entitlements; - auto user_1 = create_user(data, def_group->id(), std::string("bts"), std::string(""), false, license_data, license_entitlements, user_result); user_1->set_is_active(true); - auto user_2 = create_user(data, def_group->id(), std::string("bts_2"), std::string("bts_2"), false, license_data, license_entitlements, user_result); user_2->set_is_active(true); - auto user_3 = create_user(data, def_group->id(), std::string("bts_3"), std::string("bts_3"), false, license_data, license_entitlements, user_result); user_3->set_is_active(true); + bts::api::admin::LicenseEntitlements license_entitlements; std::string empty(""); + auto user_1 = create_user(data, def_group->id(), std::string("bts"), std::string(""), empty, empty, false, license_data, license_entitlements, user_result); user_1->set_is_active(true); + auto user_2 = create_user(data, def_group->id(), std::string("bts_2"), std::string("bts_2"), empty, empty, false, license_data, license_entitlements, user_result); user_2->set_is_active(true); + auto user_3 = create_user(data, def_group->id(), std::string("bts_3"), std::string("bts_3"), empty, empty, false, license_data, license_entitlements, user_result); user_3->set_is_active(true); //associate users bts::api::admin::UserAccountPermissionUnit permission_unit; permission_unit.mutable_trading_permission()->set_submit_market_orders(true); + permission_unit.mutable_trading_permission()->set_has_permissions(true); permission_unit.mutable_admin_permission()->set_has_permissions(true); bts::api::admin::UserAccountPermissions account_permissions; account_permissions.mutable_account_permissions()->insert(google::protobuf::MapPair(parent_account->id(), permission_unit)); diff --git a/src/lib/api/service_helpers/AdminServiceUtils.h b/src/lib/api/service_helpers/AdminServiceUtils.h index 9836c65ee..781a82362 100644 --- a/src/lib/api/service_helpers/AdminServiceUtils.h +++ b/src/lib/api/service_helpers/AdminServiceUtils.h @@ -217,6 +217,12 @@ public: const AdminData& admin_data, uint32_t user_id, std::vector& associated_accounts); + // for a given account, fills in the associated_users ref arg + // with the users that can trade into the account + static void find_users_for_trading_account ( + const AdminData& admin_data, + uint32_t account_id, + std::vector& associated_users); // validates that changes in user data satisfy all the // constraints static void validate_user_update (const AdminData& admin_data, @@ -230,7 +236,7 @@ public: std::vector& entitlements); // Gets a reporting unit out of CMEMicData static MDEntitlementReportUnit get_cme_md_entitlement_unit( - const std::string& user, + const BTSUser& user, const CMEMicData& cme_mic_data); static void get_user_symbol_permissions( const AdminData& data, @@ -243,6 +249,8 @@ public: uint32_t parent_group_id, const std::string& name, const std::string& password, + const std::string& full_name, + const std::string& company, bool is_active, const LicenseData& license_data, const LicenseEntitlements& license_entitlements, diff --git a/src/lib/api/services/AdminService.proto b/src/lib/api/services/AdminService.proto index 166a38a0d..c671fb4d0 100644 --- a/src/lib/api/services/AdminService.proto +++ b/src/lib/api/services/AdminService.proto @@ -54,9 +54,12 @@ message BTSUser{ uint32 parent_group_id = 20; string name = 30; string password = 40; + string full_name = 42; + string company = 44; bool is_active = 50; - LicenseData license_data = 60; - LicenseEntitlements license_entitlements = 70; + bool can_create = 55; + LicenseData license_data = 60; //unused + LicenseEntitlements license_entitlements = 70; //unused BTSUserDerivableData user_data = 80; } @@ -89,21 +92,23 @@ message LicenseEntitlements{ } message AlgoTradingPermissionsUnit{ - bool submit_iceberg_orders = 10; - bool submit_time_box_orders = 20; - bool submit_spreader_orders = 30; + bool submit_iceberg_orders = 10; //unused + bool submit_time_box_orders = 20; //unused + bool submit_spreader_orders = 30; //unused } message TradingPermissionUnit{ - bool submit_market_orders = 10; - bool submit_gtc_orders = 20; - AlgoTradingPermissionsUnit algo_trading_permission = 30; + bool has_permissions = 5; + bool submit_market_orders = 10; //unused + bool submit_gtc_orders = 20; //unused + AlgoTradingPermissionsUnit algo_trading_permission = 30; //unused } message AdminPermissionUnit{ // TODO: needs to be more ellaborate (account writing, // reading etc, routing etc) bool has_permissions = 10; + bool has_md_permissions = 20; } // this is the functionality permissions @@ -113,6 +118,7 @@ message UserAccountPermissionUnit{ } message UserAccountPermissions{ + //uint32 = account_id map account_permissions = 10; } @@ -283,6 +289,18 @@ message SIMAccountData { string clearing_account = 40; } +enum ProfessionalDesignation +{ + PROFESSIONALDESIGNATION_PRO = 0; + PROFESSIONALDESIGNATION_NONPRO = 1; +} + +enum DisplayDesignation +{ + DISPLAYDESIGNATION_DISPLAY = 0; + DISPLAYDESIGNATION_NONDISPLAY = 1; +} + message CMEUserData{ string operator_id = 10; string ats_operator_id = 20; @@ -293,7 +311,11 @@ message CMEUserData{ string smp_instruction = 70; string max_order_rate_per_connection = 80; string location = 90; - // add suff here + ProfessionalDesignation pro_nonpro = 100; + DisplayDesignation display_nondisplay = 110; + + enum AdminDisplay { All = 0; MD = 1; Routing = 2; None = 100; } + AdminDisplay admin_display_flag = 120; repeated CMEMicData md_permissions = 1000; } @@ -377,6 +399,7 @@ message OrderCancelRequest{ message MDEntitlementReportUnit{ string record_id = 1 [(bts.api.key)=true]; string user = 10; + uint32 user_id=11; string exchange = 20; string mic = 30; bool enabled = 40; @@ -400,6 +423,7 @@ message AccountCreateAPIArgument{ uint32 parent_account_id = 10; string account_name = 20; string description = 30; + string creator_user = 40; } message AccountUpdateAPIArgument{ BTSAccount complete_data=10; @@ -408,6 +432,8 @@ message UserCreateAPIArgument{ uint32 parent_group_id = 20; string name = 30; string password = 40; + string full_name = 42; + string company = 44; LicenseData license_data = 50; LicenseEntitlements license_entitlements = 70; } @@ -433,6 +459,10 @@ message AdminServiceCreateAccountResult { uint32 new_id = 30; } +message FilteredAdminDataRequest { + string token = 1; +} + service AdminService { option (bts.api.service_description) = "Provides a management interface to the user model"; // account @@ -446,6 +476,7 @@ service AdminService { // subscription rpc admin_data(bts.api.VoidMessage) returns (stream AdminData); rpc get_admin_data(bts.api.VoidMessage) returns (AdminData); + rpc get_filtered_admin_data(FilteredAdminDataRequest) returns (AdminData); // orders rpc get_order_summary(bts.api.VoidMessage) returns (OrdersSummary); rpc cancel_orders(OrderCancelRequest) returns (bts.api.VoidMessage); diff --git a/src/lib/api/services/UserService.proto b/src/lib/api/services/UserService.proto index f5aff089a..f6a59ecb4 100644 --- a/src/lib/api/services/UserService.proto +++ b/src/lib/api/services/UserService.proto @@ -47,6 +47,7 @@ message AuthenticateLoginResponse { string reason = 2; AuthToken token = 3; uint32 user_id = 4; + bool can_create = 5; } message AuthenticateTokenRequest {AuthToken token = 1;} message AuthenticateTokenResponse {bool is_valid = 1; string reason = 2; User user = 3;} diff --git a/src/lib/config/ConfigurationState.cpp b/src/lib/config/ConfigurationState.cpp index 06ec87f36..df1f97e64 100755 --- a/src/lib/config/ConfigurationState.cpp +++ b/src/lib/config/ConfigurationState.cpp @@ -38,6 +38,7 @@ #endif #include "lib/config_proto_files.h" +#include "lib/config_defaults.h" using namespace std; @@ -77,12 +78,6 @@ ConfigurationState::~ConfigurationState(void) { } -std::string ConfigurationState::defaults_path() -{ - std::string appdir = os::get_install_path(); - return appdir + "/defaults/"; -} - std::string get_command_argument(const char* key) { std::vector cmd_line = os::get_command_line(); @@ -127,18 +122,18 @@ void ConfigurationState::initialize_defaults(IConfigLog& log) std::shared_ptr new_message(_prototype->New()); ErrorsOnlyLog elog(log); - load_message(defaults_path(), *new_message.get(), elog, *_deferred_queue.get()); + + std::string defaults; + for (const char* str : config_static_defaults) { + defaults += str; + defaults += "\n"; + } + + proto::io::ArrayInputStream input_stream(defaults.c_str(), (int)defaults.length()); + parse_stream("static_defaults.conf", input_stream, *new_message.get(), elog, *_deferred_queue.get()); _defaults = new_message; - // If defaults has an include process that now - // FEATURE: Unlike settings loaded from ~/sparkdata/ these includes - // take precedence over the settings in the file which includes them. - // While this seems backwards it is always the behavior you want - std::string include = get_include(*_defaults.get()); - if (!include.empty()) - { - load(include, "", log); - } + // do not process 'include' for static defaults _is_initialized = true; } diff --git a/src/lib/config/ConfigurationState.h b/src/lib/config/ConfigurationState.h index 99c978a41..440c16e14 100755 --- a/src/lib/config/ConfigurationState.h +++ b/src/lib/config/ConfigurationState.h @@ -81,7 +81,6 @@ namespace internal { void generate_all_config_proto(IConfigLog&); const proto::Message* try_get_value(const std::string& field_name, const proto::Message& message) const; - std::string defaults_path(); std::string settings_path(); bool _is_initialized; diff --git a/src/lib/config/defaults/Executor.conf b/src/lib/config/defaults/Executor.conf deleted file mode 100644 index 2fed6e7bc..000000000 --- a/src/lib/config/defaults/Executor.conf +++ /dev/null @@ -1,13 +0,0 @@ -ExecutorCfg -{ - value - { - # executor for latency sensitive code - executor { affinity: 0 yield_cpu: false } - - # normal executor - executor { affinity: -1 yield_cpu: true } - } -} - - diff --git a/src/lib/domain_model/Security.h b/src/lib/domain_model/Security.h index f88a63be4..0647fa261 100644 --- a/src/lib/domain_model/Security.h +++ b/src/lib/domain_model/Security.h @@ -80,6 +80,10 @@ inline Price round_to_quote_price(api::Security const&sec, Price in, api::Side s else return Price(raw_round_to_quote_price(p,sec.contract_spec().low_tick(),side)); } + +// Looking to round md::IntPrice? Look in IntPrice.h + + // computes the difference between 2 prices in ticks. // the result is an a signed int so the order of args // matter, its second price - first price diff --git a/src/lib/domain_model/Security.proto b/src/lib/domain_model/Security.proto index 3d2b5f738..5e921021e 100644 --- a/src/lib/domain_model/Security.proto +++ b/src/lib/domain_model/Security.proto @@ -53,7 +53,11 @@ enum CMEMics { } enum ICEMics{ - ICE_FUTURES_CANADA=0; + ICE_UNSET=0; + ICE_US = 1; + ICE_EU = 2; + ICE_LIFFE = 3; + ICE_CA = 4; } enum Side { diff --git a/src/lib/logging/Logger.h b/src/lib/logging/Logger.h index f09a10adb..9a6aa5083 100644 --- a/src/lib/logging/Logger.h +++ b/src/lib/logging/Logger.h @@ -140,7 +140,7 @@ public: ~Logger() { -#ifndef WIN32 +#ifdef false //This breaks .net core and windows assert(!_active); assert(_wcursor == 0); #endif diff --git a/src/lib/logging/logging.cpp b/src/lib/logging/logging.cpp index 3c7e1bffd..82acc96a7 100644 --- a/src/lib/logging/logging.cpp +++ b/src/lib/logging/logging.cpp @@ -193,7 +193,7 @@ LoggingConfigPoller::~LoggingConfigPoller () _poller.stop(); } -#ifdef _WIN32 + namespace interop { const char* intern(const char* str) { @@ -205,7 +205,11 @@ const char* intern(const char* str) { return *iter; } else { +#ifdef _WIN32 const char* v = _strdup(str); +#else + const char* v = strdup(str); +#endif set.insert(v); return v; } @@ -218,7 +222,6 @@ extern "C" BTS_EXPORT void Logger_log (int level, int subsystem, const char *mes } } } -#endif }} diff --git a/src/lib/logging/logging.h b/src/lib/logging/logging.h index dc4e2281f..919234a6e 100644 --- a/src/lib/logging/logging.h +++ b/src/lib/logging/logging.h @@ -42,7 +42,8 @@ constexpr log::Subsystem Mercury {ExSim.ordinal+1 }; constexpr log::Subsystem Testing {Mercury.ordinal+1 }; constexpr log::Subsystem Latency {Testing.ordinal+1 }; constexpr log::Subsystem DataFlow {Latency.ordinal+1 }; -constexpr log::Subsystem Plugin {DataFlow.ordinal+1 }; +constexpr log::Subsystem Plugin {DataFlow.ordinal+1 }; +constexpr log::Subsystem ClientSdk {Plugin.ordinal+1 }; struct LoggerHandle { LoggerHandle(LoggerHandle const&) = delete; diff --git a/src/lib/md/IntPrice.h b/src/lib/md/IntPrice.h index c3c6c3573..6aed44e42 100644 --- a/src/lib/md/IntPrice.h +++ b/src/lib/md/IntPrice.h @@ -1,10 +1,13 @@ #pragma once #include "lib/utils/bts_assert.h" #include "lib/utils/bts_array_size.h" +#include "lib/domain_model/Security.pb.h" namespace bts { namespace md { +const extern double NO_PRICE; + static const double powers_10[] = { 1E-20, 1E-19, 1E-18, 1E-17, 1E-16, 1E-15, 1E-14, 1E-13, 1E-12, 1E-11, 1E-10, 1E-9, 1E-8, 1E-7, 1E-6, 1E-5, 1E-4, 1E-3, 1E-2, 1E-1, 1E0, @@ -35,14 +38,12 @@ class IntPrice { IntPrice(const IntPrice& other) : _mantissa(other._mantissa), _exponent(other._exponent) {} bool operator==(const IntPrice& other) const { - // this requires both mantissa and exponent to be equal - // logically 100*pow10(1) == 10*pow10(2) - // HOWEVER, once converted to double there are subtelties that can make them not equal so - // this function is conservative - if(_exponent == other._exponent) + if(_exponent == other._exponent) { return _mantissa == other._mantissa; - else + } + else { return price()==other.price(); + } } bool operator!=(const IntPrice& other) const { return !(*this == other); @@ -65,16 +66,40 @@ class IntPrice { bts_assert_d(o.exponent() <= 0 && _exponent <= 0); if (o.exponent() < _exponent) { int8_t delta = _exponent - o.exponent(); - auto m = _mantissa * pow10(delta); - return IntPrice(m - o.mantissa(), o.exponent()); + int64_t m = _mantissa * pow10(delta); + return { m - o.mantissa(), o.exponent() }; } else { int8_t delta = o.exponent() - _exponent; - auto m = o.mantissa() * pow10(delta); - return IntPrice(_mantissa - m, _exponent); + int64_t m = o.mantissa() * pow10(delta); + return { _mantissa - m, exponent() }; } } } + IntPrice operator + (const IntPrice& o) const { + if (_exponent==o._exponent) { + return IntPrice { _mantissa+o.mantissa(), exponent() }; + } + else { + if (is_nan() || o.is_nan()) return IntPrice(); + bts_assert_d(o.exponent() <= 0 && _exponent <= 0); + if (o.exponent() < _exponent) { + int8_t delta = _exponent - o.exponent(); + int64_t m = _mantissa * pow10(delta); + return { m + o.mantissa(), o.exponent() }; + } + else { + int8_t delta = o.exponent() - _exponent; + int64_t m = o.mantissa() * pow10(delta); + return { _mantissa + m, exponent() }; + } + } + } + IntPrice sign_extend(int8_t new_exponent) const { + int8_t delta = _exponent - new_exponent; + int64_t m = _mantissa * pow10(delta); + return { m, new_exponent }; + } int64_t mantissa() const { return _mantissa; } int8_t exponent() const { return _exponent; } double price() const { @@ -85,6 +110,7 @@ class IntPrice { }; static_assert(sizeof(IntPrice) == 8, "IntPrice should be this big |--------|"); extern IntPrice INT_NAN; +extern IntPrice INT_ZERO; template IntPrice IntPrice_from_double(double price) { @@ -98,6 +124,52 @@ IntPrice IntPrice_from_double(double price) { } return {(int64_t)price, 0}; } +// inline IntPrice IntPrice_from_double(double price, int8_t precision) { +// if (os::is_nan(price)) return INT_NAN; +// return { (int64_t)(price * pow10(-precision)), precision }; +// } + +inline md::IntPrice round_to_quote_price(const IntPrice& tick, const IntPrice& price, api::Side side) { + bts_assert_d(tick.mantissa() != 0); + if (price.is_nan()) return price; + bts_assert_d(price.exponent() <= 0 && tick.exponent() <= 0); + if (price.exponent() == tick.exponent()) { + auto mod = price.mantissa() % tick.mantissa(); + if (mod == 0) return price; + else if (side == api::SIDE_BUY) { + // buy, round down + if (price.mantissa() > 0) { + return { price.mantissa() - mod, price.exponent() }; + } + else { + return { price.mantissa() - mod - tick.mantissa(), price.exponent() }; + } + } + else if (side == api::SIDE_SELL) { + // sell, round up + if (price.mantissa() > 0) { + return { price.mantissa() - mod + tick.mantissa(), price.exponent() }; + } + else { + return { price.mantissa() - mod, price.exponent() }; + } + } + } + else { + // Uncommon path + // Math is reversed because exponents are negative + if (tick.exponent() < price.exponent()) { + return round_to_quote_price(tick, price.sign_extend(tick.exponent()), side); + } + else { + // Extend tick to price's exponent + return round_to_quote_price(tick.sign_extend(price.exponent()), price, side); + } + } + + return price; +} + inline std::ostream& operator<<(std::ostream& os, const IntPrice& p) { os << p.price(); diff --git a/src/lib/md/MDConsumerHandle.cpp b/src/lib/md/MDConsumerHandle.cpp index 6f11dcece..4062f1353 100644 --- a/src/lib/md/MDConsumerHandle.cpp +++ b/src/lib/md/MDConsumerHandle.cpp @@ -85,7 +85,7 @@ TimeStamp copy_depth( ///////////////////////////// struct Level { double price; - uint16_t size; + double size; }; struct DepthTraversal { std::array levels; @@ -100,42 +100,92 @@ struct DepthTraversal { levels[x].size = depth[x].size(); } } - double try_take1() { - if (head >= levels.size()) return os::nan(); - if (levels[head].size >= qty) { - levels[head].size -= qty; - return levels[head].price * price_mult; - } - else { - double price = 0; - size_t count = 0; - while(count < qty) { - if (levels[head].size >= 1) { - price += levels[head].price; - levels[head].size -= 1; - count += 1; - } - else { - head++; - if (head >= levels.size()) return os::nan(); - } - } - return (price / qty) * price_mult; + #ifdef PRECISE_SYNTHETICS + double available_size() const { + double available = 0.0; + auto cur = head; + bool partial = false; + while(cur < levels.size() && available < 1) { + available += levels[cur].size / qty; + if (available < 1.0) partial = true; + ++cur; } + if (partial && available >= 1.0) return 1.0; + return available; } + double consume(double size) { + bts_assert_d(size <= available_size()); + double take = size * qty; + double price = 0.0; + while(take > 0) { + if (levels[head].size >= take) { + price += levels[head].price * price_mult * (take/qty); + levels[head].size -= take; + if (levels[head].size <= 0) ++head; + break; + } + else { + double available = levels[head].size; + price += levels[head].price * price_mult * (available/qty); + levels[head].size = 0; + ++head; + take -= available; + } + } + return price/size; + } + #else + double available_size() const { + double available = 0.0; + auto cur = head; + while(cur < levels.size() && available < 1) { + available += levels[cur].size / qty; + ++cur; + } + return available; + } + double consume(double size) { + bts_assert_d(size <= available_size()); + double take = size * qty; + double price = 0.0; + while(take > 0) { + if (levels[head].size >= take) { + price = levels[head].price * price_mult; + levels[head].size -= take; + if (levels[head].size <= 0) ++head; + break; + } + else { + double available = levels[head].size; + price = levels[head].price * price_mult; + levels[head].size = 0; + ++head; + take -= available; + } + } + return price; + } + #endif }; -void copy_depth(size_t count, api::Side side, const api::ContractSpecification& spec, small_vector& leg_travs, Level* out_price) { +void copy_synthetic_side(size_t count, api::Side side, const api::ContractSpecification& spec, small_vector& leg_travs, Level* out_price) { size_t out_index = 0; bool first = true; while(out_index < count) { - double price = 0.0; - for (auto& dt : leg_travs) { - double temp = dt.try_take1(); - price += temp; - } - if (os::is_nan(price)) { + double price = 0.0; + // Find the leg with the minimum available size + double size = std::numeric_limits().max(); + + for (const auto& dt : leg_travs) { + auto sz = dt.available_size(); + // If we can't get 1.0 from any leg we're done + if (sz <= size) size = sz; + if (size < 1.0) break; + } + size = (int64_t)size; + + if (size < 1.0) { // We've run out of book so we nan out any remaining levels and finish size_t start = first ? out_index : out_index+1; for (size_t x=start; x < count; ++x) { @@ -145,6 +195,13 @@ void copy_depth(size_t count, api::Side side, const api::ContractSpecification& return; } + // Take that size from each leg + for (auto& dt : leg_travs) { + double temp = dt.consume(size); + price += temp; + } + bts_assert_d(!os::is_nan(price)); + // Round to tick size price = securities::checked_round_to_quote_price(spec, price, side); @@ -154,19 +211,19 @@ void copy_depth(size_t count, api::Side side, const api::ContractSpecification& } if (price == out_price[out_index].price) { - out_price[out_index].size += 1; + out_price[out_index].size += size; } else { out_index += 1; if (out_index < count) { out_price[out_index].price = price; - out_price[out_index].size = 1; + out_price[out_index].size = size; } } } } -TimeStamp copy_depth(const SyntheticStrategy& synth, size_t count, PriceSize* bid, PriceSize* ask) { +TimeStamp copy_synthetic_depth(const SyntheticStrategy& synth, size_t count, PriceSize* bid, PriceSize* ask) { small_vector bid_leg_travs; small_vector ask_leg_travs; bid_leg_travs.reserve(synth.legs.size()); @@ -210,12 +267,12 @@ TimeStamp copy_depth(const SyntheticStrategy& synth, size_t count, PriceSize* bi } std::array scratch {}; const auto& spec = synth.security.contract_spec(); - copy_depth(count, api::SIDE_BUY, spec, bid_leg_travs, scratch.data()); + copy_synthetic_side(count, api::SIDE_BUY, spec, bid_leg_travs, scratch.data()); for (size_t x = 0; x < count; ++x) { bid[x] = PriceSize_from_double<7>(scratch[x].price, scratch[x].size); } memset(scratch.data(), 0, sizeof(scratch)); - copy_depth(count, api::SIDE_SELL, spec, ask_leg_travs, scratch.data()); + copy_synthetic_side(count, api::SIDE_SELL, spec, ask_leg_travs, scratch.data()); for (size_t x = 0; x < count; ++x) { ask[x] = PriceSize_from_double<7>(scratch[x].price, scratch[x].size); } diff --git a/src/lib/md/MDConsumerHandle.h b/src/lib/md/MDConsumerHandle.h index 904a44e21..2000ab7cd 100644 --- a/src/lib/md/MDConsumerHandle.h +++ b/src/lib/md/MDConsumerHandle.h @@ -22,7 +22,7 @@ struct SyntheticStrategy { TimeStamp copy_bbo(const HotEntry& src, PriceSize& out_bid, PriceSize& out_ask); TimeStamp copy_depth(const HotDepthEntry&, size_t count, PriceSize* bid, PriceSize* ask); -TimeStamp copy_depth(const SyntheticStrategy&, size_t count, PriceSize* bid, PriceSize* ask); +TimeStamp copy_synthetic_depth(const SyntheticStrategy&, size_t count, PriceSize* bid, PriceSize* ask); enum class HandleReadResult { NO_CHANGE, @@ -281,7 +281,7 @@ private: case HANDLETYPE_SYNTHETIC: auto t = last_market_update(); if (t > time || t == TimeStamp::invalid()) { - TimeStamp temp = copy_depth(*synthetic.def, std::min(copydepth, COCONUT_MAX_DEPTH), bids, asks); + TimeStamp temp = copy_synthetic_depth(*synthetic.def, std::min(copydepth, COCONUT_MAX_DEPTH), bids, asks); if (temp == TimeStamp::invalid()) { return HandleReadResult::BUSY; } time = temp; return HandleReadResult::SUCCESS; diff --git a/src/lib/md/PriceSize.cpp b/src/lib/md/PriceSize.cpp index 46ea81030..42723246a 100644 --- a/src/lib/md/PriceSize.cpp +++ b/src/lib/md/PriceSize.cpp @@ -5,6 +5,7 @@ namespace bts { namespace md { IntPrice INT_NAN = IntPrice(); +IntPrice INT_ZERO = { 0, -7 }; PriceSize NO_MARKET = PriceSize(); int to_exponent(double value) { diff --git a/src/lib/md/SyntheticSecurityService.cpp b/src/lib/md/SyntheticSecurityService.cpp index 2c3456807..a4ec9b962 100644 --- a/src/lib/md/SyntheticSecurityService.cpp +++ b/src/lib/md/SyntheticSecurityService.cpp @@ -131,7 +131,31 @@ void SyntheticSecurityService::create_synthetic( // Notify listeners that a new security is added auto iter = _me->synthetics.find(SecurityKey(security.id())); if (iter != _me->synthetics.end()) { - send_reply(reply, CreateResult::ERROR_SECURITY_ALREADY_EXISTS, security.id()); + auto metadata = get_metadata(iter->first); + if (metadata && metadata->strategy().deleted()) { + // If this security is deleted we can just undelete it + Metadata newmeta; + // Rather than copy from the existing metatdata create a default. + // The existing metadata is from a deleted spread so may not be valid + // UI will call update_security_metadata if non-defaults are needed + newmeta.set_security_key(security.id()); + newmeta.mutable_strategy()->set_deleted(false); + LOG(Api,Info,"Un-deleting security {}", security.id()); + auto id = security.id(); + update_security_metadata(newmeta, [id,reply](const UpdateResult& result) { + if (result.error() == UpdateResult::ERROR_OK) { + // undelete was successful. Metadata update will make this visible again + send_reply(reply, CreateResult::ERROR_OK, id); + } + else { + LOG(Api,Info,"Failed to un-delete security {}. Error {}", id, result.error()); + send_reply(reply, CreateResult::ERROR_SECURITY_ALREADY_EXISTS, id); + } + }); + } + else { + send_reply(reply, CreateResult::ERROR_SECURITY_ALREADY_EXISTS, security.id()); + } } else { _me->synthetics.insert(std::make_pair(security.id(), security)); diff --git a/src/lib/md/common.h b/src/lib/md/common.h index 20c5cf1e8..06f07b294 100644 --- a/src/lib/md/common.h +++ b/src/lib/md/common.h @@ -4,6 +4,7 @@ #include "lib/utils/bts_export.h" #include "lib/utils/datetime.h" #include "lib/domain_model/SecurityKey.h" +#include "IntPrice.h" #include "lib/md/protos/co2.pb.h" #include "lib/domain_model/Security.pb.h" @@ -12,7 +13,6 @@ namespace bts { namespace md { - BTS_EXPORT const extern double NO_PRICE; const extern char* SYNTHETIC_SYMBOL; typedef uint32_t security_key; diff --git a/src/lib/md/relay/QueryServer.cpp b/src/lib/md/relay/QueryServer.cpp index 7af0043e9..2c6d692bb 100644 --- a/src/lib/md/relay/QueryServer.cpp +++ b/src/lib/md/relay/QueryServer.cpp @@ -17,6 +17,8 @@ #include "lib/api/services/MarketDataRelay.server.pb.h" #include "lib/api/public/ServiceContext.h" #include "lib/api/services/AdminService.client.pb.h" +#include "lib/api/service_helpers/AdminServiceUtils.h" +#include "lib/config/protos/cme_reference_data.pb.h" #ifndef _WIN32 #include "lib/metrics/metrics.h" #endif @@ -357,7 +359,7 @@ public: if (groupiter != _groups.end()) { auto& group = groupiter->second; bool is_entitled = bypass_entitlement || - ch.exchange() == api::VENUE_SIM || + /*ch.exchange() == api::VENUE_SIM || */ ch.exchange() == api::VENUE_BTS || (entitlements && entitlements->count(ch.symbol())); fill(ch, *group, reply->add_channels(), is_entitled); @@ -437,7 +439,7 @@ struct MDRelayServer : bts::co2::MarketDataRelayBase { } } // Temporarily bypass all entitlements - _db.query(request, preply, user_entitlement, true); + _db.query(request, preply, user_entitlement, bypass_entitlement); reply(*preply); #ifndef _WIN32 auto elapsed = (TimeStamp::now() - start); @@ -518,28 +520,39 @@ QueryServerPtr run_query_server(const bts::api::ServiceContext& ctx, std::shared db.check_heartbeats(threadpool); }); container->health_timer->start(); - + // Subscribe to entitlement data container->entitlement_sub = - container->admin_client.subscribe_md_permissions_data().subscribe([=](const api::admin::Md_permissions_dataUpdate& update) { - auto entitlements = std::make_shared>(); - for (const auto& row : update.all()) { - if (row && row->enabled()) { - auto iter = entitlements->find(row->user_id()); - if (iter == entitlements->end()) { - Entitlements ents; - ents.insert(row->symbol()); - entitlements->insert(iter, std::make_pair(row->user_id(), std::move(ents))); - } - else { - iter->second.insert(row->symbol()); + container->admin_client.subscribe_md_entitlement_data().subscribe([=](const api::admin::Md_entitlement_dataUpdate& update) { + const auto& all_updates = update.all(); + utils::Dispatcher::background().post([all_updates, container]() + { + const auto& cme_symb_mics = config::get().cme_mic(); + auto entitlements = std::make_shared>(); + for (const auto& row : all_updates) { + if (row && row->enabled()) { + for(auto mic=cme_symb_mics.begin();mic!=cme_symb_mics.end();mic++){ + if(api::CMEMics_Name(mic->second) == row->mic()) { + const auto& symbol = mic->first; + auto iter = entitlements->find(row->user_id()); + if (iter == entitlements->end()) { + Entitlements ents; + ents.insert(symbol); + ents.insert("SIM:" + symbol); + entitlements->insert(iter, std::make_pair(row->user_id(), std::move(ents))); + } + else { + iter->second.insert(symbol); + iter->second.insert("SIM:" + symbol); + } + } + } } } - } - container->relay.update_entitlements(entitlements); + container->relay.update_entitlements(entitlements); + }); }); - // Add a few threads to keep md latency low for (int x = 1; x < std::min(4, os::num_cores()); ++x) { threadpool.add_thread(); diff --git a/src/lib/md/test/md2_tests.cpp b/src/lib/md/test/md2_tests.cpp index 9da770f46..c78efa58b 100644 --- a/src/lib/md/test/md2_tests.cpp +++ b/src/lib/md/test/md2_tests.cpp @@ -2256,6 +2256,17 @@ TEST_CASE("MergeImpliedTests", "[md]") { } TEST_CASE("IntPrice", "[md]") { + SECTION("sign extend") { + auto a = IntPrice_from_double<4>(101.111); + REQUIRE(std::to_string(a.price()) == "101.111000"); + REQUIRE(a.mantissa() == 1011110); + a = a.sign_extend(-5); + REQUIRE(std::to_string(a.price()) == "101.111000"); + REQUIRE(a.mantissa() == 10111100); + a = a.sign_extend(-9); + REQUIRE(std::to_string(a.price()) == "101.111000"); + REQUIRE(a.mantissa() == 101111000000); + } SECTION("< equal exponent") { auto a = IntPrice_from_double<4>(101.111); auto b = IntPrice_from_double<4>(100.111); @@ -2307,7 +2318,45 @@ TEST_CASE("IntPrice", "[md]") { IntPrice delta = INT_NAN - a; REQUIRE(delta == INT_NAN); } + + SECTION("round equal exponents") { + auto price = IntPrice_from_double<4>(100.333); + auto tick = IntPrice_from_double<4>(0.25); + // buy - round down + auto buy = round_to_quote_price(tick, price, api::SIDE_BUY); + REQUIRE(buy == IntPrice_from_double<4>(100.25)); + // sell - round up + auto sell = round_to_quote_price(tick, price, api::SIDE_SELL); + REQUIRE(sell == IntPrice_from_double<4>(100.50)); + } + SECTION("round smaller tick exponent") { + auto price = IntPrice_from_double<4>(100.333); + auto tick = IntPrice_from_double<3>(0.25); + // buy - round down + auto buy = round_to_quote_price(tick, price, api::SIDE_BUY); + REQUIRE(buy == IntPrice_from_double<4>(100.25)); + // sell - round up + auto sell = round_to_quote_price(tick, price, api::SIDE_SELL); + REQUIRE(sell == IntPrice_from_double<4>(100.50)); + } + SECTION("round smaller price exponent") { + auto price = IntPrice_from_double<4>(100.333); + auto tick = IntPrice_from_double<7>(0.25); + // buy - round down + auto buy = round_to_quote_price(tick, price, api::SIDE_BUY); + REQUIRE(buy == IntPrice_from_double<7>(100.25)); + // sell - round up + auto sell = round_to_quote_price(tick, price, api::SIDE_SELL); + REQUIRE(sell == IntPrice_from_double<4>(100.50)); + } + SECTION("round 0.005") { + IntPrice price = { -43595000, -7 }; + IntPrice tick = { 50000, -7 }; + auto buy = round_to_quote_price(tick, price, api::SIDE_BUY); + REQUIRE(buy == IntPrice_from_double<7>(-4.360)); + } } + }}} diff --git a/src/lib/md/test/synthetic_book_merge_tests.cpp b/src/lib/md/test/synthetic_book_merge_tests.cpp index e6067a64e..4d174207a 100644 --- a/src/lib/md/test/synthetic_book_merge_tests.cpp +++ b/src/lib/md/test/synthetic_book_merge_tests.cpp @@ -27,7 +27,10 @@ struct PS { double price; Size size; bool operator == (const PS& other) const { - return price == other.price && size == other.size; + // Convert to IntPrice to avoid double rounding issues + auto p1 = IntPrice_from_double<11>(price); + auto p2 = IntPrice_from_double<11>(other.price); + return p1 == p2 && size == other.size; } }; @@ -46,6 +49,25 @@ void setup_market(MDProducerHandle producer, const vector& bids, const vecto producer.update_direct(ts, bids_a, asks_a); } +void dump_market(const MDConsumerHandle& handle) { + array raw_bids,raw_asks; + TimeStamp t; + handle.get_book(t, COCONUT_MAX_DEPTH, raw_bids.data(), raw_asks.data()); + vector src_bids, src_asks; + sane::map(raw_bids, src_bids, [](const PriceSize& ps) -> PS {return {ps.price(), ps.size()};}); + sane::map(raw_asks, src_asks, [](const PriceSize& ps) -> PS {return {ps.price(), ps.size()}; }); + + std::cout << std::endl << "bid: "; + for (const auto& bid : src_bids) { + if (bid.size != 0) std::cout << bid; + } + std::cout << std::endl << "ask: "; + for (const auto& ask : src_asks) { + if (ask.size != 0) std::cout << ask; + } + std::cout << std::endl; +} + void expect_market(const MDConsumerHandle& handle, const vector bids, const vector& asks) { array raw_bids,raw_asks; TimeStamp t; @@ -71,15 +93,15 @@ void expect_market(const MDConsumerHandle& handle, const vector bids, const } // Crate some securities with given side -// tuple = (quantity, tick_size, side) -tuple,vector> make_securities(const vector>& leg_descr) { +// (quantity, multiplier, tick_size, side) +tuple,vector> make_securities(const vector>& leg_descr) { vector legs; auto synthetic = make_shared(); uint32_t security_key = 100; for (const auto& ldesc : leg_descr) { - double quantity, tick_size; + double quantity, mult, tick_size; api::Side side; - std::tie(quantity, tick_size, side) = ldesc; + std::tie(quantity, mult, tick_size, side) = ldesc; Co2TestInstrument instr("ES", api::SECURITYTYPE_FUTURE); instr.producer().set_key(security_key); ++security_key; @@ -99,8 +121,20 @@ tuple,vector> make_securities(c } return { synthetic, legs }; } +// tuple = (quantity, tick_size, side) +tuple,vector> make_securities(const vector>& leg_descr) { + std::vector> legs; + for (const auto& t : leg_descr) { + double quantity, tick_size; + api::Side side; + std::tie(quantity, tick_size, side) = t; + legs.push_back({ quantity, quantity, tick_size, side }); + } + return make_securities(legs); +} -void set_leg_params(SyntheticStrategy& strat, uint security_key, const spark::LegSpreaderParams& params) { + +void set_leg_params(SyntheticStrategy& strat, uint32_t security_key, const spark::LegSpreaderParams& params) { auto* map = strat.strategy.mutable_leg_params_map(); map->insert({ security_key, params }); } @@ -162,7 +196,8 @@ TEST_CASE("SyntheticBook+1-2", "[md][synthetic]") { {{100,16}, {110,8}, {120,12}, {130,5}}); expect_market(synthetic_handle, {{-10,1}, {-20,7}, {-40,4}, {-70,4}, {-80,2}, {-100,2}}, - {{20,2}, {40,1}, {50,4}, {70,1}, {80,4}, {90,1}, {100,3}, {110,1}, {120,1}}); + {{20,2}, {50,5}, {70,1}, {80,4}, {100,4}, {110,1}, {130,1}}); + //precise {{20,2}, {40,1}, {50,4}, {70,1}, {80,4}, {90,1}, {100,3}, {110,1}, {120,1}}); } } TEST_CASE("SyntheticBook+2-2", "[md][synthetic]") { @@ -181,8 +216,10 @@ TEST_CASE("SyntheticBook+2-2", "[md][synthetic]") { {{2003.25, 12}, {2003.5, 3}, {2003.75,5}}); expect_market(synthetic_handle, - {{-6.5,5}, {-7.0,1}, {-7.5,1}, {-8.0,1}, {-8.5,2}}, - {{-5.50,2}, {-5.25,1}, {-5.00,4}, {-4.75,1}, {-4.5,2}, {-3.00,5}}); + {{-6.5,5}, {-7.0,1}, {-7.5,1}, {-8.5,3}}, + //precise {{-6.5,5}, {-7.0,1}, {-7.5,1}, {-8.0,1}, {-8.5,2}}, + {{-5.50,2}, {-5.00,5}, {-4.5,3}, {-3.00,5}}); + //precise {{-5.50,2}, {-5.25,1}, {-5.00,4}, {-4.75,1}, {-4.5,2}, {-3.00,5}}); } @@ -209,6 +246,26 @@ TEST_CASE("Synthetic3Legs", "[md][synthetic]") { {{-790,2}, {-788,1}, {-778,2}, {-777,5}, {-767,3}, {-766,4}}, {{-802,8}, {-803,1}, {-813,1}, {-814,4}, {-824,4}}); } +} + +TEST_CASE("AllBlank", "[md][synthetic]") { + shared_ptr synthetic; + vector test_instr; + + tie(synthetic, test_instr) = make_securities({ {1.0, 0.1, api::SIDE_BUY}, {1.0, 0.1, api::SIDE_SELL }, { 1.0, 0.1, api::SIDE_BUY}}); + auto leg1 = test_instr[0]; + auto leg2 = test_instr[1]; + MDConsumerHandle synthetic_handle(synthetic); + + setup_market(leg1.producer(), + {}, + {}); + setup_market(leg2.producer(), + {}, + {}); + expect_market(synthetic_handle, + {}, + {}); } @@ -232,10 +289,92 @@ TEST_CASE("SPARK-955", "[md][synthetic]") { {{2607.25, 3}, {2607.50, 1}, {2608.25, 9}}); expect_market(synthetic_handle, // If we do strict price this is right. If we're pessimistic we get {-4.25,2} - { {-4.00, 1}, {-4.25, 1}, { -5.00, 3}, {-5.25, 3}, {-5.50,1}, {-5.75, 6} }, + { {-4.25, 2}, { -5.00, 3}, {-5.25, 3}, {-5.75, 7} }, + //precise { {-4.00, 1}, {-4.25, 1}, { -5.00, 3}, {-5.25, 3}, {-5.50,1}, {-5.75, 6} }, { {5.00, 3}, {5.25, 1}, {6.00,3}, {6.50,6} }); } +TEST_CASE("SPARK-954", "[md][synthetic]") { + shared_ptr synthetic; + vector test_instr; + + SECTION("price multiplier = 0.9,1.1") { + tie(synthetic, test_instr) = make_securities({ {0.9, 0.25, api::SIDE_BUY}, {1.1, 0.25, api::SIDE_SELL } }); + auto leg1 = test_instr[0]; + auto leg2 = test_instr[1]; + MDConsumerHandle synthetic_handle(synthetic); + + setup_market(leg1.producer(), + { {2796.75,22}, {2796.50,38}, {2796.25,57}, {2796.00,59}, {2795.75,60}, {2795.50,67}, {2795.25,68}, {2795.00,84}, {2794.75,115}, {2794.50,98}, }, + { {2797.00,158}, {2797.25,110}, {2797.50,83}, {2797.75,168}, {2798.00,130}, {2798.25,180}, {2798.50,75}, {2798.75,89}, {2799.00,123}, {2799.25,193}, }); + setup_market(leg2.producer(), + { {2800.50,1}, {2800.25,6}, {2800.00,8}, {2799.75,14}, {2799.50,15}, {2799.25,14}, {2799.00,44}, {2798.75,13}, {2798.50,18}, {2798.25,14}, }, + { {2801.00,1}, {2801.25,4}, {2801.50,16}, {2801.75,15}, {2802.00,16}, {2802.25,15}, {2802.50,45}, {2802.75,13}, {2803.00,14}, {2803.25,14}, }); + expect_market(synthetic_handle, + { {-564.50,4}, {-564.75,15}, {-565.00,5}, {-565.25,8}, {-565.50,15}, {-565.75,13}, {-566.00,6}, {-566.25,35}, {-566.50,12}, {-566.75,13}, }, + { {-562.75,6}, {-562.50,7}, {-562.25,13}, {-562.00,13}, {-561.75,13}, {-561.50,40}, {-561.25,12}, {-561.00,16}, {-560.75,13}, }); + + } + + SECTION("price multiplier = 1.0,-1.3") { + tie(synthetic, test_instr) = make_securities({ {1.0, 0.005, api::SIDE_BUY}, {1.3, 0.005, api::SIDE_SELL } }); + auto leg1 = test_instr[0]; + auto leg2 = test_instr[1]; + MDConsumerHandle synthetic_handle(synthetic); + setup_market(leg1.producer(), + { { 14.185, 1 }, { 14.180, 7 } }, + { { 14.205, 1 }, { 14.210, 5 } }); + setup_market(leg2.producer(), + { { 14.255, 10 }, { 14.250, 42 }, { 14.230, 1 }, { 14.220, 1 }, { 14.215, 1 }, { 14.210, 3 }, { 14.205, 1 }, { 14.200, 2 } }, + { { 14.265, 18 }, { 14.270, 19 } }); + expect_market(synthetic_handle, + { { -4.360, 1 }, { -4.365, 7 } }, + { { -4.325, 1 }, { -4.320, 5 } }); + } + +} + +TEST_CASE("AggregationAcrossLevels", "[md][synthetic]") { + shared_ptr synthetic; + vector test_instr; + SECTION("buy 1 sell 3") { + tie(synthetic, test_instr) = make_securities({ {1.0, 0.005, api::SIDE_BUY}, {3, 0.005, api::SIDE_SELL } }); + auto leg1 = test_instr[0]; + auto leg2 = test_instr[1]; + MDConsumerHandle synthetic_handle(synthetic); + setup_market(leg1.producer(), + { {16.215, 6} }, + { {16.220, 5} } + ); + setup_market(leg2.producer(), + { {16.500, 2 }, { 16.495, 2 } }, + { {16.505, 1 }, { 16.510, 1 }, { 16.515, 1 }, {16.520,1}, {16.525,1}, {16.530,1}} + ); + expect_market(synthetic_handle, + { {-33.330,1}, {-33.375, 1} }, + { { -33.265,1} } + ); + } + SECTION("buy 1 sell 4") { + tie(synthetic, test_instr) = make_securities({ {1.0, 0.005, api::SIDE_BUY}, {4, 0.005, api::SIDE_SELL } }); + auto leg1 = test_instr[0]; + auto leg2 = test_instr[1]; + MDConsumerHandle synthetic_handle(synthetic); + setup_market(leg1.producer(), + { {16.215, 6} }, + { {16.220, 5} } + ); + setup_market(leg2.producer(), + { {16.500, 2 }, { 16.495, 2 } }, + { {16.505, 1 }, { 16.510, 1 }, { 16.515, 1 }, {16.520,1}, {16.525,1}, {16.530,1}, {16.535,2}} + ); + expect_market(synthetic_handle, + { { -49.865,1}, {-49.925,1} }, + { { -49.760,1} } + ); + } +} + TEST_CASE("Synthetic_net_change", "[md][synthetic]") { shared_ptr synthetic; vector test_instr; @@ -265,7 +404,8 @@ TEST_CASE("Synthetic_net_change", "[md][synthetic]") { // Validate merge expect_market(synthetic_handle, {{-10,1}, {-20,7}, {-40,4}, {-70,4}, {-80,2}, {-100,2}}, - {{20,2}, {40,1}, {50,4}, {70,1}, {80,4}, {90,1}, {100,3}, {110,1}, {120,1}}); + {{20,2}, {50,5}, {70,1}, {80,4}, {100,4}, {110,1}, {130,1}}); + // precise {{20,2}, {40,1}, {50,4}, {70,1}, {80,4}, {90,1}, {100,3}, {110,1}, {120,1}}); } } @@ -325,4 +465,4 @@ BENCHMARK(synthetic_get_book_speed3); #endif }}}//namespace -#endif \ No newline at end of file +#endif diff --git a/src/lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.cpp b/src/lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.cpp index 9cf51cdf0..5e8d7b570 100644 --- a/src/lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.cpp +++ b/src/lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.cpp @@ -30,12 +30,12 @@ bool SpreaderUtils::resolve_synthetic_spread (const SpreaderPreActivationOrderSe const bts::api::ContractLeg& leg = *it; if (leg.security().has_future() || leg.security().has_spread()){ const bts::api::Security* leg_sec_ptr = spreader_pao_services.resolve(bts::SecurityKey (leg.security().id())); - if (leg_sec_ptr != nullptr){ + auto leg_exec_strategy_it = execution_strategy.leg_params_map().find(leg.security().id()); + if (leg_sec_ptr != nullptr && + leg_exec_strategy_it != execution_strategy.leg_params_map().end()) { bts_assert(leg_sec_ptr->id() == leg.security().id()); LOG(OrderMan, Info, "resolve_synthetic_spread resolved leg key {}", leg_sec_ptr->id()); - auto leg_exec_strategy_it = execution_strategy.leg_params_map().find(leg.security().id()); - bts_assert(leg_exec_strategy_it != execution_strategy.leg_params_map().end()); - const auto& leg_params=leg_exec_strategy_it->second; + const auto& leg_params = leg_exec_strategy_it->second; api::Side leg_order_side = SpreaderUtils::get_leg_side(order_def.side(), leg); // quoter order def api::orderman::OrderDefinition quoter_order_def = order_def; diff --git a/src/server/sparkd/bts_trace.cpp b/src/lib/tracing/bts_trace.cpp similarity index 100% rename from src/server/sparkd/bts_trace.cpp rename to src/lib/tracing/bts_trace.cpp diff --git a/src/lib/utils/AuthToken.cpp b/src/lib/utils/AuthToken.cpp index e53c53eb9..5a10fa63c 100644 --- a/src/lib/utils/AuthToken.cpp +++ b/src/lib/utils/AuthToken.cpp @@ -12,6 +12,8 @@ user::AuthToken generate_token(const admin::BTSUser& user) { api::user::TokenPayload payload; payload.set_date(datetime::ll_now()); payload.set_id(user.id()); + if(user.name() == "bts") + payload.set_wheel(true); auto token = websocketpp::base64_encode(payload.SerializeAsString()); user::AuthToken result; result.set_token(token); diff --git a/src/sdk/CMakeLists.txt b/src/sdk/CMakeLists.txt index aa6a3f5ec..e4a38178e 100644 --- a/src/sdk/CMakeLists.txt +++ b/src/sdk/CMakeLists.txt @@ -7,6 +7,8 @@ add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/sdk COMMENT "Building SDK" DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/make_sdk.sh + ${CMAKE_CURRENT_SOURCE_DIR}/README.md + ${CMAKE_CURRENT_SOURCE_DIR}/sdk_shell.sh ${CMAKE_CURRENT_SOURCE_DIR}/examples/build_examples.sh ${CMAKE_CURRENT_SOURCE_DIR}/examples/md_publisher_example.cpp ${CMAKE_CURRENT_SOURCE_DIR}/examples/order_plugin_example.cpp diff --git a/src/sdk/README.md b/src/sdk/README.md new file mode 100644 index 000000000..47356faec --- /dev/null +++ b/src/sdk/README.md @@ -0,0 +1,110 @@ +# BTS Spark SDK + +#### Getting Started + +## Docker + +We use docker to provide a full dev environment with all the tools users need to develop their own algos. + +1) Setup docker on your preferred OS and pull down the BTS docker +* If you are new to docker you can find out more about it here: https://docs.docker.com/get-started/ + +``` +$ docker pull bluetradingsystems/linux_docker +``` +* Our docker can also be found here: https://hub.docker.com/r/bluetradingsystems/linux_docker/ + +2) Start the docker container +``` +$ docker run \ + --net host \ + --shm-size=1024m \ + --cap-add=SYS_PTRACE --security-opt seccomp=unconfined \ + -w $PWD \ + -v /home:/home \ + --name bts_sdk \ + -i \ + -t bluetradingsystems/linux_docker \ + /bin/bash + +``` + * Note that the lifetime of docker instance above is tied to the life of the shell instance, so if you exit bash, the container stops running. To start and re-attach to the container, use: +``` +$ docker start --attach -i bts_sdk +``` + + * If you prefer to run docker as a daemon, check out [``~/spark_sdk/sdk_shell.sh``](sdk_shell.sh) + +## Git + +* We assume the git you are using is git-lfs compatible; if you're using the git that comes with our docker, you're all set. + +* else go here: https://github.com/git-lfs/git-lfs/wiki/Installation + + +Now that you're ssh'd into the docker container, clone the repo into ```~/spark_sdk/``` and cd to that directory +``` +$ cd +$ git clone https://github.com/BlueTradingSystems/spark_sdk.git +$ cd spark_sdk +``` + + +## Development + +Look at [examples/md_publisher_example.cpp](examples/md_publisher_example.cpp) to look at how to build a custom market data producer + +Look at [examples/order_plugin_example.cpp](examples/order_plugin_example.cpp) to look at how to create custom algos. + +run ```build_examples.sh``` to make sure you can build the examples, this will produce an ```order_plugin_example.so``` + +``` +$ cd ~/spark_sdk/examples +$ ./build_examples.sh +``` + +## Debugging + +Copy the order_plugin_example.so to ```spark_sdk/lib/plugins/``` and start the sparkd server process inside gdb +``` +$ cp -f order_plugin_example.so ~/spark_sdk/lib/plugins/ +$ cd ~/spark_sdk/lib +$ gdb --args ./sparkd run +``` + + +In gdb: + +* https://darkdust.net/files/GDB%20Cheat%20Sheet.pdf +``` +(gdb) break order_plugin_example.cpp:366 +``` + +## Running without debugger + +``` +$ cp -f order_plugin_example.so ~/spark_sdk/lib/plugins/ +$ cd ~/spark_sdk/lib +$ ./sparkd run +``` + +## Connect Spark windows client + +* To start a spark client, use the -ConfigServer parameter to point at this new server + ``` +> spark.exe -ConfigServer http://location/8000/config + ``` + Or create a file called spark.conf at %APPDATA%\bts\conf\ that contains: + ``` +include: "http://location:8000/config/" + ``` + +## Notes + +* When you have a running server you can: + * Browse to http://location/8000 to set risk limits and create users + * Browse to http://location/8000/config to check configuration overrides + * Browse to http://location/8000/perf_trace to see socket to socket latencies + * Send us an email for help: api_support@bluetradesys.com + + diff --git a/src/sdk/examples/md_publisher_example.cpp b/src/sdk/examples/md_publisher_example.cpp index c81ebddb1..e3ef28826 100644 --- a/src/sdk/examples/md_publisher_example.cpp +++ b/src/sdk/examples/md_publisher_example.cpp @@ -3,7 +3,7 @@ #include "spark/lib/utils/bts_chrono.h" #include "spark/lib/md/MDProducer.h" #include "spark/lib/utils/PBUtils.h" -#include "spark/lib/tracing/bts_trace_c.c" +#include "spark/lib/tracing/bts_trace.h" #include "spark/lib/md/cme/MDP3Utils.h" using namespace bts; diff --git a/src/sdk/make_sdk.sh b/src/sdk/make_sdk.sh index c8c76d868..945b69c2e 100755 --- a/src/sdk/make_sdk.sh +++ b/src/sdk/make_sdk.sh @@ -21,12 +21,17 @@ mkdir -p $1/sdk/externals/ ln -sf $2/../../externals/linux/include $1/sdk/externals/include ln -sf $2/../../externals/linux/lib/Release $1/sdk/externals/lib - ln -sf $1/server $1/sdk/lib + mkdir $1/sdk/examples cp $2/examples/* $1/sdk/examples -ln -sf $1/sdk/lib/defaults $1/sdk/examples/defaults +cp $2/sdk_shell.sh $1/sdk/sdk_shell.sh +cp $2/update_github.sh $1/sdk/update_github.sh +cp $2/README.md $1/sdk/README.md + +# ln -sf $1/sdk/lib/defaults $1/sdk/examples/defaults chmod +x $1/sdk/examples/build_examples.sh +chmod +x $1/sdk/sdk_shell.sh +chmod +x $1/sdk/update_github.sh (cd $1/sdk/examples && ./build_examples.sh && ./md_publisher_example >/dev/null) - diff --git a/src/sdk/sdk_shell.sh b/src/sdk/sdk_shell.sh new file mode 100644 index 000000000..70da324f4 --- /dev/null +++ b/src/sdk/sdk_shell.sh @@ -0,0 +1,23 @@ +#/bin/bash + +docker kill bts_sdk +docker rm bts_sdk + +docker run \ + --restart=unless-stopped \ + --net host \ + --shm-size=1024m \ + --cap-add=SYS_PTRACE --security-opt seccomp=unconfined \ + -h $(hostname)_spark \ + -w $PWD \ + -u root \ + -v /home:/home \ + --name bts_sdk \ + -d \ + -t bluetradingsystems/linux_docker \ + /bin/bash #-c "(sudo /usr/sbin/sshd -p 2323) & /bin/bash --login" + +docker exec -it bts_sdk /bin/bash + +#some windows users may find it convenient to start ssh in the docker, in that case use uncomment the -c "( ... portion above +#and use ssh instead of docker exec diff --git a/src/sdk/update_github.cmd b/src/sdk/update_github.cmd new file mode 100644 index 000000000..b97c862c8 --- /dev/null +++ b/src/sdk/update_github.cmd @@ -0,0 +1,66 @@ +@echo off +setlocal + +set STAGE="c:\temp\bts_staging" +set SDK="spark_client_sdk" +set SRC=%1 +set GH=%2 +set TG=%3 +set OPP=%4 + +if "%SRC%" == "" goto :help +if "%GH%" == "" goto :help +if "%TG%" == "" goto :help + +if "%TG%" == "stage" echo "STAGE ONLY" + +if exist %STAGE% rmdir /s /q %STAGE% +mkdir %STAGE% +git clone --recurse-submodules "%GH%" %STAGE%\\%SDK% + +del /q "%STAGE%\\%SDK%\\*" +FOR /D %%p IN ("%STAGE%\\%SDK%\*.*") DO ( + REM this skips git + if NOT "%%p" == ".git" ( + rmdir /s /q "%%p" + ) +) + +FOR %%i IN ("%src%") DO ( + set filedrive=%%~di + set filepath=%%~pi + set filename=%%~ni + set fileextension=%%~xi + if "%%~xi" == ".nupkg" ( + unzip -o %%i -d %STAGE%\\%SDK%\\ + rmdir /Q /S %STAGE%\\%SDK%\\_rels + rmdir /Q /S %STAGE%\\%SDK%\\package + del /Q %STAGE%\\%SDK%\\spark_sdk.nuspec + del /Q %STAGE%\\%SDK%\\[Content_Types].xml + ) else ( + copy /Y /E %%i %STAGE%\\%SDK%\\ + ) +) +pushd %STAGE%\%SDK%\ + +if NOT "%TG%" == "stage" ( + git status + git add . + git commit -m "%SDK% update %TG%" + git tag "%TG%" + git push origin master --tags %OPP% + + popd + rmdir /s /q %STAGE% +) + +goto :eof + +:help +echo. +echo update_github.cmd ^ ^ [tag] [-push_params] +echo. +echo source can be a nupkg file or a folder +echo. +echo set tag to 'stage' if you don't want to push +goto :eof diff --git a/src/sdk/update_github.sh b/src/sdk/update_github.sh new file mode 100644 index 000000000..b81b8ae48 --- /dev/null +++ b/src/sdk/update_github.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +SDK="spark_sdk" +STAGE="/tmp/bts_staging" +SRC=$1 +GH=$2 +TG=$3 +OPP=$4 + +if [ "$#" -lt 3 ]; then + echo "update_github.sh [-push_params]" + echo "set tag to 'stage' if you don't want to push" + exit 0 +fi + +if [ "$TG" == "stage" ]; then echo "STAGE ONLY"; fi + +git lfs install + +if [ -d "$STAGE" ]; then + rm -rf $STAGE +fi +mkdir $STAGE + +git clone --recurse-submodules "$GH" $STAGE/$SDK +rm -rf $STAGE/$SDK/* +cp -L -r -f "$SRC"/** $STAGE/$SDK/ +pushd $STAGE/$SDK + +#clean all the stuff we don't want in github +rm ./examples/md_publisher_example +rm ./examples/order_plugin_example.so +rm ./lib/data_files/cert_secure_logon.txt +rm -r ./externals/lib/libonixs* +rm -r ./externals/include/OnixS/ +rm -r ./externals/lib/celoxica/ +rm -r ./externals/include/celoxica/ + +if [ "$TG" != "stage" ]; then + git status + git add . + git commit -m "$SDK update $TG" + git tag "$TG" + git push origin master --tags $OPP + + popd + rm -rf $STAGE +fi + diff --git a/src/server/sparkd/cmds/AdminReport.cpp b/src/server/sparkd/cmds/AdminReport.cpp new file mode 100644 index 000000000..59866b223 --- /dev/null +++ b/src/server/sparkd/cmds/AdminReport.cpp @@ -0,0 +1,104 @@ +#include "AdminReport.h" + +#include "lib/config/config.h" +#include "lib/logging/logging.h" +#include "lib/config/protos/logging.pb.h" +#include "lib/quickbus/quickbus.h" +#include "lib/api/public/ServiceContext.h" + +#include "lib/api/services/AdminService.client.pb.h" +#include "lib/api/service_helpers/AdminServiceUtils.h" + +#include +#include +#include +#include + +namespace bts +{ +namespace cmd +{ + +int AdminReport::execute(const std::vector& args) +{ + auto cfg = config::get (); + cfg.mutable_console()->set_default_level("Fatal"); + log::configure_logging(cfg); + + if(args[0] == "md") + return md_report(); + else + { + std::cout << std::endl << std::endl << help() << std::endl << std::endl; + return -1; + } +} + +int AdminReport::md_report() +{ + std::map mic_map; + mic_map[api::CMEMics::CME] = "XCME"; + mic_map[api::CMEMics::COMEX] = "XCEC"; + mic_map[api::CMEMics::CBT] = "XCBT"; + mic_map[api::CMEMics::NYMEX] = "XNYM"; + + // config::QuickbusNodeCfg qb_cfg; + // auto& ports = config::get(); + // qb_cfg.set_my_port(ports.qbus_port()); + //qbus::Quickbus quickbus(); + api::ServiceContext (sc); //for Eric + + api::admin::AdminService admin = sc.locate(); + auto res = admin.get_admin_data(api::VoidMessage()); + if(res.success()) + { + const api::admin::AdminData& data = *res.result(); + std::cout << "User,Fullname,Company,Exchange,MIC,Display,Pro/NonPro" << std::endl; + for(const auto& u : data.users()) + { + if(u.name() == "bts") + continue; + const bts::api::admin::CMEUserData* cme = admin::AdminServiceUtils::get_user_cme_data(u, data); + if(cme) + { + for(const auto& md : cme->md_permissions()) + { + if(!md.enabled()) + continue; + std::string mic_string = bts::api::CMEMics_Name(md.mic()); + auto it = mic_map.find(md.mic()); + if(it != mic_map.end()) + mic_string = it->second; + std::string disp_string = (cme->display_nondisplay() == api::admin::DisplayDesignation::DISPLAYDESIGNATION_NONDISPLAY) + ? "NONDISPLAY" : "DISPLAY"; + std::string pro_string = (cme->pro_nonpro() == api::admin::ProfessionalDesignation::PROFESSIONALDESIGNATION_NONPRO) + ? "NONPRO" : "PRO"; + + std::string name_string = u.name(); + name_string.erase(std::remove(name_string.begin(), name_string.end(), ','), name_string.end()); + std::string full_string = u.full_name(); + full_string.erase(std::remove(full_string.begin(), full_string.end(), ','), full_string.end()); + std::string co_string = u.company(); + co_string.erase(std::remove(co_string.begin(), co_string.end(), ','), co_string.end()); + + std::cout << name_string << "," << full_string << "," << co_string << ",CMEGroup," + << mic_string << "," << disp_string << "," << pro_string << std::endl; + } + } + } + } + return 0; +} + +std::string AdminReport::help() +{ + return + "\t sparkd adminreport [md] \n" + "\t Write a market data entitlement report csv to stdout \n" + ; +} + +} +} + + diff --git a/src/server/sparkd/cmds/AdminReport.h b/src/server/sparkd/cmds/AdminReport.h new file mode 100644 index 000000000..427b5105b --- /dev/null +++ b/src/server/sparkd/cmds/AdminReport.h @@ -0,0 +1,22 @@ +#pragma once + +#include "ICmd.h" + +namespace bts +{ +namespace cmd +{ + +class AdminReport : public ICmd +{ +public: + int execute(std::vector const &args); + int md_report(); + std::string help(); + +}; + +} +} + + diff --git a/src/server/sparkd/http/ApiGateway.cpp b/src/server/sparkd/http/ApiGateway.cpp index 213786c60..ec889dc80 100644 --- a/src/server/sparkd/http/ApiGateway.cpp +++ b/src/server/sparkd/http/ApiGateway.cpp @@ -46,6 +46,7 @@ struct ApiGatewayImpl { if (logon_response.result()->is_valid()) { resp.mutable_logon()->set_is_valid(true); resp.mutable_logon()->set_token(logon_response.result()->token().token()); + resp.mutable_logon()->set_can_create(logon_response.result()->can_create()); } else { resp.mutable_logon()->set_reason(logon_response.result()->reason()); diff --git a/src/server/sparkd/main.cpp b/src/server/sparkd/main.cpp index 37d790c76..524a8a1f3 100644 --- a/src/server/sparkd/main.cpp +++ b/src/server/sparkd/main.cpp @@ -16,6 +16,7 @@ #include "server/sparkd/cmds/Span.h" #include "server/sparkd/cmds/Test.h" #include "server/sparkd/cmds/TestCeloxica.h" +#include "server/sparkd/cmds/AdminReport.h" #include "server/sparkd/cmds/Web.h" using namespace bts; @@ -37,6 +38,7 @@ int main(int argc, char **argv) { REGISTER(Span); REGISTER(Web); REGISTER(PrintHedgeOrders); + REGISTER(AdminReport); END_CMD; utils::finit_spark_lib(); diff --git a/src/server/sparkd/md/MarketDataAuxiliaryServiceServer.cpp b/src/server/sparkd/md/MarketDataAuxiliaryServiceServer.cpp index 17886e386..31e16620c 100644 --- a/src/server/sparkd/md/MarketDataAuxiliaryServiceServer.cpp +++ b/src/server/sparkd/md/MarketDataAuxiliaryServiceServer.cpp @@ -56,7 +56,7 @@ void MarketDataAuxiliaryServiceServer::_poll_md(){ me->relay_service.requestmd(me->state.md_req(), [this](const bts::api::Result& md_reply) { - if(md_reply.result()!=nullptr) + if(md_reply) _scan_trades(*md_reply.result()); me->context.post([this](){_poll_md();},me->poll_period_ms); }); diff --git a/src/server/sparkd/user/AdminServiceServer.cpp b/src/server/sparkd/user/AdminServiceServer.cpp index df967f6eb..a3f705ba9 100644 --- a/src/server/sparkd/user/AdminServiceServer.cpp +++ b/src/server/sparkd/user/AdminServiceServer.cpp @@ -7,7 +7,9 @@ #include "lib/api/service_helpers/AdminServiceUtils.h" #include "lib/orderman/orderman_utils/orderman_utils.h" #include "lib/utils/TimeStamp.h" +#include "lib/utils/AuthToken.h" +#include #include #include #include @@ -80,6 +82,22 @@ void AdminServiceServer::create_account( request.description(), false, result); + if(request.creator_user() != "" && result.new_id() != 0) + { + const bts::api::admin::BTSUser* user = AdminServiceUtils::find_user(_state, request.creator_user(), false); + if(user) + { + BTSUser update(*user); + UserAccountPermissionUnit unit(UserAccountPermissionUnit::default_instance()); + unit.mutable_admin_permission()->set_has_permissions(true); + unit.mutable_admin_permission()->set_has_md_permissions(true); + + google::protobuf::MapPair v(result.new_id(), unit); + update.mutable_user_data()->mutable_account_permissions()->mutable_account_permissions()->insert(v); + AdminServiceOperationResult res; + AdminServiceUtils::update_user(_state, update, res); + } + } _update_and_publish(false); reply(result); } @@ -99,6 +117,8 @@ void AdminServiceServer::create_user( request.parent_group_id(), request.name(), request.password(), + request.full_name(), + request.company(), false, request.license_data(), request.license_entitlements(), @@ -118,6 +138,80 @@ void AdminServiceServer::get_admin_data(const bts::api::VoidMessage&, const api::Response& reply){ reply(_state); } + +void AdminServiceServer::get_filtered_admin_data(const bts::api::admin::FilteredAdminDataRequest& req, + const api::Response& reply) +{ + bts::api::user::TokenPayload toke; + if(bts::api::auth::decode_token(req.token(), &toke)) + { + if(toke.wheel()) + reply(_state); + else + { + const BTSUser* admin_user = AdminServiceUtils::find_user(_state, toke.id()); + AdminData filtered(_state); + boost::container::flat_map added_accounts, added_users; + filtered.clear_users(); + filtered.clear_accounts(); + if(admin_user && admin_user->has_user_data()) + { + const auto& permis = admin_user->user_data().account_permissions(); + for(const auto& map_entry : permis.account_permissions()) + { + auto acct_id = map_entry.first; + const bts::api::admin::UserAccountPermissionUnit& unit = map_entry.second; + const bts::api::admin::BTSAccount* acct = AdminServiceUtils::find_account(_state, acct_id, false); + if(!acct) + continue; + + std::vector users_for_account; + admin::AdminServiceUtils::find_users_for_trading_account(_state, acct_id, users_for_account); + if(unit.admin_permission().has_permissions()) + { + if(added_accounts.find(acct->name()) == added_accounts.end()) + { + added_accounts[acct->name()] = 0; + filtered.add_accounts()->CopyFrom(*acct); + for(const auto& acctuser : users_for_account) + { + if(added_users.find(acctuser->name()) == added_users.end()) + { + added_users[acctuser->name()] = 0; + const auto newuser = filtered.add_users(); + newuser->CopyFrom(*acctuser); + if(!unit.admin_permission().has_md_permissions()) + newuser->mutable_user_data()->mutable_exchange_user_data()-> + mutable_cme_data()->set_admin_display_flag(bts::api::admin::CMEUserData_AdminDisplay::CMEUserData_AdminDisplay_Routing); + else + newuser->mutable_user_data()->mutable_exchange_user_data()-> + mutable_cme_data()->set_admin_display_flag(bts::api::admin::CMEUserData_AdminDisplay::CMEUserData_AdminDisplay_All); + } + } + } + } + else if(unit.admin_permission().has_md_permissions()) + { + for(const auto& acctuser : users_for_account) + { + if(added_users.find(acctuser->name()) == added_users.end()) + { + added_users[acctuser->name()] = 0; + const auto newuser = filtered.add_users(); + newuser->CopyFrom(*acctuser); + newuser->mutable_user_data()->mutable_exchange_user_data()-> + mutable_cme_data()->set_admin_display_flag(bts::api::admin::CMEUserData_AdminDisplay::CMEUserData_AdminDisplay_MD); + } + } + } + } + } + reply(filtered); + } + } +} + + void AdminServiceServer::delete_user( const IDAPIArgument& id, const api::Response& reply){ @@ -241,14 +335,14 @@ void AdminServiceServer::_publish_md_entitlements(){ _md_entit_publisher.add_or_update(e); _md_entit_publisher.flush(); } -void AdminServiceServer::_publish_md_permissions(){ - std::vector perms; - for (const BTSUser* user : AdminServiceUtils::users(_state,false)) - AdminServiceUtils::get_user_symbol_permissions(_state,*user,perms); - for (const auto& p : perms) - _md_perm_publisher.add_or_update(p); - _md_perm_publisher.flush(); -} +// void AdminServiceServer::_publish_md_permissions(){ +// std::vector perms; +// for (const BTSUser* user : AdminServiceUtils::users(_state,false)) +// AdminServiceUtils::get_user_symbol_permissions(_state,*user,perms); +// for (const auto& p : perms) +// _md_perm_publisher.add_or_update(p); +// _md_perm_publisher.flush(); +// } void AdminServiceServer::_check_data_on_start (){ AdminServiceUtils::fill_connections_from_config(_state); for(int i=0; i<_state.accounts().size(); i++) diff --git a/src/server/sparkd/user/AdminServiceServer.h b/src/server/sparkd/user/AdminServiceServer.h index 618a20a38..ec1363032 100644 --- a/src/server/sparkd/user/AdminServiceServer.h +++ b/src/server/sparkd/user/AdminServiceServer.h @@ -52,6 +52,9 @@ public: void get_admin_data(const bts::api::VoidMessage& request, const api::Response& reply) override; + void get_filtered_admin_data(const bts::api::admin::FilteredAdminDataRequest& request, + const api::Response& reply) override; + void delete_user( const IDAPIArgument& request, const api::Response& reply) override; diff --git a/src/server/sparkd/user/UserServiceServer.cpp b/src/server/sparkd/user/UserServiceServer.cpp index a8d054633..e1ffb1857 100644 --- a/src/server/sparkd/user/UserServiceServer.cpp +++ b/src/server/sparkd/user/UserServiceServer.cpp @@ -6,6 +6,7 @@ #include "lib/api/services/AdminService.client.pb.h" #include "lib/utils/PBUtils.h" #include "lib/utils/AuthToken.h" +#include "lib/api/service_helpers/AdminServiceUtils.h" #include #include @@ -62,9 +63,15 @@ void UserServiceServer::authenticate_login(const api::user::AuthenticateLoginReq if (admin_data.success()) { for (const auto& user : admin_data.result()->users()) { if (user.name() == req.login() && user.password() == req.password() && user.is_present()) { - resp.set_is_valid(true); + resp.set_is_valid(user.is_active()); + if(!resp.is_valid()) + resp.set_reason("User login privledges restricted, please contact your risk manager"); resp.set_user_id(user.id()); resp.mutable_token()->CopyFrom(api::auth::generate_token(user)); + + api::user::TokenPayload payload; + api::auth::decode_token(resp.token().token(), &payload); + resp.set_can_create(payload.wheel() || user.can_create()); respond(resp); return; } @@ -79,4 +86,5 @@ void UserServiceServer::authenticate_login(const api::user::AuthenticateLoginReq } + } } diff --git a/src/server/sparkd/user/UserServiceServer.h b/src/server/sparkd/user/UserServiceServer.h index c23df00c5..431f6bf27 100644 --- a/src/server/sparkd/user/UserServiceServer.h +++ b/src/server/sparkd/user/UserServiceServer.h @@ -2,6 +2,7 @@ #include #include "lib/api/services/UserService.server.pb.h" +#include "lib/api/services/AdminService.pb.h" #include "lib/utils/bts_no_copy.h" namespace bts @@ -18,7 +19,7 @@ public: const std::function& ) override; void authenticate_login(const api::user::AuthenticateLoginRequest& , const std::function& ) override; - + private: struct PImpl; std::unique_ptr me; diff --git a/src/server/sparkd/user/tests/admin_service_tests.cpp b/src/server/sparkd/user/tests/admin_service_tests.cpp index 7f2709d54..ad33cf908 100644 --- a/src/server/sparkd/user/tests/admin_service_tests.cpp +++ b/src/server/sparkd/user/tests/admin_service_tests.cpp @@ -62,8 +62,8 @@ TEST_CASE ("Users", "[admin_service]") std::string name = "test_user", password = "test_user_password"; bts::api::admin::LicenseData license_data; - const bts::api::admin::LicenseEntitlements license_entitlements; - AdminServiceUtils::create_user(admin_data, parent_group->id(), name, password, true, license_data, license_entitlements, user_result); + const bts::api::admin::LicenseEntitlements license_entitlements; std::string empty(""); + AdminServiceUtils::create_user(admin_data, parent_group->id(), name, password, empty, empty, true, license_data, license_entitlements, user_result); bts::api::admin::BTSUser* new_user = AdminServiceUtils::find_user(admin_data, name); REQUIRE(user_result.is_success()); REQUIRE(admin_data.users_size()==1); @@ -73,7 +73,7 @@ TEST_CASE ("Users", "[admin_service]") REQUIRE(new_user->password() == password); REQUIRE(new_user->is_active()); // duplicate users can not be added - new_user = AdminServiceUtils::create_user(admin_data, parent_group->id(), name, password, true, license_data, license_entitlements, user_result); + new_user = AdminServiceUtils::create_user(admin_data, parent_group->id(), name, password, empty, empty, true, license_data, license_entitlements, user_result); REQUIRE(!user_result.is_success()); REQUIRE(new_user == nullptr); } @@ -92,10 +92,11 @@ TEST_CASE ("Users", "[admin_service]") int n_users = 100; bts::api::admin::LicenseData license_data; const bts::api::admin::LicenseEntitlements license_entitlements; + std::string empty(""); for (int i=1; i<=n_users; i++){ std::string name = fmt::format("test_user_{}",i), - password = fmt::format("password_{}",i); - AdminServiceUtils::create_user(admin_data, parent_group->id(), name, password, true, license_data, license_entitlements, user_result); + password = fmt::format("password_{}",i); + AdminServiceUtils::create_user(admin_data, parent_group->id(), name, password, empty, empty, true, license_data, license_entitlements, user_result); REQUIRE(user_result.is_success()); REQUIRE(AdminServiceUtils::users(admin_data,true).size()==i); REQUIRE(admin_data.users_size()==i); @@ -124,7 +125,7 @@ TEST_CASE ("Users", "[admin_service]") for (int i=1; i<=n_users; i++){ std::string name = "test_user_zombie", password = "password"; - AdminServiceUtils::create_user(admin_data, parent_group->id(), name, password, true, license_data, license_entitlements, user_result); + AdminServiceUtils::create_user(admin_data, parent_group->id(), name, password, empty, empty, true, license_data, license_entitlements, user_result); REQUIRE(user_result.is_success()); REQUIRE(AdminServiceUtils::users(admin_data,true).size()==n_users+i); REQUIRE(AdminServiceUtils::users(admin_data,false).size()==1); diff --git a/src/web/CMakeDeps.cmake b/src/web/CMakeDeps.cmake index 050dc8062..d404bc862 100644 --- a/src/web/CMakeDeps.cmake +++ b/src/web/CMakeDeps.cmake @@ -1 +1 @@ -set(sources ../../externals/linux/include/google/protobuf/descriptor.proto;../../externals/linux/include/google/protobuf/timestamp.proto;../lib/api/apicore.proto;../lib/api/apigateway.proto;../lib/api/apioptions.proto;../lib/api/services/AdminService.proto;../lib/api/services/ApiUnitTestService.proto;../lib/api/services/ErrorReportService.proto;../lib/api/services/HelloService.proto;../lib/api/services/MarketDataAuxiliaryService.proto;../lib/api/services/MarketDataRelay.proto;../lib/api/services/OrderService.proto;../lib/api/services/OutOfProcessURLListener.proto;../lib/api/services/PersistenceService.proto;../lib/api/services/PositionService.proto;../lib/api/services/ShellDiagnosticService.proto;../lib/api/services/ShellLatencyService.proto;../lib/api/services/SyntheticSecurityService.proto;../lib/api/services/UserService.proto;../lib/domain_model/Security.proto;../lib/md/protos/co2.proto;../lib/sparkproto/SparkProtos.proto;api/build.sh;api/node_modules/cssstyle/scripts/run_tests.sh;api/node_modules/exit/test/fixtures/create-files.sh;api/node_modules/protobufjs/cli/node_modules/acorn-jsx/node_modules/acorn/bin/update_authors.sh;api/node_modules/watch/release.sh;api/quiet_build.sh;api/src/DynamicService.ts;api/src/ServiceContext.ts;api/src/bts_assert.ts;ui/src/Access.fs;ui/src/Accounts/ClipLimits.fs;ui/src/Accounts/ProductLimits.fs;ui/src/Accounts/SecurityLimits.fs;ui/src/Accounts/State.fs;ui/src/Accounts/Types.fs;ui/src/Accounts/View.fs;ui/src/App.fs;ui/src/Cmd.fs;ui/src/Controls/Button.fs;ui/src/Controls/DataGrid.fs;ui/src/Controls/Fields.fs;ui/src/Controls/Modal.fs;ui/src/Controls/ReactGrid.fs;ui/src/Controls/Table.fs;ui/src/Controls/nbsp.fs;ui/src/Global.fs;ui/src/Imports.fs;ui/src/Lens.fs;ui/src/Login/Login.fs;ui/src/Nav.fs;ui/src/State.fs;ui/src/Types.fs;ui/src/Users/State.fs;ui/src/Users/Types.fs;ui/src/Users/View.fs;ui/src/Util/EnumUtils.fs;ui/src/Util/JSMap.fs) \ No newline at end of file +set(sources ../../externals/linux/include/google/protobuf/descriptor.proto;../../externals/linux/include/google/protobuf/timestamp.proto;../lib/api/apicore.proto;../lib/api/apigateway.proto;../lib/api/apioptions.proto;../lib/api/services/AdminService.proto;../lib/api/services/ApiUnitTestService.proto;../lib/api/services/ErrorReportService.proto;../lib/api/services/HelloService.proto;../lib/api/services/MarketDataAuxiliaryService.proto;../lib/api/services/MarketDataRelay.proto;../lib/api/services/OrderService.proto;../lib/api/services/OutOfProcessURLListener.proto;../lib/api/services/PersistenceService.proto;../lib/api/services/PositionService.proto;../lib/api/services/ShellDiagnosticService.proto;../lib/api/services/ShellLatencyService.proto;../lib/api/services/SyntheticSecurityService.proto;../lib/api/services/UserService.proto;../lib/domain_model/Security.proto;../lib/md/protos/co2.proto;../lib/sparkproto/SparkProtos.proto;api/build.sh;api/node_modules/cssstyle/scripts/run_tests.sh;api/node_modules/exit/test/fixtures/create-files.sh;api/node_modules/protobufjs/cli/node_modules/acorn-jsx/node_modules/acorn/bin/update_authors.sh;api/node_modules/watch/release.sh;api/quiet_build.sh;api/src/DynamicService.ts;api/src/ServiceContext.ts;api/src/bts_assert.ts;ui/src/Access.fs;ui/src/Accounts/ClipLimits.fs;ui/src/Accounts/ProductLimits.fs;ui/src/Accounts/SecurityLimits.fs;ui/src/Accounts/State.fs;ui/src/Accounts/Types.fs;ui/src/Accounts/View.fs;ui/src/App.fs;ui/src/Cmd.fs;ui/src/Controls/Button.fs;ui/src/Controls/DataGrid.fs;ui/src/Controls/Fields.fs;ui/src/Controls/Modal.fs;ui/src/Controls/ReactGrid.fs;ui/src/Controls/Table.fs;ui/src/Controls/nbsp.fs;ui/src/Global.fs;ui/src/Imports.fs;ui/src/Lens.fs;ui/src/Login/Login.fs;ui/src/Nav.fs;ui/src/State.fs;ui/src/Types.fs;ui/src/Users/State.fs;ui/src/Users/Types.fs;ui/src/Users/View.fs;ui/src/Util/EnumUtils.fs;ui/src/Util/JSMap.fs;ui/src/obj/Debug/netstandard2.0/ui.AssemblyInfo.fs) \ No newline at end of file diff --git a/src/web/api/build.sh b/src/web/api/build.sh index ce45eaddc..921e590a3 100755 --- a/src/web/api/build.sh +++ b/src/web/api/build.sh @@ -1,4 +1,15 @@ #!/bin/bash +export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 +export PATH="$PATH:/root/.dotnet/tools" + +# install npx +if ! [ -x "$(command -v npx)" ]; then + npm install -g npx +fi +# install paket +if ! [ -x "$(command -v paket)" ]; then + dotnet tool install -g paket +fi export OUT=${BUILD_DIR:-../../../build}/web MODE=manual diff --git a/src/web/api/package-lock.json b/src/web/api/package-lock.json index ff3bb0115..f923270ae 100644 --- a/src/web/api/package-lock.json +++ b/src/web/api/package-lock.json @@ -1825,8 +1825,8 @@ "dev": true, "optional": true, "requires": { - "co": "4.6.0", - "json-stable-stringify": "1.0.1" + "co": "^4.6.0", + "json-stable-stringify": "^1.0.1" } }, "ansi-regex": { @@ -1846,8 +1846,8 @@ "dev": true, "optional": true, "requires": { - "delegates": "1.0.0", - "readable-stream": "2.2.9" + "delegates": "^1.0.0", + "readable-stream": "^2.0.6" } }, "asn1": { @@ -1891,7 +1891,7 @@ "dev": true, "optional": true, "requires": { - "tweetnacl": "0.14.5" + "tweetnacl": "^0.14.3" } }, "block-stream": { @@ -1899,7 +1899,7 @@ "bundled": true, "dev": true, "requires": { - "inherits": "2.0.3" + "inherits": "~2.0.0" } }, "boom": { @@ -1907,7 +1907,7 @@ "bundled": true, "dev": true, "requires": { - "hoek": "2.16.3" + "hoek": "2.x.x" } }, "brace-expansion": { @@ -1915,7 +1915,7 @@ "bundled": true, "dev": true, "requires": { - "balanced-match": "0.4.2", + "balanced-match": "^0.4.1", "concat-map": "0.0.1" } }, @@ -1946,7 +1946,7 @@ "bundled": true, "dev": true, "requires": { - "delayed-stream": "1.0.0" + "delayed-stream": "~1.0.0" } }, "concat-map": { @@ -1969,7 +1969,7 @@ "bundled": true, "dev": true, "requires": { - "boom": "2.10.1" + "boom": "2.x.x" } }, "dashdash": { @@ -1978,7 +1978,7 @@ "dev": true, "optional": true, "requires": { - "assert-plus": "1.0.0" + "assert-plus": "^1.0.0" }, "dependencies": { "assert-plus": { @@ -2027,7 +2027,7 @@ "dev": true, "optional": true, "requires": { - "jsbn": "0.1.1" + "jsbn": "~0.1.0" } }, "extend": { @@ -2068,10 +2068,10 @@ "bundled": true, "dev": true, "requires": { - "graceful-fs": "4.1.11", - "inherits": "2.0.3", - "mkdirp": "0.5.1", - "rimraf": "2.6.1" + "graceful-fs": "^4.1.2", + "inherits": "~2.0.0", + "mkdirp": ">=0.5 0", + "rimraf": "2" } }, "fstream-ignore": { @@ -2080,9 +2080,9 @@ "dev": true, "optional": true, "requires": { - "fstream": "1.0.11", - "inherits": "2.0.3", - "minimatch": "3.0.4" + "fstream": "^1.0.0", + "inherits": "2", + "minimatch": "^3.0.0" } }, "gauge": { @@ -2091,14 +2091,14 @@ "dev": true, "optional": true, "requires": { - "aproba": "1.1.1", - "console-control-strings": "1.1.0", - "has-unicode": "2.0.1", - "object-assign": "4.1.1", - "signal-exit": "3.0.2", - "string-width": "1.0.2", - "strip-ansi": "3.0.1", - "wide-align": "1.1.2" + "aproba": "^1.0.3", + "console-control-strings": "^1.0.0", + "has-unicode": "^2.0.0", + "object-assign": "^4.1.0", + "signal-exit": "^3.0.0", + "string-width": "^1.0.1", + "strip-ansi": "^3.0.1", + "wide-align": "^1.1.0" } }, "getpass": { @@ -2107,7 +2107,7 @@ "dev": true, "optional": true, "requires": { - "assert-plus": "1.0.0" + "assert-plus": "^1.0.0" }, "dependencies": { "assert-plus": { @@ -2123,12 +2123,12 @@ "bundled": true, "dev": true, "requires": { - "fs.realpath": "1.0.0", - "inflight": "1.0.6", - "inherits": "2.0.3", - "minimatch": "3.0.4", - "once": "1.4.0", - "path-is-absolute": "1.0.1" + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" } }, "graceful-fs": { @@ -2163,10 +2163,10 @@ "bundled": true, "dev": true, "requires": { - "boom": "2.10.1", - "cryptiles": "2.0.5", - "hoek": "2.16.3", - "sntp": "1.0.9" + "boom": "2.x.x", + "cryptiles": "2.x.x", + "hoek": "2.x.x", + "sntp": "1.x.x" } }, "hoek": { @@ -2180,9 +2180,9 @@ "dev": true, "optional": true, "requires": { - "assert-plus": "0.2.0", - "jsprim": "1.4.0", - "sshpk": "1.13.0" + "assert-plus": "^0.2.0", + "jsprim": "^1.2.2", + "sshpk": "^1.7.0" } }, "inflight": { @@ -2190,8 +2190,8 @@ "bundled": true, "dev": true, "requires": { - "once": "1.4.0", - "wrappy": "1.0.2" + "once": "^1.3.0", + "wrappy": "1" } }, "inherits": { @@ -2236,7 +2236,7 @@ "dev": true, "optional": true, "requires": { - "jsbn": "0.1.1" + "jsbn": "~0.1.0" } }, "jsbn": { @@ -2257,7 +2257,7 @@ "dev": true, "optional": true, "requires": { - "jsonify": "0.0.0" + "jsonify": "~0.0.0" } }, "json-stringify-safe": { @@ -2338,17 +2338,17 @@ "dev": true, "optional": true, "requires": { - "detect-libc": "1.0.2", + "detect-libc": "^1.0.2", "hawk": "3.1.3", - "mkdirp": "0.5.1", - "nopt": "4.0.1", - "npmlog": "4.1.0", - "rc": "1.2.1", + "mkdirp": "^0.5.1", + "nopt": "^4.0.1", + "npmlog": "^4.0.2", + "rc": "^1.1.7", "request": "2.81.0", - "rimraf": "2.6.1", - "semver": "5.3.0", - "tar": "2.2.1", - "tar-pack": "3.4.0" + "rimraf": "^2.6.1", + "semver": "^5.3.0", + "tar": "^2.2.1", + "tar-pack": "^3.4.0" } }, "nopt": { @@ -2357,8 +2357,8 @@ "dev": true, "optional": true, "requires": { - "abbrev": "1.1.0", - "osenv": "0.1.4" + "abbrev": "1", + "osenv": "^0.1.4" } }, "npmlog": { @@ -2367,10 +2367,10 @@ "dev": true, "optional": true, "requires": { - "are-we-there-yet": "1.1.4", - "console-control-strings": "1.1.0", - "gauge": "2.7.4", - "set-blocking": "2.0.0" + "are-we-there-yet": "~1.1.2", + "console-control-strings": "~1.1.0", + "gauge": "~2.7.3", + "set-blocking": "~2.0.0" } }, "number-is-nan": { @@ -2395,7 +2395,7 @@ "bundled": true, "dev": true, "requires": { - "wrappy": "1.0.2" + "wrappy": "1" } }, "os-homedir": { @@ -2416,8 +2416,8 @@ "dev": true, "optional": true, "requires": { - "os-homedir": "1.0.2", - "os-tmpdir": "1.0.2" + "os-homedir": "^1.0.0", + "os-tmpdir": "^1.0.0" } }, "path-is-absolute": { @@ -2454,10 +2454,10 @@ "dev": true, "optional": true, "requires": { - "deep-extend": "0.4.2", - "ini": "1.3.4", - "minimist": "1.2.0", - "strip-json-comments": "2.0.1" + "deep-extend": "~0.4.0", + "ini": "~1.3.0", + "minimist": "^1.2.0", + "strip-json-comments": "~2.0.1" }, "dependencies": { "minimist": { @@ -2473,13 +2473,13 @@ "bundled": true, "dev": true, "requires": { - "buffer-shims": "1.0.0", - "core-util-is": "1.0.2", - "inherits": "2.0.3", - "isarray": "1.0.0", - "process-nextick-args": "1.0.7", - "string_decoder": "1.0.1", - "util-deprecate": "1.0.2" + "buffer-shims": "~1.0.0", + "core-util-is": "~1.0.0", + "inherits": "~2.0.1", + "isarray": "~1.0.0", + "process-nextick-args": "~1.0.6", + "string_decoder": "~1.0.0", + "util-deprecate": "~1.0.1" } }, "request": { @@ -2488,28 +2488,28 @@ "dev": true, "optional": true, "requires": { - "aws-sign2": "0.6.0", - "aws4": "1.6.0", - "caseless": "0.12.0", - "combined-stream": "1.0.5", - "extend": "3.0.1", - "forever-agent": "0.6.1", - "form-data": "2.1.4", - "har-validator": "4.2.1", - "hawk": "3.1.3", - "http-signature": "1.1.1", - "is-typedarray": "1.0.0", - "isstream": "0.1.2", - "json-stringify-safe": "5.0.1", - "mime-types": "2.1.15", - "oauth-sign": "0.8.2", - "performance-now": "0.2.0", - "qs": "6.4.0", - "safe-buffer": "5.0.1", - "stringstream": "0.0.5", - "tough-cookie": "2.3.2", - "tunnel-agent": "0.6.0", - "uuid": "3.0.1" + "aws-sign2": "~0.6.0", + "aws4": "^1.2.1", + "caseless": "~0.12.0", + "combined-stream": "~1.0.5", + "extend": "~3.0.0", + "forever-agent": "~0.6.1", + "form-data": "~2.1.1", + "har-validator": "~4.2.1", + "hawk": "~3.1.3", + "http-signature": "~1.1.0", + "is-typedarray": "~1.0.0", + "isstream": "~0.1.2", + "json-stringify-safe": "~5.0.1", + "mime-types": "~2.1.7", + "oauth-sign": "~0.8.1", + "performance-now": "^0.2.0", + "qs": "~6.4.0", + "safe-buffer": "^5.0.1", + "stringstream": "~0.0.4", + "tough-cookie": "~2.3.0", + "tunnel-agent": "^0.6.0", + "uuid": "^3.0.0" } }, "rimraf": { @@ -2517,7 +2517,7 @@ "bundled": true, "dev": true, "requires": { - "glob": "7.1.2" + "glob": "^7.0.5" } }, "safe-buffer": { @@ -2548,7 +2548,7 @@ "bundled": true, "dev": true, "requires": { - "hoek": "2.16.3" + "hoek": "2.x.x" } }, "sshpk": { @@ -2557,15 +2557,15 @@ "dev": true, "optional": true, "requires": { - "asn1": "0.2.3", - "assert-plus": "1.0.0", - "bcrypt-pbkdf": "1.0.1", - "dashdash": "1.14.1", - "ecc-jsbn": "0.1.1", - "getpass": "0.1.7", - "jodid25519": "1.0.2", - "jsbn": "0.1.1", - "tweetnacl": "0.14.5" + "asn1": "~0.2.3", + "assert-plus": "^1.0.0", + "bcrypt-pbkdf": "^1.0.0", + "dashdash": "^1.12.0", + "ecc-jsbn": "~0.1.1", + "getpass": "^0.1.1", + "jodid25519": "^1.0.0", + "jsbn": "~0.1.0", + "tweetnacl": "~0.14.0" }, "dependencies": { "assert-plus": { @@ -2581,9 +2581,9 @@ "bundled": true, "dev": true, "requires": { - "code-point-at": "1.1.0", - "is-fullwidth-code-point": "1.0.0", - "strip-ansi": "3.0.1" + "code-point-at": "^1.0.0", + "is-fullwidth-code-point": "^1.0.0", + "strip-ansi": "^3.0.0" } }, "string_decoder": { @@ -2591,7 +2591,7 @@ "bundled": true, "dev": true, "requires": { - "safe-buffer": "5.0.1" + "safe-buffer": "^5.0.1" } }, "stringstream": { @@ -2605,7 +2605,7 @@ "bundled": true, "dev": true, "requires": { - "ansi-regex": "2.1.1" + "ansi-regex": "^2.0.0" } }, "strip-json-comments": { @@ -2619,9 +2619,9 @@ "bundled": true, "dev": true, "requires": { - "block-stream": "0.0.9", - "fstream": "1.0.11", - "inherits": "2.0.3" + "block-stream": "*", + "fstream": "^1.0.2", + "inherits": "2" } }, "tar-pack": { @@ -2630,14 +2630,14 @@ "dev": true, "optional": true, "requires": { - "debug": "2.6.8", - "fstream": "1.0.11", - "fstream-ignore": "1.0.5", - "once": "1.4.0", - "readable-stream": "2.2.9", - "rimraf": "2.6.1", - "tar": "2.2.1", - "uid-number": "0.0.6" + "debug": "^2.2.0", + "fstream": "^1.0.10", + "fstream-ignore": "^1.0.5", + "once": "^1.3.3", + "readable-stream": "^2.1.4", + "rimraf": "^2.5.1", + "tar": "^2.2.1", + "uid-number": "^0.0.6" } }, "tough-cookie": { @@ -2646,7 +2646,7 @@ "dev": true, "optional": true, "requires": { - "punycode": "1.4.1" + "punycode": "^1.4.1" } }, "tunnel-agent": { @@ -2655,7 +2655,7 @@ "dev": true, "optional": true, "requires": { - "safe-buffer": "5.0.1" + "safe-buffer": "^5.0.1" } }, "tweetnacl": { @@ -2696,7 +2696,7 @@ "dev": true, "optional": true, "requires": { - "string-width": "1.0.2" + "string-width": "^1.0.2" } }, "wrappy": { diff --git a/src/web/api/src/ServiceContext.ts b/src/web/api/src/ServiceContext.ts index 6e17094ab..c0efa340d 100644 --- a/src/web/api/src/ServiceContext.ts +++ b/src/web/api/src/ServiceContext.ts @@ -64,7 +64,9 @@ class PrivateContext { // Switch to steady state onmessage this.ws.onmessage = e => this.onmessage(e) console.log("Authenticated") + this.sc.username = this.username this.sc.token = response.logon.token + this.sc.can_create = response.logon.canCreate resolve(this.sc) } else { @@ -120,8 +122,10 @@ class PrivateContext { export class ServiceContext { next_id : number - send : (msg)=>void - token : string + send: (msg) => void + username: string + token: string + can_create: boolean outstanding : { [request:number]:{ resolve : (buffer)=>void, reject: (msg)=>void } } constructor(send : (msg)=>void) { diff --git a/src/web/ui/.paket/Paket.Restore.targets b/src/web/ui/.paket/Paket.Restore.targets index f98079998..218d16919 100644 --- a/src/web/ui/.paket/Paket.Restore.targets +++ b/src/web/ui/.paket/Paket.Restore.targets @@ -11,25 +11,9 @@ $(MSBuildThisFileDirectory)..\ $(PaketRootPath)paket-files\paket.restore.cached $(PaketRootPath)paket.lock - /Library/Frameworks/Mono.framework/Commands/mono - mono - $(PaketRootPath)paket.exe - $(PaketToolsPath)paket.exe - "$(PaketExePath)" - $(MonoPath) --runtime=v4.0.30319 "$(PaketExePath)" - - - <_PaketExeExtension>$([System.IO.Path]::GetExtension("$(PaketExePath)")) - dotnet "$(PaketExePath)" - - - "$(PaketExePath)" - - $(PaketRootPath)paket.bootstrapper.exe - $(PaketToolsPath)paket.bootstrapper.exe - "$(PaketBootStrapperExePath)" - $(MonoPath) --runtime=v4.0.30319 "$(PaketBootStrapperExePath)" + paket + paket diff --git a/src/web/ui/.paket/paket.exe b/src/web/ui/.paket/paket.exe deleted file mode 100644 index 809cc4448..000000000 Binary files a/src/web/ui/.paket/paket.exe and /dev/null differ diff --git a/src/web/ui/.paket/paket.exe.config b/src/web/ui/.paket/paket.exe.config deleted file mode 100644 index cba16197e..000000000 --- a/src/web/ui/.paket/paket.exe.config +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - True - - - - - - - True - - - - - - - - \ No newline at end of file diff --git a/src/web/ui/src/Access.fs b/src/web/ui/src/Access.fs index 4241744d2..f625884e9 100644 --- a/src/web/ui/src/Access.fs +++ b/src/web/ui/src/Access.fs @@ -5,10 +5,11 @@ open bts.api open Elmish open bts.api.orderman -let getAdminData (admin:IAdminService) (fsuc) (ffail) = +let superuser = "bts" + +let getAdminData (admin:IAdminService) (token) (fsuc) (ffail) = Cmd.ofPromise - admin.get_admin_data - () + admin.get_filtered_admin_data { token = token } fsuc (fun e -> ffail e.Message) diff --git a/src/web/ui/src/Accounts/State.fs b/src/web/ui/src/Accounts/State.fs index 2af6e8cd8..9be77a425 100644 --- a/src/web/ui/src/Accounts/State.fs +++ b/src/web/ui/src/Accounts/State.fs @@ -33,8 +33,11 @@ let init (context:ServiceContext.ServiceContext) = ConfirmModal = "", (Msg.SelectTab General) SelectedClipLimits = [] SelectedPositionLimits = [] + token = context.token + can_create = context.can_create + this_username = context.username ShowLoading = false - }, Access.getAdminData admin UpdateAdminData NoAdminData + }, Access.getAdminData admin context.token UpdateAdminData NoAdminData let existingSelection (scratch:BTSAccount) (previousScratch:BTSAccount) (data:AdminData) = List.choose id [ @@ -70,39 +73,39 @@ let applySIMUpdate (data:SIMAccountData) = function | Origin v -> { data with origin = v } | ClearingAccount v -> { data with clearingAccount = v } -let saveAccount (admin:IAdminService) (account:BTSAccount) = promise { +let saveAccount (admin:IAdminService) (account:BTSAccount) (model:Model) = promise { let! result = admin.update_account { completeData = account } if result.isSuccess then - let! data = admin.get_admin_data() + let! data = admin.get_filtered_admin_data {token = model.token} return UpdateAdminData data else return ErrorOccured (sprintf "Error saving account: %s" result.errorText) } -let createAccount (admin:IAdminService) (account:BTSAccount) = promise { - let args = { parentAccountId = 0u; accountName = account.name; description = account.description } +let createAccount (admin:IAdminService) (account:BTSAccount) (model:Model) = promise { + let args = { parentAccountId = 0u; accountName = account.name; description = account.description; creatorUser = model.this_username } let! result = admin.create_account args if result.isSuccess then - return! saveAccount admin { account with id = result.newId } + return! saveAccount admin { account with id = result.newId } model else return ErrorOccured (sprintf "Error creating account: %s" result.errorText) } -let deleteAccount (admin:IAdminService) (account:BTSAccount) = promise { +let deleteAccount (admin:IAdminService) (account:BTSAccount) (model:Model) = promise { let! result = admin.delete_account { id = account.id } if result.isSuccess then - let! data = admin.get_admin_data() + let! data = admin.get_filtered_admin_data {token = model.token} return UpdateAdminData data else return ErrorOccured (sprintf "Error deleting account: %s" result.errorText) } -let cancelOrders (admin:IAdminService) (accountName:string) (orders:OrdersSummaryUnit list) = promise { +let cancelOrders (admin:IAdminService) (accountName:string) (orders:OrdersSummaryUnit list) (model:Model) = promise { let users = (Array.map (fun (ord:OrdersSummaryUnit) -> ord.user) (Array.ofList orders)) let accounts = [| accountName |] let! result = admin.cancel_orders {accounts = accounts; users = users } - let! data = admin.get_admin_data() + let! data = admin.get_filtered_admin_data {token = model.token} return UpdateAdminData data } @@ -177,7 +180,7 @@ let update msg (model:Model) : Model * Cmd = | CancelOrders orders -> { model with ConfirmModal = ("", Msg.SelectTab model.tab); SelectedOrders = []; ShowLoading = true }, Cmd.batch [ - Cmd.ofExistingPromise (cancelOrders model.admin model.scratch.name orders) id (box>>ErrorOccured) + Cmd.ofExistingPromise (cancelOrders model.admin model.scratch.name orders model ) id (box>>ErrorOccured) Cmd.ofExistingPromise (promise { do! Promise.sleep 1000 return GetOrdersData @@ -195,15 +198,17 @@ let update msg (model:Model) : Model * Cmd = | DeleteAccount account -> let mdl = { model with OptionsMenuOpen = ""} match Fable.Import.Browser.window.confirm (sprintf "Are you sure you want to delete '%s'" account.name) with - | true -> mdl, Cmd.ofExistingPromise (deleteAccount model.admin account) id (box>>ErrorOccured) + | true -> mdl, Cmd.ofExistingPromise (deleteAccount model.admin account model ) id (box>>ErrorOccured) | false -> mdl, Cmd.Empty | AddAccount -> + match model.can_create with // Create a new scratch account. Send to server after user has filled in details - { model with previousScratch = model.scratch; scratch = { emptyAccount with name = "New Account" } }, Cmd.ofMsg <| SelectTab General + | true-> { model with previousScratch = model.scratch; scratch = { emptyAccount with name = "New Account" } }, Cmd.ofMsg <| SelectTab General + | false-> model, Cmd.Empty | SaveScratch -> match isNewAccount model.scratch with - | true -> model, Cmd.ofExistingPromise (createAccount model.admin model.scratch) id (box>>ErrorOccured) - | false -> model, Cmd.ofExistingPromise (saveAccount model.admin model.scratch) id (box>>ErrorOccured) + | true -> model, Cmd.ofExistingPromise (createAccount model.admin model.scratch model ) id (box>>ErrorOccured) + | false -> model, Cmd.ofExistingPromise (saveAccount model.admin model.scratch model ) id (box>>ErrorOccured) | ErrorOccured msg -> Global.alert Global.Error (string msg) Browser.console.log msg diff --git a/src/web/ui/src/Accounts/Types.fs b/src/web/ui/src/Accounts/Types.fs index c47804b24..f249085bf 100644 --- a/src/web/ui/src/Accounts/Types.fs +++ b/src/web/ui/src/Accounts/Types.fs @@ -14,8 +14,9 @@ type Tab = | ConnectionsTab | OrdersTab -let venues = Venue.values |> Array.skip 1 -let securityTypes = SecurityType.values |> Array.skip 1 +let venues = [| Venue.GLBX; Venue.SIM |] + +let securityTypes = [| SecurityType.FUTURE; SecurityType.SPREAD |] let emptyAccount = Access.Accounts.empty @@ -104,5 +105,8 @@ type Model = { SelectedPositionLimits: AccountProductPositionLimitUnit list OptionsMenuOpen:string ConfirmModal: string * Msg + token: string + can_create: bool + this_username: string ShowLoading: bool } \ No newline at end of file diff --git a/src/web/ui/src/Accounts/View.fs b/src/web/ui/src/Accounts/View.fs index cfe0341b3..547808baf 100644 --- a/src/web/ui/src/Accounts/View.fs +++ b/src/web/ui/src/Accounts/View.fs @@ -12,6 +12,8 @@ open System open bts.co2 +let accountIsSelected (initialState:BTSAccount) (scratch:BTSAccount) = scratch <> initialState + let selectedAccount model = match model.adminData with | Some data -> @@ -61,7 +63,7 @@ let generalView model dispatch = (div [] [ Fields.text "Name" account.name [] (AccountName >> Update >> dispatch) Fields.text "Description" account.description [] (Description >> Update >> dispatch) - Fields.checkbox "Can Trade Into Account" "Unchecking this stops all users from entering orders into the account" account.isActive [] (IsActive >> 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 @@ -71,8 +73,8 @@ let generalView model dispatch = br [] Fields.text "Name" account.name [] (AccountName >> Update >> dispatch) Fields.text "Description" account.description [] (Description >> Update >> dispatch) - Fields.checkbox "Can Trade Into Account" "Unchecking this stops all users from entering orders into the account" account.isActive [] (IsActive >> Update >> dispatch) - (if State.isNewAccount account then modal else span[][]) + 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 ] @@ -745,13 +747,15 @@ let exchangeSettings model dispatch = let tabContent model dispatch = div [Key (string model.scratch.id); ClassName "is-tab-content"] [ - (match model.tab with - | General -> generalView model dispatch - | LimitsTab -> LimitsView model dispatch - | ConnectionsTab -> ConnectionsView model dispatch - | CreditLimitsTab -> creditLimitsView model dispatch - | ExchangeSettingsTab -> exchangeSettings model dispatch - | OrdersTab -> ordersView model dispatch) + // (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) ] let isActive account = function @@ -817,65 +821,42 @@ let accountSelectionGrid (accountList:BTSAccount list) (currentAccount:BTSAccoun ] - -let selectionPageContent (adminData:AdminData) (model:Model) (dispatch:Msg->Unit) = - 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 "Can Trade Into Account" "Unchecking this stops all users from entering orders into the account" account.isActive [] (IsActive >> Update >> dispatch) - ]) - (fun _ -> dispatch SaveScratch) - revertFun - - div [] [ - accountSelectionGrid (Array.toList adminData.accounts) model.scratch dispatch - //NavRoot data.accounts (selectedAccount model) dispatch - (if State.isNewAccount model.scratch then modal else span[][]) - ] - let menuItem account selectedAccount model dispatch = a [ ClassName (isActive account selectedAccount) OnClick (fun _ -> SelectAccount account |> dispatch) ] [ span [] [ str account.name ] - 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" + (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" ] - ] - ] - ] - ] + ] + [ 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 = @@ -884,7 +865,14 @@ let NavRoot (accounts:BTSAccount[]) selectedAccount model dispatch = [ p [ Class "menu-label" ] [ span [Class "is-size-4"] [str "Accounts"] span [ Class "is-pulled-right circle-icon" ] - [ Button.fabutton "Add Account" "plus-circle" "" Button.Enabled (fun _ -> dispatch AddAccount) ] + (if model.can_create then + [ Button.fabutton + "Add Account" + "plus-circle" + "" + Button.Enabled + (fun _ -> dispatch AddAccount) ] + else []) ] ul [ Class "menu-list" ] @@ -926,14 +914,15 @@ let root (model:Model) dispatch = [ NavRoot data.accounts (selectedAccount model) model dispatch div [ Class "column is-main-content" ] [ + div [ ClassName "tabs is-boxed" ] [ ul [] [ - tabHeader General model.tab dispatch - tabHeader LimitsTab model.tab dispatch - tabHeader ConnectionsTab model.tab dispatch + (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 - tabHeader ExchangeSettingsTab model.tab dispatch - tabHeader OrdersTab 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 [][] ) ] ] tabContent model dispatch diff --git a/src/web/ui/src/Controls/Button.fs b/src/web/ui/src/Controls/Button.fs index 7caf22245..3352611a6 100644 --- a/src/web/ui/src/Controls/Button.fs +++ b/src/web/ui/src/Controls/Button.fs @@ -11,6 +11,14 @@ type IsDisabled = let isDisabled = function | Disabled -> true | Enabled -> false + +type IsHidden = + | Hidden + | Visible + +let isHidden = function + | Hidden -> true + | Visible -> false let boolToDisabledConverter d = match d with diff --git a/src/web/ui/src/Controls/Fields.fs b/src/web/ui/src/Controls/Fields.fs index a81122410..20cd5876e 100644 --- a/src/web/ui/src/Controls/Fields.fs +++ b/src/web/ui/src/Controls/Fields.fs @@ -193,15 +193,18 @@ let radioButton (lbl:string) (description:string) (dv:bool) (attrs:IHTMLProp lis ] -let mapSelect (lbl:string) (options:Map) (defaultText:string option) (defaultValue:string option) (onchange:'a->unit) = +let mapSelectEx (lbl:string) (options:Map) (defaultText:string option) (defaultValue:string option) (onchange:'a->unit) (is_disabled:bool option) = + let dis = match is_disabled with + | None -> false + | Some a -> a + let optList:ReactElement list = match defaultText with | None -> ([ for opt in options do yield option [ Value opt.Key ] [ str (opt.Value) ] ]) | Some dt -> (option [] [str dt]) :: ([ for opt in options do yield option [ Value opt.Key ] [ str (opt.Value) ] ]) let dv = match defaultValue with - | Some d -> - d + | Some d -> d | None -> "" @@ -210,17 +213,21 @@ let mapSelect (lbl:string) (options:Map) (defaultText:string opti Label lbl div [ ClassName "control" ] [ - div [ ClassName "select" ] + div [ ClassName "select"] [ select [ Value dv OnChange (fun ev -> !!ev.target?value |> onchange) + Disabled dis ] optList ] ] ] +let mapSelect (lbl:string) (options:Map) (defaultText:string option) (defaultValue:string option) (onchange:'a->unit) = + mapSelectEx lbl options defaultText defaultValue onchange (Some false) + let simpleSelect (lbl:string) (options:string list) (defaultValue:string) (onchange:'a->unit) = div [ ClassName "field" ] diff --git a/src/web/ui/src/Login/Login.fs b/src/web/ui/src/Login/Login.fs index 20d9d49e9..fd09d561d 100644 --- a/src/web/ui/src/Login/Login.fs +++ b/src/web/ui/src/Login/Login.fs @@ -43,10 +43,7 @@ let update msg model = model, Cmd.Empty | Submit -> printfn "Login with %s %s" model.user model.password - let isAdmin = ((model.user.ToLower().Contains "bts") || (model.user.ToLower().Contains "admin")) - match isAdmin with - | true -> model, loginMsg (model.user.ToLower()) model.password - | false -> { model with error = "Only administrators are allowed to login" }, Cmd.Empty + model, loginMsg (model.user.ToLower()) model.password | LoginFailure msg -> { model with error = msg }, Cmd.Empty | LoginSuccess _ -> failwith "Handled externally. Should not get here." diff --git a/src/web/ui/src/Nav.fs b/src/web/ui/src/Nav.fs index dccdc36f1..d272169e6 100644 --- a/src/web/ui/src/Nav.fs +++ b/src/web/ui/src/Nav.fs @@ -52,7 +52,7 @@ let root (currentPage:Page) (sc:ServiceContext) dispatch = [ div [ ClassName "icon is-large" ] [ i [ ClassName "fa fa-3x fa-sign-out" ] [] ] - div [] [str "Logout"] + div [] [str ("Logout \n" + sc.username)] ] ] ] diff --git a/src/web/ui/src/Users/State.fs b/src/web/ui/src/Users/State.fs index e8b73011e..6e288c739 100644 --- a/src/web/ui/src/Users/State.fs +++ b/src/web/ui/src/Users/State.fs @@ -17,14 +17,18 @@ let SMPInstructionMap:Map = Map.empty .Add("N", "Cancel Aggressing") .Add("", "Undefined") - let isNewUser (user:BTSUser) = user.id = 0u && user.isPresent -let getAdminData (admin:IAdminService) = +// let getUserData (user:IUserService) username password = +// Cmd.ofPromise +// user.authenticate_login { login = username; password = password} +// (fun u -> UpdateAdminAuthData u.adminData) +// (fun _ -> RpcResponse "Error getting admin auth data") + +let getAdminData (admin:IAdminService) (token:string) = Cmd.ofPromise - admin.get_admin_data - () + admin.get_filtered_admin_data { token = token } UpdateAdminData (fun _ -> RpcResponse "Error getting admin data") @@ -32,9 +36,12 @@ let defaultScratchUser = { isPresent = true id = 0u parentGroupId = 1u - isActive = false + isActive = true + canCreate = false name = "" password = "" + fullName = "" + company = "" licenseData = { createDate = 0L @@ -53,6 +60,7 @@ let defaultScratchUser = { exchangeUserData = { cmeData = { + adminDisplayFlag = bts.api.admin.CMEUserData.AdminDisplay.None operatorId = "" atsOperatorId = "" smpId = "" @@ -62,6 +70,8 @@ let defaultScratchUser = { smpInstruction = "" maxOrderRatePerConnection = "" location = "" + proNonpro = ProfessionalDesignation.PRO + displayNondisplay = DisplayDesignation.DISPLAY mdPermissions = [||] } simData = { @@ -92,18 +102,22 @@ let defaultScratchUser = { } let init (context:ServiceContext.ServiceContext) : Model * Cmd = + //let user = UserService.Create context "" let admin = AdminService.Create context "" { userList = [] accountsList = [] scratchUser = defaultScratchUser PreviousScratchUser = defaultScratchUser - currentTab = Tab.General + currentTab = Tab.General admin = admin adminData = None OptionsMenuOpen = "" ConfirmModal = "", (Msg.SwitchTab Tab.General) - }, getAdminData admin + token = context.token + can_create = context.can_create + this_username = context.username + }, getAdminData admin context.token let rec removeUser (user:BTSUser) (userList:BTSUser list) = match userList with @@ -139,35 +153,37 @@ let userIsdirty (initialState:BTSUser) (scratch:BTSUser) (existing:BTSUser) = (s let userIsSelected (initialState:BTSUser) (scratch:BTSUser) = scratch <> initialState -let saveUser (admin:IAdminService) (user:BTSUser) = promise { +let saveUser (admin:IAdminService) (user:BTSUser) (model:Model) = promise { let! result = admin.update_user { completeData = user } if (result.isSuccess) then - let! data = admin.get_admin_data() + let! data = admin.get_filtered_admin_data {token = model.token} return UpdateAdminData data else return ErrorOccured (sprintf "Error saving user: %s" result.errorText) } -let deleteUser (admin:IAdminService) (user:BTSUser) = promise { +let deleteUser (admin:IAdminService) (user:BTSUser) (model:Model) = promise { let! result = admin.delete_user { id = user.id } if (result.isSuccess) then - let! data = admin.get_admin_data() + let! data = admin.get_filtered_admin_data {token = model.token} return UpdateAdminData data else return ErrorOccured (sprintf "Error deleting user: %s" result.errorText) } -let createUser (admin:IAdminService) (user:BTSUser) = promise { - let args = { +let createUser (admin:IAdminService) (user:BTSUser) (model:Model)= promise { + let args : UserCreateAPIArgument = { parentGroupId = user.parentGroupId name = user.name password = user.password + fullName = user.fullName + company = user.company licenseData = user.licenseData licenseEntitlements = user.licenseEntitlements - } + } let! result = admin.create_user args if result.isSuccess then - return! saveUser admin { user with id = result.newId } + return! saveUser admin { user with id = result.newId } model else return ErrorOccured (sprintf "Error creating user: %s" result.errorText) } @@ -176,16 +192,39 @@ let updateExchangeMdEntitlementDataCMEData user dta :BTSUser = { user with userD let updateCMEExchangeUserData user dta = { user with userData = { user.userData with exchangeUserData = { user.userData.exchangeUserData with cmeData = dta }}} let updateSIMExchangeUserData user dta = { user with userData = { user.userData with exchangeUserData = { user.userData.exchangeUserData with simData = dta }}} +let default_user_account = { + tradingPermission = { + hasPermissions = false + submitMarketOrders = false + submitGtcOrders = false + algoTradingPermission = { + submitIcebergOrders = false + submitTimeBoxOrders = false + submitSpreaderOrders = false + } + } + adminPermission = { + hasPermissions = false + hasMdPermissions = false + } +} + + let applyUpdate (field:UserField) (user:BTSUser) = match field with | Name n -> { user with name = n } | Password p -> { user with password = p } + | FullName fn -> { user with fullName = fn } + | Company cc -> { user with company = cc } | IsActive ia -> { user with isActive = ia } + | CanCreate cr -> { user with canCreate = cr } | CMEOperatorID oid -> updateCMEExchangeUserData user { user.userData.exchangeUserData.cmeData with operatorId = oid } | CMEATSOperatorID atsoid -> updateCMEExchangeUserData user { user.userData.exchangeUserData.cmeData with atsOperatorId = atsoid } | SimOperatorID oid -> updateSIMExchangeUserData user { user.userData.exchangeUserData.simData with operatorId = oid } | SMPID smpid -> updateCMEExchangeUserData user { user.userData.exchangeUserData.cmeData with smpId = smpid } | CMELocation loc -> updateCMEExchangeUserData user { user.userData.exchangeUserData.cmeData with location = loc } + | CMEProNonPro loc -> updateCMEExchangeUserData user { user.userData.exchangeUserData.cmeData with proNonpro = loc } + | CMEDisplayNonDisplay loc -> updateCMEExchangeUserData user { user.userData.exchangeUserData.cmeData with displayNondisplay = loc } | SimLocation loc -> updateSIMExchangeUserData user { user.userData.exchangeUserData.simData with location = loc } | SMPInstruction smpi -> updateCMEExchangeUserData user { user.userData.exchangeUserData.cmeData with smpInstruction = smpi } | MaxOrderRatePerConnection morpc -> updateCMEExchangeUserData user { user.userData.exchangeUserData.cmeData with maxOrderRatePerConnection = morpc } @@ -201,19 +240,27 @@ let applyUpdate (field:UserField) (user:BTSUser) = mdperm | None -> Array.concat [[|mic|]; mdperm] updateCMEExchangeUserData user { user.userData.exchangeUserData.cmeData with mdPermissions = micArr } - | AddAccount id -> - let tmpPermissions = - { adminPermission = { hasPermissions = true } - tradingPermission = - { submitMarketOrders = true - submitGtcOrders = false - algoTradingPermission = - { submitIcebergOrders = false - submitTimeBoxOrders = false - submitSpreaderOrders = false } } } - let newAccountPermissions = JSMap.add id tmpPermissions user.userData.accountPermissions.accountPermissions - let newUserData = { user.userData with accountPermissions = { user.userData.accountPermissions with accountPermissions = newAccountPermissions } } - { user with userData = newUserData } + | TradingPerm (id:string, can_trade:bool) -> + let find = JSMap.tryFind id user.userData.accountPermissions.accountPermissions + let current = if find.IsNone then default_user_account else find.Value + let updated = { current with tradingPermission = { current.tradingPermission with hasPermissions = can_trade } } + let newAccountPermissions = JSMap.add id updated user.userData.accountPermissions.accountPermissions + let newUserData = { user.userData with accountPermissions = { user.userData.accountPermissions with accountPermissions = newAccountPermissions } } + { user with userData = newUserData } + | RiskAdmin (id, admin) -> + let find = JSMap.tryFind id user.userData.accountPermissions.accountPermissions + let current = if find.IsNone then default_user_account else find.Value + let updated = { current with adminPermission = { current.adminPermission with hasPermissions = admin } } + let newAccountPermissions = JSMap.add id updated user.userData.accountPermissions.accountPermissions + let newUserData = { user.userData with accountPermissions = { user.userData.accountPermissions with accountPermissions = newAccountPermissions } } + { user with userData = newUserData } + | MDAdmin (id, admin) -> + let find = JSMap.tryFind id user.userData.accountPermissions.accountPermissions + let current = if find.IsNone then default_user_account else find.Value + let updated = { current with adminPermission = { current.adminPermission with hasMdPermissions = admin } } + let newAccountPermissions = JSMap.add id updated user.userData.accountPermissions.accountPermissions + let newUserData = { user.userData with accountPermissions = { user.userData.accountPermissions with accountPermissions = newAccountPermissions } } + { user with userData = newUserData } | RemoveAccount id -> let newObj = JSMap.remove id user.userData.accountPermissions.accountPermissions @@ -242,18 +289,22 @@ let update msg (model:Users.Types.Model) : Model * Cmd = id = usrDest.id name = usrDest.name password = usrDest.password + fullName = usrDest.fullName + company = usrDest.company isActive = usrDest.isActive } - { model with scratchUser = nusr }, Cmd.Empty + { model with scratchUser = nusr }, Cmd.Empty | Delete usr -> let mdl = { model with OptionsMenuOpen = "" } match Fable.Import.Browser.window.confirm (sprintf "Are you sure you want to delete '%s'" usr.name) with - | true -> mdl, Cmd.ofExistingPromise (deleteUser model.admin usr) id (box>>ErrorOccured) + | true -> mdl, Cmd.ofExistingPromise (deleteUser model.admin usr model) id (box>>ErrorOccured) | false -> mdl, Cmd.Empty | AddUser -> - { model with PreviousScratchUser = model.scratchUser; scratchUser = { defaultScratchUser with name = "New User" }}, Cmd.ofMsg (SwitchTab General) + match model.can_create with + | true -> { model with PreviousScratchUser = model.scratchUser; scratchUser = { defaultScratchUser with name = "New User" }}, Cmd.ofMsg (SwitchTab General) + | false -> model, Cmd.Empty | CancelAddUser -> { model with scratchUser = { model.PreviousScratchUser with name = "New User" }}, Cmd.ofMsg (SwitchTab General) | SwitchTab tb -> @@ -264,8 +315,8 @@ let update msg (model:Users.Types.Model) : Model * Cmd = | SaveUser -> // match on id = 0 to see if it's a new user match model.scratchUser.id with - | 0u -> { model with PreviousScratchUser = model.scratchUser}, Cmd.ofExistingPromise (createUser model.admin {model.scratchUser with name = model.scratchUser.name.ToLower() }) id (box>>ErrorOccured) - | _ -> model, Cmd.ofExistingPromise (saveUser model.admin {model.scratchUser with name = model.scratchUser.name.ToLower() }) id (box>>ErrorOccured) + | 0u -> { model with PreviousScratchUser = model.scratchUser}, Cmd.ofExistingPromise (createUser model.admin {model.scratchUser with name = model.scratchUser.name.ToLower() } model) id (box>>ErrorOccured) + | _ -> model, Cmd.ofExistingPromise (saveUser model.admin {model.scratchUser with name = model.scratchUser.name.ToLower() } model) id (box>>ErrorOccured) | ErrorOccured msg -> //Browser.console.log msg Global.alert Global.Error (string msg) diff --git a/src/web/ui/src/Users/Types.fs b/src/web/ui/src/Users/Types.fs index 1beeb47f8..869e2f2b9 100644 --- a/src/web/ui/src/Users/Types.fs +++ b/src/web/ui/src/Users/Types.fs @@ -12,7 +12,10 @@ type Tab = type UserField = | Name of string | Password of string +| FullName of string +| Company of string | IsActive of bool +| CanCreate of bool | CMEOperatorID of string | CMEATSOperatorID of string | SimOperatorID of string @@ -22,9 +25,13 @@ type UserField = | SMPInstruction of string | MaxOrderRatePerConnection of string | MiscTags of JSMap -| AddAccount of string +| TradingPerm of string * bool +| RiskAdmin of string*bool +| MDAdmin of string*bool | RemoveAccount of string | CMEMic of CMEMicData +| CMEProNonPro of ProfessionalDesignation +| CMEDisplayNonDisplay of DisplayDesignation type Msg = @@ -53,4 +60,14 @@ type Model = { adminData : AdminData option OptionsMenuOpen: string ConfirmModal: string * Msg + token: string + can_create: bool + this_username: string } + + +let CMEMicMap:Map = Map.empty + .Add("XCME", bts.api.CMEMics.CME) + .Add("XNYM", bts.api.CMEMics.NYMEX) + .Add("XCBT", bts.api.CMEMics.CBT) + .Add("XCEC", bts.api.CMEMics.COMEX) \ No newline at end of file diff --git a/src/web/ui/src/Users/View.fs b/src/web/ui/src/Users/View.fs index 5388afa8c..ba2c57828 100644 --- a/src/web/ui/src/Users/View.fs +++ b/src/web/ui/src/Users/View.fs @@ -11,6 +11,8 @@ open Users open bts.api.admin open Users open bts.api +open EnumUtils +open Microsoft.FSharp.Collections; let isActiveTab tab currentTab = let ia = "is-active" @@ -37,24 +39,87 @@ let saveButton (model:Users.Types.Model) dispatch = 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 SaveUser) + -let generalTabView (model:Model) (dispatch:Msg->Unit) = +let accountIDLookup (accountsList:BTSAccount list) (id:string) = + match (List.tryFind (fun a -> a.id.ToString() = id) accountsList) with + | Some acnt -> acnt.id.ToString() + | None -> "" + + +let generalTabView (model:Model) (dispatch:Msg->Unit) (readonly: bool)= + let accMap = + model.accountsList + |> List.filter (fun a -> a.isPresent) + |> List.map (fun a -> a.id.ToString(), a.name) + |> Map.ofList + + let hasPermission (acctid) = + let found = JSMap.tryFind (acctid.ToString()) model.scratchUser.userData.accountPermissions.accountPermissions + match found with + | None -> false + | Some a -> a.tradingPermission.hasPermissions + + let acctlist = model.accountsList |> List.filter (fun a -> a.isPresent) + + let hasOnePermission = + let found = + [ + for entry in acctlist do + yield JSMap.tryFind (entry.id.ToString()) model.scratchUser.userData.accountPermissions.accountPermissions + ] |> List.choose id + + let trues = + List.choose (fun x -> + match x.tradingPermission.hasPermissions with + | true -> Some x + | false -> None + ) found + + match List.length (trues) with + | 0 -> false + | _ -> true + + + let checkboxes = + [ + for acc in acctlist do + yield span [] [ + Fields.checkbox acc.name "" (hasPermission acc.id) [] ( fun x-> (acc.id.ToString(), x) |> TradingPerm |> UpdateField |> dispatch ) + ] + ] + + let can_create = model.can_create || (model.this_username = Access.superuser) + let can_login_disabled = readonly || (model.this_username = model.scratchUser.name) let modal = Modal.showCreate "Create User" (div [][ - Fields.text "Name" model.scratchUser.name [ ] (Name >> UpdateField >> dispatch) - Fields.password "Password" model.scratchUser.password [ ] (Password >> UpdateField >> dispatch) - Fields.checkbox "Active" "Unchecking this stops the user from entering orders" model.scratchUser.isActive [] (IsActive >> UpdateField >> dispatch) + Fields.text "Login" model.scratchUser.name [] (Name >> UpdateField >> dispatch) + Fields.password "Password" model.scratchUser.password [] (Password >> UpdateField >> dispatch) + Fields.text "Full Name" model.scratchUser.fullName [] (FullName >> UpdateField >> dispatch) + Fields.text "Company" model.scratchUser.company [] (Company >> UpdateField >> dispatch) + Fields.checkbox "Can Login?" "Unchecking this stops the user from logging in" model.scratchUser.isActive [] (IsActive >> UpdateField >> dispatch) + Fields.checkbox "Can Create?" "Checking this allows the user to create other users and accounts" model.scratchUser.canCreate [Disabled (not can_create)] (CanCreate >> UpdateField >> dispatch) + + p [ Style [FontWeight "Bold"] ] [ str ("Trading Account")] + div [ Style [Padding " .5em 1em"]] checkboxes + //Fields.mapSelect "Trading Account" accMap (Some "Add Accounts") None ( fun x-> (x,true) |> TradingPerm |> UpdateField |> dispatch ) ]) - (fun _ -> dispatch SaveUser) + (fun _ -> + match hasOnePermission with + | false -> dispatch (ErrorOccured "New Users must have at least one trading account") + | true -> dispatch SaveUser) (fun _ -> SwitchUser (State.getCurrentUser model) |> dispatch) div [] [ p [ Style [FontWeight "Bold"] ] [ str ("ID: " + model.scratchUser.id.ToString())] br [] - Fields.text "Name" model.scratchUser.name [ ] (Name >> UpdateField >> dispatch) - Fields.password "Password" model.scratchUser.password [ ] (Password >> UpdateField >> dispatch) - Fields.checkbox "Active" "Unchecking this stops the user from entering orders" model.scratchUser.isActive [] (IsActive >> UpdateField >> dispatch) - (if State.isNewUser model.scratchUser then modal else span[][]) + Fields.text "Login" model.scratchUser.name [Disabled readonly] (Name >> UpdateField >> dispatch) + Fields.password "Password" model.scratchUser.password [Disabled readonly] (Password >> UpdateField >> dispatch) + Fields.text "Full Name" model.scratchUser.fullName [Disabled readonly] (FullName >> UpdateField >> dispatch) + Fields.text "Company" model.scratchUser.company [Disabled readonly] (Company >> UpdateField >> dispatch) + Fields.checkbox "Can Login?" "Unchecking this stops the user from logging into Spark" model.scratchUser.isActive [Disabled can_login_disabled] (IsActive >> UpdateField >> dispatch) + Fields.checkbox "Can Create?" "Checking this allows the user to create other users and accounts" model.scratchUser.canCreate [Disabled (readonly || not can_create)] (CanCreate >> UpdateField >> dispatch) + (if (State.isNewUser model.scratchUser) then modal else span[][]) ] let accountNameLookup (accountsList:BTSAccount list) (id:string) = @@ -62,8 +127,7 @@ let accountNameLookup (accountsList:BTSAccount list) (id:string) = | Some acnt -> acnt.name | None -> "Account Not Found" - -let accountsTabView (model:Model) (dispatch:Msg->Unit) = +let accountsTabView (model:Model) (dispatch:Msg->Unit) (readonly:bool) = let accountPermissions = model.scratchUser.userData.accountPermissions.accountPermissions let keys = @@ -76,7 +140,8 @@ let accountsTabView (model:Model) (dispatch:Msg->Unit) = |> List.filter (fun a -> a.isPresent) |> List.map (fun a -> a.id.ToString(), a.name) |> Map.ofList - + + let realAccList = model.accountsList |> List.filter (fun a -> a.isPresent) let headerRow:TableControl.row = { @@ -84,40 +149,40 @@ let accountsTabView (model:Model) (dispatch:Msg->Unit) = [ TableControl.Cell(str "Account") TableControl.Cell(str "Trading Permission") - TableControl.Cell(str "Admin Permission") + TableControl.Cell(str "Risk Admin Permission") + TableControl.Cell(str "MD Admin Permission") ] className = "" header = None } + let rows:TableControl.row list = - [for acc in accMap do yield { + [for acc in realAccList do + let string_id = acc.id.ToString() + let perm = JSMap.tryFind string_id accountPermissions + let is_bts = model.scratchUser.name = Access.superuser + let hasTradeAdmin = (if perm.IsNone then false else perm.Value.tradingPermission.hasPermissions) + let hasRiskAdmin = is_bts || (if perm.IsNone then false else perm.Value.adminPermission.hasPermissions) + let hasMdAdmin = is_bts || (if perm.IsNone then false else perm.Value.adminPermission.hasMdPermissions) + let update permission value _ = permission (string_id, not value) |> UpdateField |> dispatch + yield { cells = [ - TableControl.Cell(str acc.Value) - { content = (Fields.checkbox "" "" ( - keymap.Contains <| acc.Value) - [] - (fun _ -> ( - let message:Msg = acc.Key |> (RemoveAccount >> UpdateField) - match (keymap.Contains <| acc.Value) with - | true -> (OpenConfirmModal ((sprintf "Are you sure you want to remove trading permission for %s?" acc.Value), message)) - | false -> (acc.Key |> (AddAccount >> UpdateField)) - |> dispatch - ) - ) - ); - className = ""; - isHeader = false; - colSpan = 0 - } - { content = (Fields.checkbox "" "" ( - model.scratchUser.name.Contains "bts" || model.scratchUser.name.Contains "admin") - [Disabled true] - ignore - ); - className = ""; - isHeader = false; - colSpan = 0 - } + TableControl.Cell(str acc.name) + { content = Fields.checkbox "" "" hasTradeAdmin [Disabled readonly] (update TradingPerm hasTradeAdmin) + className = ""; + isHeader = false; + colSpan = 0 + } + { content = Fields.checkbox "" "" hasRiskAdmin [Disabled (is_bts || readonly)] (update RiskAdmin hasRiskAdmin) + className = ""; + isHeader = false; + colSpan = 0 + } + { content = Fields.checkbox "" "" hasMdAdmin [Disabled (is_bts || readonly)] (update MDAdmin hasMdAdmin) + className = ""; + isHeader = false; + colSpan = 0 + } ] className="" header = None @@ -129,7 +194,7 @@ let accountsTabView (model:Model) (dispatch:Msg->Unit) = TableControl.createSelectorTable (Some headerRow) rows ] -let MarketDataTabView (model:Model) (dispatch:Msg->Unit) = +let MarketDataTabView (model:Model) (dispatch:Msg->Unit) (readonly:bool) = let cmeData = model.scratchUser.userData.exchangeUserData.cmeData let findCheckedValue (value:bts.api.CMEMics) = @@ -137,59 +202,63 @@ let MarketDataTabView (model:Model) (dispatch:Msg->Unit) = match checkedValue with | Some t -> true | None -> false - - + let micList = [ - for micValue in bts.api.CMEMics.values do - yield ( - if (micValue = bts.api.CMEMics.UNSET) |> not then - Fields.checkbox - (sprintf "%O" micValue) - "" - (findCheckedValue micValue) - [] - (fun chk -> (({enabled = chk; mic = micValue }:CMEMicData) |> (CMEMic >> UpdateField >> dispatch))) - else - str "" - ) - ] - + for micPair in CMEMicMap do + yield ( + Fields.checkbox + (sprintf "%O" micPair.Key) + "" + (findCheckedValue micPair.Value) + [Disabled readonly] + (fun chk -> (({enabled = chk; mic = micPair.Value}:CMEMicData) |> (CMEMic >> UpdateField >> dispatch))) + ) + ] + + let send = UpdateField>>dispatch div [] [ h2 [Class "is-size-3"] [ str "CME" ] h3 [Class "is-size-4"] [ str "Entitlements" ] div [Style [Padding " .5em 1em"]] micList - ] -let orderRoutingTabView (model:Model) (dispatch:Msg->Unit) = + h3 [Class "is-size-4"] [ str "Designations" ] + //Pico recommends we hide this for the ICE + //Fields.enumSelect "Pro / Non-Pro" (toHuman false ProfessionalDesignation.values cmeData.proNonpro) (allToHuman false ProfessionalDesignation.values) [Disabled readonly] (fromHuman ProfessionalDesignation.values>>UserField.CMEProNonPro>>send) + Fields.enumSelect "Display / Non-Display" (toHuman false DisplayDesignation.values cmeData.displayNondisplay) (allToHuman false DisplayDesignation.values) [Disabled readonly] (fromHuman DisplayDesignation.values>>UserField.CMEDisplayNonDisplay>>send) + ] + + +let orderRoutingTabView (model:Model) (dispatch:Msg->Unit) (readonly:bool) = let cmeData = model.scratchUser.userData.exchangeUserData.cmeData - let simData = model.scratchUser.userData.exchangeUserData.simData - - + let simData = model.scratchUser.userData.exchangeUserData.simData div [] - [ - h2 [Class "is-size-3"] [ str "CME" ] - div [] - [ - Fields.text "Operator ID" cmeData.operatorId [ MaxLength 18.0 ] (CMEOperatorID >> UpdateField >> dispatch) - //Fields.text "ATS Operator ID" cmeData.atsOperatorId [] (ATSOperatorID >> UpdateField >> dispatch) - Fields.text "SMP ID" cmeData.smpId [] (SMPID >> UpdateField >> dispatch) - Fields.mapSelect "SMP Instruction" State.SMPInstructionMap None (Some cmeData.smpInstruction) (SMPInstruction >> UpdateField >> dispatch) - Fields.text "Location" cmeData.location [] (CMELocation >> UpdateField >> dispatch) - //Fields.text "Max Order Rate Per Connection" cmeData.maxOrderRatePerConnection [] (MaxOrderRatePerConnection >> UpdateField >> dispatch) - //Fields.map "Misc Tag Mapping" cmeData.miscTags [] (MiscTags >> UpdateField >> dispatch) - ] - br [] - h2 [Class "is-size-3"] [ str "Sim" ] - div [] - [ - Fields.text "Operator ID" simData.operatorId [ MaxLength 18.0 ] (SimOperatorID >> UpdateField >> dispatch) - Fields.text "Location" simData.location [] (SimLocation >> UpdateField >> dispatch) + [ + h2 [Class "is-size-3"] [ str "CME" ] + div [] + [ + Fields.text "Operator ID" cmeData.operatorId [ MaxLength 18.0 ; Disabled readonly ] (CMEOperatorID >> UpdateField >> dispatch) + //Fields.text "ATS Operator ID" cmeData.atsOperatorId [] (ATSOperatorID >> UpdateField >> dispatch) + Fields.text "SMP ID" cmeData.smpId [Disabled readonly] (SMPID >> UpdateField >> dispatch) + Fields.mapSelectEx "SMP Instruction" State.SMPInstructionMap None (Some cmeData.smpInstruction) (SMPInstruction >> UpdateField >> dispatch) (Some readonly) + Fields.text "Location" cmeData.location [Disabled readonly] (CMELocation >> UpdateField >> dispatch) + //Fields.text "Max Order Rate Per Connection" cmeData.maxOrderRatePerConnection [] (MaxOrderRatePerConnection >> UpdateField >> dispatch) + //Fields.map "Misc Tag Mapping" cmeData.miscTags [] (MiscTags >> UpdateField >> dispatch) + ] + br [] + h2 [Class "is-size-3"] [ str "Sim" ] + div [] + [ + Fields.text "Operator ID" simData.operatorId [ MaxLength 18.0 ; Disabled readonly] (SimOperatorID >> UpdateField >> dispatch) + Fields.text "Location" simData.location [Disabled readonly] (SimLocation >> UpdateField >> dispatch) - ] - ] + ] + ] + + + let userControls (model:Model) (dispatch:Msg->Unit) = let currentUser = State.getCurrentUser model @@ -202,16 +271,20 @@ let userControls (model:Model) (dispatch:Msg->Unit) = ] -let tabContent (model:Model) (dispatch:Msg->Unit) = +let tabContent (model:Model) (dispatch:Msg->Unit) display_md display_risk = + let mod1 = { + model with currentTab = (if (not display_risk && display_md) then Tab.MarketData else model.currentTab) + } + div [Key (string model.scratchUser.id); ClassName "is-tab-content"] [ - (match model.currentTab, (State.userIsSelected model.scratchUser State.defaultScratchUser) with - | _, false -> p [Style [ Color "Red" ]] [ str "Select a User" ] - | Tab.General, true -> generalTabView model dispatch - | Tab.Accounts, true -> accountsTabView model dispatch - | Tab.MarketData, true -> MarketDataTabView model dispatch - | Tab.OrderRouting, true -> orderRoutingTabView model dispatch) + (match mod1.currentTab, ( State.userIsSelected model.scratchUser State.defaultScratchUser) with + | _, false -> p [Style [ Color "Red" ]] [ str "You are not authorized to view this data" ] + | Tab.General, true -> generalTabView model dispatch (not display_risk) + | Tab.Accounts, true -> accountsTabView model dispatch (not display_risk) + | Tab.MarketData, true -> MarketDataTabView model dispatch (not display_md) + | Tab.OrderRouting, true -> orderRoutingTabView model dispatch (not display_risk) ) - userControls model dispatch + (if (State.userIsSelected model.scratchUser State.defaultScratchUser) then userControls model dispatch else span[][]) ] let usersMenu (usersList:BTSUser list) (currentUser:BTSUser) (dispatch:Msg->Unit) = @@ -283,40 +356,43 @@ let menuItem (user:BTSUser) (selectedUser:BTSUser) model dispatch = ) ] [ span [] [ str user.name ] - span [ Class "is-pulled-right menu-icon" ] - [ - div [ Class (sprintf "dropdown %s" (isOptionsMenuOpen user.name model.OptionsMenuOpen)) ] - [ div [ Class "dropdown-trigger" ] - [ button [ Class "button" - AriaHasPopup true - OnClick (fun _ -> user.name |> OpenOptionsMenu |> dispatch) - HTMLAttr.Custom ("aria-controls", (sprintf "dropdown-menu-%s" user.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" user.name) - Role "menu" + (if model.can_create then + span [ Class "is-pulled-right menu-icon" ] + [ + div [ Class (sprintf "dropdown %s" (isOptionsMenuOpen user.name model.OptionsMenuOpen)) ] + [ div [ Class "dropdown-trigger" ] + [ button [ Class "button" + AriaHasPopup true + OnClick (fun _ -> user.name |> OpenOptionsMenu |> dispatch) + HTMLAttr.Custom ("aria-controls", (sprintf "dropdown-menu-%s" user.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" user.name) + Role "menu" - ] - [ div [ Class "dropdown-content" ] - [ //hr [ Class "dropdown-divider" ] - a [ Class "dropdown-item" - OnClick (fun _ -> dispatch <| Delete user) - ] - [ str "Remove" ] - a [ Class "dropdown-item" - OnClick (fun _ -> dispatch <| CloneUser) - ] - [ str "Clone" ] - ] - ] - ] - ] + ] + [ div [ Class "dropdown-content" ] + [ //hr [ Class "dropdown-divider" ] + a [ Class "dropdown-item" + OnClick (fun _ -> dispatch <| Delete user) + ] + [ str "Remove" ] + a [ Class "dropdown-item" + OnClick (fun _ -> dispatch <| CloneUser) + ] + [ str "Clone" ] + ] + ] + ] + ] + else + span[][]) ] let NavRoot (usersList:BTSUser list) (currentUser:BTSUser) model (dispatch:Msg->Unit) = @@ -325,10 +401,18 @@ let NavRoot (usersList:BTSUser list) (currentUser:BTSUser) model (dispatch:Msg-> div [ Class "column is-narrow is-sidebar-menu" ] [ aside [ Class "menu" ] - [ p [ Class "menu-label" ] [ + [ p [ Class "menu-label" ] [ span [Class "is-size-4"] [str "Users"] - span [ Class "is-pulled-right circle-icon" ] - [ Button.fabutton "Add User" "plus-circle" "" Button.Enabled (fun _ -> dispatch AddUser) ] + span [ Class "is-pulled-right circle-icon" ] + (if model.can_create then + [ Button.fabutton + "Add User" + "plus-circle" + "" + Button.Enabled + (fun _ -> dispatch AddUser) + ] + else []) ] ul [ Class "menu-list" ] @@ -339,21 +423,6 @@ let NavRoot (usersList:BTSUser list) (currentUser:BTSUser) model (dispatch:Msg-> ] ] -let selectionPageContent (model:Model) (dispatch:Msg->Unit) = - let modal = Modal.showCreate - "Create User" - (div [][ - Fields.text "Name" model.scratchUser.name [ ] (Name >> UpdateField >> dispatch) - Fields.password "Password" model.scratchUser.password [ ] (Password >> UpdateField >> dispatch) - Fields.checkbox "Active" "Unchecking this stops the user from entering orders" model.scratchUser.isActive [] (IsActive >> UpdateField >> dispatch) - ]) - (fun _ -> dispatch SaveUser) - //(fun _ -> SwitchUser (State.getCurrentUser model) |> dispatch) - (fun _ -> CancelAddUser |> dispatch) - div [] [ - userSelectionGrid model.userList model.scratchUser dispatch - (if State.isNewUser model.scratchUser then modal else span[][]) - ] let root (model:Model) (dispatch:Msg->Unit) = (* @@ -366,6 +435,11 @@ let root (model:Model) (dispatch:Msg->Unit) = | _, _ -> () ) *) + let adminDisplay = model.scratchUser.userData.exchangeUserData.cmeData.adminDisplayFlag + let is_bts = model.this_username = Access.superuser + let display_md = if is_bts then true else (adminDisplay = bts.api.admin.CMEUserData.AdminDisplay.All || adminDisplay = bts.api.admin.CMEUserData.AdminDisplay.MD) + let display_risk = if is_bts then true else (adminDisplay = bts.api.admin.CMEUserData.AdminDisplay.All || adminDisplay = bts.api.admin.CMEUserData.AdminDisplay.Routing) + let modal = match (fst model.ConfirmModal) with | "" -> span [] [] | _ -> Modal.showConfirm (fst model.ConfirmModal) (fun () -> (snd model.ConfirmModal) |> dispatch) (fun _ -> OpenConfirmModal ("", Msg.SwitchTab model.currentTab ) |> dispatch) @@ -386,21 +460,33 @@ let root (model:Model) (dispatch:Msg->Unit) = div [ ClassName "tabs is-boxed" ] [ ul [ ] [ - li [ ClassName (isActiveTab Tab.General model.currentTab) ] - [ a [ OnClick (fun _ -> dispatch (SwitchTab Tab.General)) ] - [ str "General" ] ] - li [ ClassName (isActiveTab Tab.Accounts model.currentTab) ] - [ a [ OnClick (fun _ -> dispatch (SwitchTab Tab.Accounts)) ] - [ str "Account Permissions" ] ] - li [ ClassName (isActiveTab Tab.MarketData model.currentTab) ] - [ a [ OnClick (fun _ -> dispatch (SwitchTab Tab.MarketData)) ] - [ str "Market Data" ] ] - li [ ClassName (isActiveTab Tab.OrderRouting model.currentTab) ] - [ a [ OnClick (fun _ -> dispatch (SwitchTab Tab.OrderRouting)) ] - [ str "Order Routing" ] ] + (if display_risk then + li [ ClassName (isActiveTab Tab.General model.currentTab) ] + [ a [ OnClick (fun _ -> dispatch (SwitchTab Tab.General)) ] + [ str "General" ] ] + else + span [] []) + (if display_risk then + li [ ClassName (isActiveTab Tab.Accounts model.currentTab) ] + [ a [ OnClick (fun _ -> dispatch (SwitchTab Tab.Accounts)) ] + [ str "Account Permissions" ] ] + else + span [] []) + (if display_md then + li [ ClassName (isActiveTab Tab.MarketData model.currentTab) ] + [ a [ OnClick (fun _ -> dispatch (SwitchTab Tab.MarketData)) ] + [ str "Market Data" ] ] + else + span [] [] ) + (if display_risk then + li [ ClassName (isActiveTab Tab.OrderRouting model.currentTab) ] + [ a [ OnClick (fun _ -> dispatch (SwitchTab Tab.OrderRouting)) ] + [ str "Order Routing" ] ] + else + span [] [] ) ] ] - tabContent model dispatch + tabContent model dispatch display_md display_risk modal ] ] diff --git a/tools/jetfix_tools/gen_cert_config.py b/tools/jetfix_tools/gen_cert_config.py index ce7c788a7..c0e4b5ec3 100755 --- a/tools/jetfix_tools/gen_cert_config.py +++ b/tools/jetfix_tools/gen_cert_config.py @@ -2,13 +2,16 @@ logins = { - "mbx":61920, "mc1":61921, "mc5":61922, "mc7":61923, "mc8":61924, } +cgw_logins = { + "v06":("69.50.112.143","69.50.112.140",28296) +} + gws = { "50":"69.50.112.202", "52":"69.50.112.181", @@ -78,6 +81,40 @@ for login,port in logins.iteritems(): print " }" print "}" + +print "" + +print """ + +#You probably will need to copy this entry out into your own +#JetFIX if you are mixing MSGW with CGW in 1 config +""" + +# CGW iLinks +for login,endpoint_info in cgw_logins.iteritems(): + print "JetFIX {" + print " rule: \"CannedCertSession.name='%s'\"" % (login) + print " value {" + print " connection: @JetFIXSimConnection.sim" + print " connection {" + print " name: \"cme_%s_g\"" % login + print " platform: GLBX" + print " socket_connect_host_ip: \"%s\"" % endpoint_info[0] + print "# Backup IP" + print "# socket_connect_host_ip: \"%s\"" % endpoint_info[1] + print " socket_connect_port: %s" % endpoint_info[2] + print " sender_compid: \"%s004N\"" % login.upper() + print " target_compid: \"CME\"" + print " target_subid: \"G\"" + print " start_time: \"00:30:00\"" + print " end_time: \"23:30:00\"" + print " start_day: \"sunday\"" + print " end_day: \"friday\"" + print " sender_subid: \"BTS\"" + print " auto_fix_seq_num: true" + print " }" + print " }" + print "}" print """ diff --git a/tools/runexcel.cmd b/tools/runexcel.cmd new file mode 100644 index 000000000..8d1c9ea90 --- /dev/null +++ b/tools/runexcel.cmd @@ -0,0 +1,4 @@ +@echo off +pushd %~dp0\..\build\debug\bin\net471\ +start spark_excel-addin64.xll +popd diff --git a/tools/watch_tests.sh b/tools/watch_tests.sh index 6a5b9a871..5bf7c9f02 100755 --- a/tools/watch_tests.sh +++ b/tools/watch_tests.sh @@ -1,14 +1,14 @@ #!/bin/bash DIR=$(dirname ${BASH_SOURCE[0]}) -if [ "$1" = "-b" ] +cd $DIR/../build/ninja_debug/server/ +if [ "$1" = "-b" ] then - cd $DIR/../build/ninja_debug/ - ninja - cd server + echo "Waiting..." + sleep 1 + pkill -f "sparkd test $2" echo "Starting tests..." - ./sparkd test $2 + ./sparkd test --force-colour -a $2 else - cd $DIR/../src - find $DIR/../src/ -name \*.h -o -name \*.cpp | entr /home/bts/spark/tools/watch_tests.sh -b $1 -fi - + echo ./sparkd | entr /home/bts/spark/tools/watch_tests.sh -b $1 + # find -name sparkd -o -name libspark.so | entr /home/bts/spark/tools/watch_tests.sh -b $1 +fi \ No newline at end of file