-
Notifications
You must be signed in to change notification settings - Fork 834
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Rob Carver
committed
Mar 19, 2024
1 parent
57c8c23
commit 91a0dbb
Showing
4 changed files
with
92 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from sysbrokers.IB.ib_connection import connectionIB | ||
from sysbrokers.IB.ib_orders import ibExecutionStackData | ||
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 | ||
|
||
from syslogging.logger import * | ||
|
||
class ibFuturesContractCommissionData(brokerFuturesContractCommissionData): | ||
""" | ||
Extends the baseData object to a data source that reads in and writes prices for specific futures contracts | ||
This gets HISTORIC data from interactive brokers. It is blocking code | ||
In a live production system it is suitable for running on a daily basis to get end of day prices | ||
""" | ||
|
||
def __init__( | ||
self, | ||
ibconnection: connectionIB, | ||
data: dataBlob, | ||
log=get_logger("ibFuturesContractCommissionData"), | ||
): | ||
super().__init__(log=log, data=data) | ||
self._ibconnection = ibconnection | ||
|
||
def __repr__(self): | ||
return "IB Futures commissions data %s" % str(self.ibconnection) | ||
|
||
@property | ||
def ibconnection(self) -> connectionIB: | ||
return self._ibconnection | ||
|
||
@property | ||
def execution_stack(self) -> ibExecutionStackData: | ||
return self.data.broker_execution_stack | ||
|
||
def get_commission_for_contract(self, futures_contract: futuresContract) -> float: | ||
## FOR NOW DO NOT RUN IF ANYTHING ELSE IS RUNNING | ||
## NEEDS CODE TO TAKE THE TEST STRATEGY OFF THE STACK WHEN RETURNING ORDERS | ||
size_of_test_trade = 10 | ||
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) | ||
|
||
order = self.execution_stack.put_what_if_order_on_stack(broker_order) | ||
|
||
while not self.execution_stack.is_completed(order.order.order_id): | ||
## could last forever! | ||
continue | ||
|
||
order_from_stack = self.execution_stack.get_order_with_id_from_stack(order_id=order.order.order_id) | ||
return order_from_stack.commission / 10.0 | ||
|
||
test_commission_strategy = "testCommmission" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.