fx-shared-models 0.2.6__tar.gz → 0.2.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {fx_shared_models-0.2.6/fx_shared_models.egg-info → fx_shared_models-0.2.7}/PKG-INFO +1 -1
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7/fx_shared_models.egg-info}/PKG-INFO +1 -1
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/setup.py +1 -1
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/__init__.py +1 -1
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/ib_commission/services/commission_calculator_service.py +109 -66
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/LICENSE +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/MANIFEST.in +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/README.md +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/fx_shared_models.egg-info/SOURCES.txt +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/fx_shared_models.egg-info/dependency_links.txt +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/fx_shared_models.egg-info/requires.txt +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/fx_shared_models.egg-info/top_level.txt +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/setup.cfg +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/accounts/__init__.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/accounts/apps.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/accounts/migrations/0001_initial.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/accounts/migrations/0002_remove_account_group_type_account_has_bonus_and_more.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/accounts/migrations/0003_account_is_archived_account_is_trading_enabled.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/accounts/migrations/0004_alter_account_created_at_alter_account_created_by_and_more.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/accounts/migrations/0005_account_currency.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/accounts/migrations/0006_alter_account_options.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/accounts/migrations/__init__.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/accounts/models.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/common/__pycache__/base.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/common/__pycache__/mixins.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/common/__pycache__/utils.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/common/base.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/common/mixins.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/common/utils.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/company_ba/__init__.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/company_ba/apps.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/company_ba/migrations/0001_initial.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/company_ba/migrations/__init__.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/company_ba/models.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/constants.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/customers/__init__.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/customers/__pycache__/__init__.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/customers/__pycache__/apps.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/customers/__pycache__/models.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/customers/apps.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/customers/migrations/0001_initial.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/customers/migrations/0002_alter_customer_email_alter_customer_first_name_and_more.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/customers/migrations/0004_customerauth_two_factor_backup_codes_and_more.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/customers/migrations/0005_customerauth_temp_webauthn_challenge.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/customers/migrations/0006_customerauth_webauthn_challenge.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/customers/migrations/0007_customerauth_blocked_customerauth_blocked_at_and_more.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/customers/migrations/0008_customer_email_hash.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/customers/migrations/__init__.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/customers/migrations/__pycache__/0001_initial.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/customers/migrations/__pycache__/0002_alter_customer_email_alter_customer_first_name_and_more.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/customers/migrations/__pycache__/0004_customerauth_two_factor_backup_codes_and_more.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/customers/migrations/__pycache__/0005_customerauth_temp_webauthn_challenge.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/customers/migrations/__pycache__/0006_customerauth_webauthn_challenge.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/customers/migrations/__pycache__/0007_customerauth_blocked_customerauth_blocked_at_and_more.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/customers/migrations/__pycache__/0008_customer_email_hash.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/customers/migrations/__pycache__/__init__.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/customers/models.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/ib_commission/__init__.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/ib_commission/apps.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/ib_commission/migrations/0001_initial.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/ib_commission/migrations/0002_alter_clientibmapping_id_and_more.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/ib_commission/migrations/0003_commissiondistribution_is_pass_up_and_more.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/ib_commission/migrations/0004_rename_ib_commissi_account_76e731_idx_ib_commissi_account_10d556_idx_and_more.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/ib_commission/migrations/0005_alter_ibagreementmember_start_date.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/ib_commission/migrations/0006_clientibmapping_agreement_and_more.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/ib_commission/migrations/0007_alter_clientibmapping_mt5_login.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/ib_commission/migrations/0008_commissiondistribution_is_processed_and_more.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/ib_commission/migrations/0009_commissiondistribution_processing_notes_and_more.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/ib_commission/migrations/__init__.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/ib_commission/models.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/ib_commission/services/__init__.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/services/group_resolver.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/__pycache__/apps.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/__pycache__/serializers.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/apps.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/migrations/0001_initial.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/migrations/0002_rename_is_enabled_systemsetting_is_active.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/migrations/0003_tradingplatformserver.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/migrations/0004_tradingplatformserver_connection_timeout_and_more.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/migrations/0005_accountsequence_accounttype.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/migrations/0006_alter_accounttype_sequence.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/migrations/0007_remove_accounttype_default_group_type_and_more.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/migrations/0008_paymentgatewayconfig_paymentmethodconfig_and_more.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/migrations/0009_alter_accountsequence_created_at_and_more.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/migrations/0010_alter_paymentgatewayconfig_gateway_and_more.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/migrations/__init__.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/migrations/__pycache__/0001_initial.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/migrations/__pycache__/0002_rename_is_enabled_systemsetting_is_active.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/migrations/__pycache__/0003_tradingplatformserver.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/migrations/__pycache__/0004_tradingplatformserver_connection_timeout_and_more.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/migrations/__pycache__/0005_accountsequence_accounttype.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/migrations/__pycache__/0006_alter_accounttype_sequence.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/migrations/__pycache__/0007_remove_accounttype_default_group_type_and_more.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/migrations/__pycache__/0008_paymentgatewayconfig_paymentmethodconfig_and_more.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/migrations/__pycache__/0009_alter_accountsequence_created_at_and_more.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/migrations/__pycache__/0010_alter_paymentgatewayconfig_gateway_and_more.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/migrations/__pycache__/__init__.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/models/__init__.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/models/__pycache__/__init__.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/models/__pycache__/account_sequence.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/models/__pycache__/account_types.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/models/__pycache__/accounts.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/models/__pycache__/base.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/models/__pycache__/email.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/models/__pycache__/group_configurations.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/models/__pycache__/payment_methods.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/models/__pycache__/trading_platform.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/models/__pycache__/transaction_configs.cpython-313.pyc +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/models/account_sequence.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/models/account_types.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/models/base.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/models/email.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/models/group_configurations.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/models/payment_methods.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/models/trading_platform.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/models/transaction_configs.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/serializers.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/transactions/__init__.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/transactions/apps.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/transactions/constants.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/transactions/enums.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/transactions/migrations/0001_initial.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/transactions/migrations/0002_transaction_mt5_ticket.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/transactions/migrations/0003_alter_transaction_options.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/transactions/migrations/__init__.py +0 -0
- {fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/transactions/models.py +0 -0
|
@@ -71,14 +71,6 @@ class CommissionCalculatorService:
|
|
|
71
71
|
# Get customer from account
|
|
72
72
|
customer = account.customer
|
|
73
73
|
|
|
74
|
-
# Find mapping for this customer
|
|
75
|
-
client_mapping = ClientIBMapping.objects.filter(
|
|
76
|
-
customer=customer
|
|
77
|
-
).first()
|
|
78
|
-
|
|
79
|
-
if not client_mapping:
|
|
80
|
-
return {'distributions': [], 'client_deduction': 0, 'client_server_id': None, 'is_processed': False}
|
|
81
|
-
|
|
82
74
|
# Determine which rules to apply based on entry type
|
|
83
75
|
is_entry = entry in [cls.ENTRY_IN, cls.ENTRY_INOUT] # Entry or InOut
|
|
84
76
|
is_exit = entry in [cls.ENTRY_OUT, cls.ENTRY_OUT_BY] # Exit or OutBy
|
|
@@ -88,16 +80,25 @@ class CommissionCalculatorService:
|
|
|
88
80
|
if is_exit:
|
|
89
81
|
rule_filter = {'commission_type': cls.REBATE_TYPE}
|
|
90
82
|
|
|
91
|
-
# Find applicable rules
|
|
83
|
+
# Find applicable rules - this will also find the client mapping
|
|
92
84
|
applicable_rules = cls._find_applicable_rules(
|
|
93
|
-
|
|
94
|
-
mt5_login,
|
|
95
|
-
symbol,
|
|
96
|
-
order_type,
|
|
85
|
+
ib_id=None, # Will be determined in _find_applicable_rules
|
|
86
|
+
mt5_account_id=mt5_login,
|
|
87
|
+
symbol=symbol,
|
|
88
|
+
order_type=order_type,
|
|
89
|
+
customer=customer,
|
|
90
|
+
account=account,
|
|
97
91
|
**rule_filter
|
|
98
92
|
)
|
|
99
93
|
|
|
100
|
-
if not applicable_rules:
|
|
94
|
+
if not applicable_rules or not applicable_rules.get('rules'):
|
|
95
|
+
return {'distributions': [], 'client_deduction': 0, 'client_server_id': None, 'is_processed': False}
|
|
96
|
+
|
|
97
|
+
# Get the client mapping and rules from the result
|
|
98
|
+
client_mapping = applicable_rules.get('client_mapping')
|
|
99
|
+
rules = applicable_rules.get('rules')
|
|
100
|
+
|
|
101
|
+
if not client_mapping:
|
|
101
102
|
return {'distributions': [], 'client_deduction': 0, 'client_server_id': None, 'is_processed': False}
|
|
102
103
|
|
|
103
104
|
distributions = []
|
|
@@ -112,7 +113,7 @@ class CommissionCalculatorService:
|
|
|
112
113
|
client_account=account,
|
|
113
114
|
mt5_login=mt5_login,
|
|
114
115
|
commission_type=cls.COMMISSION_TYPE if is_entry else cls.REBATE_TYPE,
|
|
115
|
-
rule=
|
|
116
|
+
rule=rules[0], # Use first rule for tracking
|
|
116
117
|
amount=Decimal('0.0'), # Will be updated after calculation
|
|
117
118
|
processed_time=datetime.now(),
|
|
118
119
|
trade_open_time=datetime.now(), # Should be from deal data
|
|
@@ -272,14 +273,18 @@ class CommissionCalculatorService:
|
|
|
272
273
|
if is_exit:
|
|
273
274
|
rule_filter = {'commission_type': cls.REBATE_TYPE}
|
|
274
275
|
|
|
275
|
-
|
|
276
|
+
result = cls._find_applicable_rules(
|
|
276
277
|
ib_id=ib_id,
|
|
277
278
|
mt5_account_id=client_mapping.mt5_login,
|
|
278
279
|
symbol='*',
|
|
279
280
|
order_type='*',
|
|
281
|
+
customer=client_mapping.customer,
|
|
282
|
+
account=client_mapping.account,
|
|
280
283
|
**rule_filter
|
|
281
284
|
)
|
|
282
285
|
|
|
286
|
+
applicable_rules = result.get('rules', [])
|
|
287
|
+
|
|
283
288
|
for rule in applicable_rules:
|
|
284
289
|
# Calculate base amount from rule
|
|
285
290
|
base_amount = cls._calculate_amount_from_rule(
|
|
@@ -410,76 +415,114 @@ class CommissionCalculatorService:
|
|
|
410
415
|
return amount
|
|
411
416
|
|
|
412
417
|
@classmethod
|
|
413
|
-
def _find_applicable_rules(cls, ib_id, mt5_account_id, symbol, order_type, **kwargs):
|
|
418
|
+
def _find_applicable_rules(cls, ib_id, mt5_account_id, symbol, order_type, customer=None, account=None, **kwargs):
|
|
414
419
|
"""
|
|
415
420
|
Find applicable commission rules for a given deal.
|
|
416
421
|
|
|
417
422
|
Args:
|
|
418
|
-
ib_id: The IB ID
|
|
423
|
+
ib_id: The IB ID (can be None, will be determined from client mapping)
|
|
419
424
|
mt5_account_id: The MT5 account ID
|
|
420
425
|
symbol: The trading symbol
|
|
421
426
|
order_type: The order type
|
|
427
|
+
customer: The customer who made the trade
|
|
428
|
+
account: The account used for the trade
|
|
422
429
|
**kwargs: Additional filters for rules (e.g., commission_type='REBATE')
|
|
423
430
|
|
|
424
431
|
Returns:
|
|
425
|
-
|
|
432
|
+
Dictionary containing:
|
|
433
|
+
- rules: A list of applicable rules
|
|
434
|
+
- client_mapping: The client mapping used to find the rules
|
|
426
435
|
"""
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
436
|
+
client_mapping = None
|
|
437
|
+
|
|
438
|
+
# PRIORITY 1: Find client mapping with account and mt5_login
|
|
439
|
+
if mt5_account_id:
|
|
440
|
+
# Try to find account-specific mapping first
|
|
441
|
+
client_mapping = ClientIBMapping.objects.filter(
|
|
442
|
+
mt5_login=mt5_account_id,
|
|
443
|
+
is_active=True
|
|
444
|
+
).first()
|
|
445
|
+
|
|
446
|
+
# PRIORITY 2: If no account-specific mapping, try to find customer mapping
|
|
447
|
+
if not client_mapping and customer:
|
|
448
|
+
client_mapping = ClientIBMapping.objects.filter(
|
|
449
|
+
customer=customer,
|
|
450
|
+
is_active=True
|
|
451
|
+
).first()
|
|
432
452
|
|
|
433
|
-
#
|
|
434
|
-
|
|
453
|
+
# If no client mapping found, return empty result
|
|
454
|
+
if not client_mapping:
|
|
455
|
+
return {
|
|
456
|
+
'rules': [],
|
|
457
|
+
'client_mapping': None
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
# Get the IB ID from the client mapping if not provided
|
|
461
|
+
if not ib_id:
|
|
462
|
+
ib_id = client_mapping.direct_ib_customer_id
|
|
463
|
+
|
|
464
|
+
# PRIORITY 1: Check for account-specific agreement overrides
|
|
435
465
|
account_agreements = IBAccountAgreement.objects.filter(
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
agreement_id__in=ib_agreements,
|
|
466
|
+
mt5_login=mt5_account_id,
|
|
467
|
+
ib_customer_id=ib_id,
|
|
439
468
|
is_active=True
|
|
440
469
|
).values_list('agreement_id', flat=True)
|
|
441
470
|
|
|
442
|
-
# If
|
|
443
|
-
if
|
|
444
|
-
#
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
471
|
+
# If account-specific agreements exist, use those
|
|
472
|
+
if account_agreements:
|
|
473
|
+
# Find rules matching the criteria from account-specific agreements
|
|
474
|
+
rules_query = IBCommissionRule.objects.filter(
|
|
475
|
+
agreement_id__in=account_agreements,
|
|
476
|
+
is_active=True
|
|
477
|
+
).filter(
|
|
478
|
+
models.Q(symbol__iexact=symbol) | models.Q(symbol='*')
|
|
479
|
+
).filter(
|
|
480
|
+
models.Q(order_type__iexact=order_type) | models.Q(order_type='*')
|
|
481
|
+
)
|
|
450
482
|
|
|
451
|
-
if
|
|
452
|
-
|
|
483
|
+
# Apply additional filters if provided
|
|
484
|
+
if kwargs:
|
|
485
|
+
rules_query = rules_query.filter(**kwargs)
|
|
453
486
|
|
|
454
|
-
#
|
|
455
|
-
|
|
456
|
-
account_agreements = [client_mapping.agreement_id]
|
|
457
|
-
else:
|
|
458
|
-
# Otherwise, use all of the IB's agreements
|
|
459
|
-
account_agreements = ib_agreements
|
|
487
|
+
# Order by priority
|
|
488
|
+
rules = rules_query.order_by('priority')
|
|
460
489
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
490
|
+
if rules:
|
|
491
|
+
return {
|
|
492
|
+
'rules': list(rules),
|
|
493
|
+
'client_mapping': client_mapping
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
# If client mapping exists and has a specific agreement, use that
|
|
497
|
+
if client_mapping and client_mapping.agreement_id:
|
|
498
|
+
# Find rules matching the criteria from the client mapping agreement
|
|
499
|
+
rules_query = IBCommissionRule.objects.filter(
|
|
500
|
+
agreement_id=client_mapping.agreement_id,
|
|
501
|
+
is_active=True
|
|
502
|
+
).filter(
|
|
503
|
+
models.Q(symbol__iexact=symbol) | models.Q(symbol='*')
|
|
504
|
+
).filter(
|
|
505
|
+
models.Q(order_type__iexact=order_type) | models.Q(order_type='*')
|
|
506
|
+
)
|
|
507
|
+
|
|
508
|
+
# Apply additional filters if provided
|
|
509
|
+
if kwargs:
|
|
510
|
+
rules_query = rules_query.filter(**kwargs)
|
|
511
|
+
|
|
512
|
+
# Order by priority
|
|
513
|
+
rules = rules_query.order_by('priority')
|
|
514
|
+
|
|
515
|
+
if rules:
|
|
516
|
+
return {
|
|
517
|
+
'rules': list(rules),
|
|
518
|
+
'client_mapping': client_mapping
|
|
519
|
+
}
|
|
481
520
|
|
|
482
|
-
|
|
521
|
+
# If we get here, no applicable rules were found
|
|
522
|
+
return {
|
|
523
|
+
'rules': [],
|
|
524
|
+
'client_mapping': client_mapping
|
|
525
|
+
}
|
|
483
526
|
|
|
484
527
|
@classmethod
|
|
485
528
|
def _calculate_client_deduction(cls, distributions):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/fx_shared_models.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/accounts/migrations/0001_initial.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/accounts/migrations/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/company_ba/migrations/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/customers/migrations/0001_initial.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/customers/migrations/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/ib_commission/migrations/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/ib_commission/services/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/models/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/models/base.py
RENAMED
|
File without changes
|
{fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/models/email.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/system_settings/serializers.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fx_shared_models-0.2.6 → fx_shared_models-0.2.7}/shared_models/transactions/migrations/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|