|
| 1 | +import assert from "node:assert/strict"; |
| 2 | + |
| 3 | +import { __test } from "../web/strategy-switch-console/worker.js"; |
| 4 | + |
| 5 | +const strategyProfiles = __test.normalizeStrategyProfilesPayload( |
| 6 | + [ |
| 7 | + { |
| 8 | + profile: "tqqq_growth_income", |
| 9 | + label: "TQQQ Growth Income", |
| 10 | + domain: "us_equity", |
| 11 | + runtime_enabled: true, |
| 12 | + }, |
| 13 | + { |
| 14 | + profile: "hk_low_vol_dividend_quality_snapshot", |
| 15 | + label: "HK Low-Vol Dividend Quality Snapshot", |
| 16 | + domain: "hk_equity", |
| 17 | + runtime_enabled: true, |
| 18 | + }, |
| 19 | + ], |
| 20 | + "test_strategy_profiles", |
| 21 | +); |
| 22 | + |
| 23 | +const accountOptions = __test.normalizeAccountOptionsPayload( |
| 24 | + { |
| 25 | + longbridge: [ |
| 26 | + { |
| 27 | + key: "hk", |
| 28 | + label: "hk", |
| 29 | + target_name: "hk", |
| 30 | + account_selector: "HK", |
| 31 | + default_strategy_profile: "hk_low_vol_dividend_quality_snapshot", |
| 32 | + }, |
| 33 | + { |
| 34 | + key: "sg", |
| 35 | + label: "sg", |
| 36 | + target_name: "sg", |
| 37 | + account_selector: "SG", |
| 38 | + default_strategy_profile: "tqqq_growth_income", |
| 39 | + }, |
| 40 | + ], |
| 41 | + ibkr: [ |
| 42 | + { |
| 43 | + key: "u15998061", |
| 44 | + label: "u15998061", |
| 45 | + target_name: "u15998061", |
| 46 | + account_selector: "U15998061", |
| 47 | + deployment_selector: "live-u1599-tqqq", |
| 48 | + account_scope: "live-u1599-tqqq", |
| 49 | + service_name: "interactive-brokers-live-u1599-tqqq-service", |
| 50 | + }, |
| 51 | + ], |
| 52 | + schwab: [ |
| 53 | + { |
| 54 | + key: "default", |
| 55 | + label: "default", |
| 56 | + target_name: "default", |
| 57 | + supported_domains: ["us_equity"], |
| 58 | + }, |
| 59 | + ], |
| 60 | + firstrade: [ |
| 61 | + { |
| 62 | + key: "default", |
| 63 | + label: "default", |
| 64 | + target_name: "default", |
| 65 | + supported_domains: ["us_equity"], |
| 66 | + }, |
| 67 | + ], |
| 68 | + }, |
| 69 | + "test_account_options", |
| 70 | +); |
| 71 | + |
| 72 | +assert.deepEqual(accountOptions.longbridge[0].supported_domains, ["hk_equity"]); |
| 73 | +assert.deepEqual(accountOptions.longbridge[1].supported_domains, ["us_equity"]); |
| 74 | +assert.deepEqual(accountOptions.ibkr[0].supported_domains, ["us_equity"]); |
| 75 | + |
| 76 | +const longbridgeHk = __test.assertConfiguredAccount( |
| 77 | + { |
| 78 | + platform: "longbridge", |
| 79 | + target_name: "hk", |
| 80 | + account_selector: "HK", |
| 81 | + strategy_profile: "hk_low_vol_dividend_quality_snapshot", |
| 82 | + }, |
| 83 | + accountOptions, |
| 84 | +); |
| 85 | +__test.assertStrategyAllowedForAccount( |
| 86 | + { |
| 87 | + platform: "longbridge", |
| 88 | + strategy_profile: "hk_low_vol_dividend_quality_snapshot", |
| 89 | + }, |
| 90 | + longbridgeHk, |
| 91 | + strategyProfiles, |
| 92 | +); |
| 93 | + |
| 94 | +const ibkrAccount = __test.assertConfiguredAccount( |
| 95 | + { |
| 96 | + platform: "ibkr", |
| 97 | + target_name: "u15998061", |
| 98 | + account_selector: "U15998061", |
| 99 | + deployment_selector: "live-u1599-tqqq", |
| 100 | + account_scope: "live-u1599-tqqq", |
| 101 | + service_name: "interactive-brokers-live-u1599-tqqq-service", |
| 102 | + strategy_profile: "tqqq_growth_income", |
| 103 | + }, |
| 104 | + accountOptions, |
| 105 | +); |
| 106 | +__test.assertStrategyAllowedForAccount( |
| 107 | + { |
| 108 | + platform: "ibkr", |
| 109 | + strategy_profile: "tqqq_growth_income", |
| 110 | + }, |
| 111 | + ibkrAccount, |
| 112 | + strategyProfiles, |
| 113 | +); |
| 114 | +assert.throws( |
| 115 | + () => __test.assertStrategyAllowedForAccount( |
| 116 | + { |
| 117 | + platform: "ibkr", |
| 118 | + strategy_profile: "hk_low_vol_dividend_quality_snapshot", |
| 119 | + }, |
| 120 | + ibkrAccount, |
| 121 | + strategyProfiles, |
| 122 | + ), |
| 123 | + /not supported/, |
| 124 | +); |
0 commit comments