diff --git a/src/lib/orderman/actors/FillStore.cpp b/src/lib/orderman/actors/FillStore.cpp index 81995284d..c5a492fa7 100644 --- a/src/lib/orderman/actors/FillStore.cpp +++ b/src/lib/orderman/actors/FillStore.cpp @@ -9,6 +9,7 @@ #include "lib/orderman/events/StoredFillEvent.h" #include "lib/persistence/SqliteStore.h" #include "lib/utils/PBUtils.h" +#include "lib/orderman/actors/SODPosition.h" #include #include @@ -50,9 +51,11 @@ void FillStore::init() { LOG(persist, Info, "Loading load all fills"); auto all = me->store->retrieve_all()[fills_ns]; LOG(persist, Info, "Finished loading all {} fills", all.size()); + SODPosition sod_helper; for (auto const &kvp : all) if (utils::pb::from_string(kvp.second, &fill)) { - + if (sod_helper.is_sod(fill.timestamp())) + fill.set_fill_kind(Fill::FILL_KIND_SOD); auto sec = me->oracle.get_security(SecurityKey(fill.security_key())); if (sec) { if (config::get().enabled() && diff --git a/src/lib/orderman/actors/SODPosition.cpp b/src/lib/orderman/actors/SODPosition.cpp index 4a54a7b27..f962b119e 100644 --- a/src/lib/orderman/actors/SODPosition.cpp +++ b/src/lib/orderman/actors/SODPosition.cpp @@ -24,20 +24,24 @@ _sod_time(sod_time){ LOG(persist, Info, "SODPosition::cons sod_time:{}", sod_time.tv_sec); } -// returns the timeval for today's hh,mm,ss +// returns the timeval for today's hh,mm,ss (in local machine terms) // (timeval is the microseconds from epoch) timeval SODPosition::to_timeval(uint16_t hh, uint16_t mm, uint16_t ss) { + // function does the conversion the following way: + // 1. gets the now secs from epoch using time + // 2. converts it into local time (so we have now local time) + // 3. overrides the hh, mm, ss passed + // 4. converts it back into secs from epoch using mktime bts_assert(hh < 24); bts_assert(mm < 60); bts_assert(ss < 60); time_t secs; - time(&secs); // seconds since epoch (utc) - struct tm *ptm = gmtime(&secs); - ptm->tm_hour = hh; - ptm->tm_min = mm; - ptm->tm_sec = ss; - ptm->tm_isdst = -1; - secs = mktime(ptm); + time(&secs); // seconds since epoch (utc) (independent of machine timezone) + struct tm *ptm_local = localtime(&secs); // in local timezone + ptm_local->tm_hour = hh; + ptm_local->tm_min = mm; + ptm_local->tm_sec = ss; + secs = mktime(ptm_local); // converts local time to UTC epoch time timeval rv; rv.tv_sec = secs; rv.tv_usec = 0; @@ -112,7 +116,7 @@ timeval SODPosition::get_order_cutoff_time( const auto &orders_cleanup = config::get(); return subtract_days(rv, orders_cleanup.extra_days()); } - +// returns now in UTC timeval SODPosition::now(){ timeval tv; gettimeofday(&tv, NULL); diff --git a/src/web/ui/src/Accounts/View.fs b/src/web/ui/src/Accounts/View.fs index 8f656277d..b584c5271 100644 --- a/src/web/ui/src/Accounts/View.fs +++ b/src/web/ui/src/Accounts/View.fs @@ -624,7 +624,7 @@ let productLimits model dispatch = Fields.radioButton "Use Absolute Contracts" "" (not model.scratch.riskLimitEnforcement.productLimitInNetTerms) [] (not >> EnforceProductLimitInNetTerms >> dispatch) div [] [ Fields.checkbox "Ignore Spread Position Limits" "" model.scratch.riskLimitEnforcement.ignoreSpreadPositionLimits [] (IgnoreSpreadPositionLimits >> dispatch) - ] + ] ] TableControl.createDataTable (Some headerRow) rws (Button.button "Add" "" "plus-circle" Button.Enabled addRow) br [] @@ -832,7 +832,7 @@ let DayPositionView model dispatch = cells = [ TableControl.controlCell (str "") - TableControl.Cell (str "ID") + // TableControl.Cell (str "ID") TableControl.Cell (str "Exchange") TableControl.Cell (str "Symbol") TableControl.Cell (str "Security") @@ -900,9 +900,11 @@ let DayPositionView model dispatch = cells = [ TableControl.Cell (Button.deleteButton Button.IsDisabled.Enabled (fun _ -> ((ulimit.id |> int), false)|> RemoveManualFill |> dispatch)) - TableControl.Cell (span [Style [Color "green"]][str (sprintf "%i" ulimit.id)]) - TableControl.Cell (Fields.simpleSelect "" venueList (ulimit.venue) (fun v -> (ulimit.id, v, "venue", false) |> UpdateManualFill |> dispatch)) - TableControl.Cell (Fields.simpleSelect "" (getSymbolList model ulimit.venue) (ulimit.symbol) (fun v -> (ulimit.id, v, "symbol", false) |> UpdateManualFill |> dispatch)) + // TableControl.Cell (span [Style [Color "green"]][str (sprintf "%i" ulimit.id)]) + TableControl.Cell (str (venueToString securityMap.[limit.securityKey].venue)) + TableControl.Cell (str securityMap.[limit.securityKey].symbol) + // TableControl.Cell (Fields.simpleSelect "" venueList (ulimit.venue) (fun v -> (ulimit.id, v, "venue", false) |> UpdateManualFill |> dispatch)) + // TableControl.Cell (Fields.simpleSelect "" (getSymbolList model ulimit.venue) (ulimit.symbol) (fun v -> (ulimit.id, v, "symbol", false) |> UpdateManualFill |> dispatch)) TableControl.Cell (Fields.tupleMapSelect "" (getPositionSecMap @@ -940,7 +942,7 @@ let DayPositionView model dispatch = cells = [ TableControl.Cell (Button.deleteButton Button.IsDisabled.Enabled (fun _ -> ((limit.recordId |> int), false) |> RemoveManualFill |> dispatch)) - TableControl.Cell (str (sprintf "%i" limit.recordId)) + // TableControl.Cell (str (sprintf "%i" limit.recordId)) TableControl.Cell (str (venueToString securityMap.[limit.securityKey].venue)) TableControl.Cell (str securityMap.[limit.securityKey].symbol) TableControl.Cell (str securityMap.[limit.securityKey].securityName) @@ -960,7 +962,7 @@ let DayPositionView model dispatch = cells = [ TableControl.Cell (Button.deleteButton Button.IsDisabled.Enabled (fun _ -> ((limit.newId |> int), true) |> RemoveManualFill |> dispatch)) - TableControl.Cell (span [Style [Color "green"]][str "NEW"]) + // TableControl.Cell (span [Style [Color "green"]][str "NEW"]) TableControl.Cell (Fields.simpleSelect "" venueList (limit.venue) (fun v -> (limit.newId, v, "venue", true) |> UpdateManualFill |> dispatch)) TableControl.Cell (Fields.simpleSelect "" (getSymbolList model limit.venue) (limit.symbol) (fun v -> (limit.newId, v, "symbol", true) |> UpdateManualFill |> dispatch)) TableControl.Cell (Fields.tupleMapSelect @@ -999,13 +1001,13 @@ let DayPositionView model dispatch = onClick = None }] - let dividerRow = match newRows.Length with 0 -> [] | _ -> [({ cells = [{ content = str ""; className = "border-row"; isHeader = false; colSpan = 9 }]; className = ""; header = None; onClick = None }:TableControl.row)] + let dividerRow = match newRows.Length with 0 -> [] | _ -> [({ cells = [{ content = str ""; className = "border-row"; isHeader = false; colSpan = 8 }]; className = ""; header = None; onClick = None }:TableControl.row)] let rws:TableControl.row list = fillRows @ dividerRow @ newRows div [] [ div [ ClassName "columns" ][ - h1 [ ClassName "is-size-3 column is-narrow" ][str "Day" ] + h1 [ ClassName "is-size-3 column is-narrow" ][str "Day Fills" ] div [ ClassName "column is-size-7 has-text-grey-mid is-help-text"; ] [str "Manually add fills for the Day position"] ] diff --git a/testing/manual/admin/product_position_limits.txt b/testing/manual/admin/product_position_limits.txt index c47774106..b43baabc1 100644 --- a/testing/manual/admin/product_position_limits.txt +++ b/testing/manual/admin/product_position_limits.txt @@ -1,6 +1,4 @@ -This test verifies that product position limits are enforced correctly. (Position limits are -enforced at both the security and account level) - +This test verifies that product position limits are enforced correctly. Use SIM for all steps of the test 0. Clear up your orders, fills and admin db so we don't have any lingering positions @@ -17,11 +15,16 @@ and enter a big clip, say 500000, so that clip limits don't interfere with this 5. Enter a rule for SIM, Future, SI, 60, 120. -6. Send 3 10 lot buys for both the futures. Make sure they go through. +6. Send 3 20 lot buys for both the futures. Make sure they go through. 7. Send a 1 lot on SIU8. The limit of 60 should not allow it. Make sure the rejection message is clear. +8. Cross 2 of the 20 lots enterred in 6 so that they fill. + +9. Send a 1 lot on SIU8. The limit of 60 should not allow it. Make sure the rejection +message is clear. + 8. Change the max to 70, and try a 10 lot again. This order should be allowed. Try another 10 lot and it should be stopped. diff --git a/testing/manual/admin/spread_position_limits.txt b/testing/manual/admin/spread_position_limits.txt index 994f71c19..ee5a65bc8 100644 --- a/testing/manual/admin/spread_position_limits.txt +++ b/testing/manual/admin/spread_position_limits.txt @@ -4,17 +4,19 @@ ii. spread legs fills (and working orders) are applied toward enforcing the position limits for the legs iii. leg limits are checked when entering spread orders -i: - 1. Pick a 2 legged spread (lets say SIU8-SIZ8). Set the clip limits high for both spreads and futures so that they don't interfere. 2. For the Position Limits, set Max Long and Max Short of 100 and 110 for the SI futures and 20 and 30 for the SI spreads respectively. -3. Verify that the limits set in 2 work for futures(remember working orders count toward limit enforcement so you dont need -fills). Cancel all the orders. +3. Make sure "Ignore Spread Position Limits" is not checked -4. Verify that the limits set in 2. work for spreads. Cancel all the orders. +4. Verify that the limits set in 2 work for futures. Accrue future "positions" through a +combination of working orders and fills. Cancel all the orders. -5. Make these position limits 1,000,000 to make them irrelevant +5. Verify that the limits set in 2. work for spreads. Cancel all the orders. + +6. Check "gnore Spread Position Limits" and make sure this disables spread limits. + +7. Make these position limits 1,000,000 to make them irrelevant diff --git a/testing/manual/positions_and_fills/SOD.txt b/testing/manual/positions_and_fills/SOD.txt index 90526c240..dab64d72d 100644 --- a/testing/manual/positions_and_fills/SOD.txt +++ b/testing/manual/positions_and_fills/SOD.txt @@ -27,7 +27,7 @@ SODTime{ } } -3. Now restart the server. Verify that all rows in the fills have a Fill Kind 'Sod' and the time matches the SODTime (converted to your local time zone) +3. Now restart the server. Verify that all rows in the fills have a Fill Kind 'Sod' 4. Verify that the ladder is displaying the correct position (it should be the same as before the server start)