Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CI on develop branch #1367

Merged
merged 8 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: psf/black@stable
with:
version: "23.11.0"
6 changes: 3 additions & 3 deletions .github/workflows/quick-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ on:
jobs:
build:

runs-on: ubuntu-20.04
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ 3.10.13 ]

steps:

- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/slow-test-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ on:
jobs:
build:

runs-on: ubuntu-20.04
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ 3.10.13 ]

steps:

- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: "develop"

- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pandas==2.1.3
matplotlib>=3.0.0
pyyaml==5.3.1
pyyaml==6.0.1
numpy>=1.24.0
scipy>=1.0.0
pymongo==3.11.3
Expand All @@ -12,4 +12,4 @@ Werkzeug>=2.0.1
statsmodels==0.14.0
PyPDF2>=2.5.0
pyarrow>=14.0.1
scikit-learn>1.3.0
scikit-learn>1.3.0
2 changes: 1 addition & 1 deletion sysbrokers/IB/client/ib_orders_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def broker_submit_order(
account_id: str = arg_not_supplied,
order_type: brokerOrderType = market_order_type,
limit_price: float = None,
what_if: bool = False
what_if: bool = False,
) -> tradeWithContract:
"""

Expand Down
28 changes: 20 additions & 8 deletions sysbrokers/IB/ib_broker_commissions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from sysbrokers.IB.ib_connection import connectionIB
from sysbrokers.IB.ib_orders import ibExecutionStackData
from sysbrokers.IB.ib_translate_broker_order_objects import tradeWithContract
from sysbrokers.broker_contract_commission_data import brokerFuturesContractCommissionData
from sysbrokers.broker_contract_commission_data import (
brokerFuturesContractCommissionData,
)
from sysdata.data_blob import dataBlob
from sysexecution.orders.broker_orders import brokerOrder
from sysobjects.contracts import futuresContract
Expand Down Expand Up @@ -40,17 +42,20 @@ def ibconnection(self) -> connectionIB:
def execution_stack(self) -> ibExecutionStackData:
return self.data.broker_execution_stack

def get_commission_for_contract(self, futures_contract: futuresContract) -> currencyValue:
def get_commission_for_contract(
self, futures_contract: futuresContract
) -> currencyValue:
instrument_code = futures_contract.instrument_code
contract_date = futures_contract.contract_date.list_of_date_str[0]

broker_order =brokerOrder(test_commission_strategy, instrument_code, contract_date,
size_of_test_trade)
broker_order = brokerOrder(
test_commission_strategy, instrument_code, contract_date, size_of_test_trade
)

order = self.execution_stack.what_if_order(broker_order)

timer = quickTimer(5)
comm_currency_value = currencyValue(currency='', value=0)
comm_currency_value = currencyValue(currency="", value=0)
while timer.unfinished:
try:
comm_currency_value = get_commission_and_currency_from_ib_order(order)
Expand All @@ -59,8 +64,15 @@ def get_commission_for_contract(self, futures_contract: futuresContract) -> curr

return comm_currency_value

def get_commission_and_currency_from_ib_order(ib_order: tradeWithContract) -> currencyValue:
return currencyValue(value=ib_order.trade.commission / size_of_test_trade, currency=ib_order.trade.commissionCurrency)

test_commission_strategy = "testCommmission" ## whatever not put on stack
def get_commission_and_currency_from_ib_order(
ib_order: tradeWithContract,
) -> currencyValue:
return currencyValue(
value=ib_order.trade.commission / size_of_test_trade,
currency=ib_order.trade.commissionCurrency,
)


test_commission_strategy = "testCommmission" ## whatever not put on stack
size_of_test_trade = 10 ## arbitrary
30 changes: 19 additions & 11 deletions sysbrokers/IB/ib_orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,16 @@ def put_order_on_stack(self, broker_order: brokerOrder) -> ibOrderWithControls:
:param broker_order: key properties are instrument_code, contract_id, quantity
:return: ibOrderWithControls or missing_order
"""
trade_with_contract_from_ib = self._send_broker_order_to_IB(broker_order, what_if=False)
trade_with_contract_from_ib = self._send_broker_order_to_IB(
broker_order, what_if=False
)

placed_broker_order_with_controls = self._return_place_order_given_ib_trade_with_contract(trade_with_contract_from_ib=trade_with_contract_from_ib,
broker_order=broker_order)
placed_broker_order_with_controls = (
self._return_place_order_given_ib_trade_with_contract(
trade_with_contract_from_ib=trade_with_contract_from_ib,
broker_order=broker_order,
)
)

return placed_broker_order_with_controls

Expand All @@ -279,13 +285,15 @@ def what_if_order(self, broker_order: brokerOrder) -> tradeWithContract:
:param broker_order: key properties are instrument_code, contract_id, quantity
:return: ibOrderWithControls or missing_order
"""
trade_with_contract_from_ib = self._send_broker_order_to_IB(broker_order, what_if=True)
trade_with_contract_from_ib = self._send_broker_order_to_IB(
broker_order, what_if=True
)

return trade_with_contract_from_ib



def _return_place_order_given_ib_trade_with_contract(self, trade_with_contract_from_ib: tradeWithContract, broker_order: brokerOrder) -> ibOrderWithControls:
def _return_place_order_given_ib_trade_with_contract(
self, trade_with_contract_from_ib: tradeWithContract, broker_order: brokerOrder
) -> ibOrderWithControls:
if trade_with_contract_from_ib is missing_order:
return missing_order

Expand All @@ -307,8 +315,9 @@ def _return_place_order_given_ib_trade_with_contract(self, trade_with_contract_f

return placed_broker_order_with_controls


def _send_broker_order_to_IB(self, broker_order: brokerOrder, what_if: bool = False) -> tradeWithContract:
def _send_broker_order_to_IB(
self, broker_order: brokerOrder, what_if: bool = False
) -> tradeWithContract:
"""

:param broker_order: key properties are instrument_code, contract_id, quantity
Expand Down Expand Up @@ -337,7 +346,7 @@ def _send_broker_order_to_IB(self, broker_order: brokerOrder, what_if: bool = Fa
account_id=account_id,
order_type=order_type,
limit_price=limit_price,
what_if=what_if
what_if=what_if,
)
if placed_broker_trade_object is missing_order:
self.log.warning("Couldn't submit order", **log_attrs)
Expand All @@ -347,7 +356,6 @@ def _send_broker_order_to_IB(self, broker_order: brokerOrder, what_if: bool = Fa

return placed_broker_trade_object


def match_db_broker_order_to_order_from_brokers(
self, broker_order_to_match: brokerOrder
) -> brokerOrder:
Expand Down
6 changes: 3 additions & 3 deletions sysbrokers/broker_contract_commission_data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


from sysdata.futures.contracts import futuresContractData
from sysdata.data_blob import dataBlob
from sysobjects.contracts import futuresContract
Expand All @@ -9,7 +7,9 @@


class brokerFuturesContractCommissionData(futuresContractData):
def __init__(self, data: dataBlob, log=get_logger("brokerFuturesContractCommissionData")):
def __init__(
self, data: dataBlob, log=get_logger("brokerFuturesContractCommissionData")
):
super().__init__(log=log)
self._data = data

Expand Down
2 changes: 1 addition & 1 deletion sysbrokers/broker_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ def get_ib_class_list():
ibCapitalData,
ibFuturesInstrumentData,
ibFxHandlingData,
ibFuturesContractCommissionData
ibFuturesContractCommissionData,
]
2 changes: 0 additions & 2 deletions sysdata/csv/csv_spread_costs.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ def get_spread_costs_as_series(self) -> pd.Series:

return spread_cost_series



def write_all_instrument_spreads(self, spread_cost_as_series: pd.Series):
spread_cost_as_df = pd.DataFrame(spread_cost_as_series)
spread_cost_as_df.columns = [SPREAD_COST_COLUMN_NAME]
Expand Down
1 change: 0 additions & 1 deletion sysdata/futures/spread_costs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def get_spread_cost(self, instrument_code: str) -> float:
def get_spread_costs_as_series(self) -> pd.Series:
raise NotImplementedError


def _get_spread_cost_if_series_provided(self, instrument_code: str) -> float:
all_data = self.get_spread_costs_as_series()
return all_data[instrument_code]
Expand Down
13 changes: 9 additions & 4 deletions sysproduction/data/broker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from copy import copy

from sysbrokers.broker_contract_commission_data import brokerFuturesContractCommissionData
from sysbrokers.broker_contract_commission_data import (
brokerFuturesContractCommissionData,
)
from sysbrokers.broker_factory import get_broker_class_list
from sysbrokers.broker_fx_handling import brokerFxHandlingData
from sysbrokers.broker_static_data import brokerStaticData
Expand Down Expand Up @@ -103,9 +105,12 @@ def diag_controls(self) -> diagControlProcess:
return self._diag_controls

## Methods
def get_commission_for_contract_in_currency_value(self, contract: futuresContract) -> currencyValue:

return self.broker_futures_contract_commission.get_commission_for_contract(contract)
def get_commission_for_contract_in_currency_value(
self, contract: futuresContract
) -> currencyValue:
return self.broker_futures_contract_commission.get_commission_for_contract(
contract
)

def get_list_of_contract_dates_for_instrument_code(
self, instrument_code: str, allow_expired: bool = False
Expand Down
16 changes: 12 additions & 4 deletions sysproduction/data/instruments.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,30 @@ def _add_required_classes_to_data(self, data: dataBlob) -> dataBlob:
def get_spread_costs_as_series(self):
return self.db_spread_cost_data.get_spread_costs_as_series()

def get_block_commission_for_instrument_as_currency_value(self, instrument_code: str) -> currencyValue:
def get_block_commission_for_instrument_as_currency_value(
self, instrument_code: str
) -> currencyValue:
currency = self.get_currency(instrument_code)
block_commission = self.get_block_commission_for_instrument_as_in_instrument_currency(instrument_code)
block_commission = (
self.get_block_commission_for_instrument_as_in_instrument_currency(
instrument_code
)
)
ccy_value = currencyValue(currency=currency, value=block_commission)

return ccy_value

def get_block_commission_for_instrument_as_in_instrument_currency(self, instrument_code: str) -> float:
def get_block_commission_for_instrument_as_in_instrument_currency(
self, instrument_code: str
) -> float:
costs = self.get_cost_object(instrument_code)
block_commission = costs.value_of_block_commission

return block_commission

def has_percentage_commission(self, instrument_code: str) -> float:
costs = self.get_cost_object(instrument_code)
return costs.percentage_cost>0
return costs.percentage_cost > 0

def get_cost_object(self, instrument_code: str) -> instrumentCosts:
meta_data = self.get_meta_data(instrument_code)
Expand Down
3 changes: 2 additions & 1 deletion sysproduction/interactive_diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
remove_markets_report_config,
market_monitor_report_config,
account_curve_report_config,
commission_report_config
commission_report_config,
)


Expand Down Expand Up @@ -233,6 +233,7 @@ def slippage_report(data):
report_config.modify_kwargs(start_date=start_date, end_date=end_date)
run_report(report_config, data=data)


def commission_report(data):
report_config = email_or_print_or_file(commission_report_config)
run_report(report_config, data=data)
Expand Down
9 changes: 6 additions & 3 deletions sysproduction/reporting/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@
get_position_limits_as_df,
)
from sysproduction.reporting.data.volume import get_liquidity_data_df
from sysproduction.reporting.data.commissions import df_of_configure_and_broker_block_cost_sorted_by_diff
from sysproduction.reporting.data.commissions import (
df_of_configure_and_broker_block_cost_sorted_by_diff,
)

REPORT_DATETIME_FORMAT = "%d/%m/%Y %H:%M"

Expand Down Expand Up @@ -953,11 +955,12 @@ def df_commissions(self):
return self.cache.get(self._df_commissions)

def _df_commissions(self):
combined_df_costs = df_of_configure_and_broker_block_cost_sorted_by_diff(self.data)
combined_df_costs = df_of_configure_and_broker_block_cost_sorted_by_diff(
self.data
)

return combined_df_costs


##### TRADES ######
def table_of_orders_overview(self):
broker_orders = self.broker_orders
Expand Down
3 changes: 1 addition & 2 deletions sysproduction/reporting/commissions_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ def commissions_report(
data = dataBlob()

reporting_api = reportingApi(
data,
start_date=datetime.datetime.now() ## not required for this report
data, start_date=datetime.datetime.now() ## not required for this report
)

formatted_output = []
Expand Down
Loading