Skip to content

Commit

Permalink
Merge pull request ctpbee#137 from ctpbee/dev
Browse files Browse the repository at this point in the history
fix time checking by trade_date check
  • Loading branch information
somewheve authored Feb 28, 2021
2 parents 257de80 + 4421808 commit 98b1ebe
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 21 deletions.
2 changes: 1 addition & 1 deletion ctpbee/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
for the future of life
"""
__version__ = '1.3.5'
__version__ = '1.3.6'
__status__ = 'develop level'

# Here are some import
Expand Down
25 changes: 14 additions & 11 deletions ctpbee/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class Interval(Enum):


@dataclass(init=False, repr=False)
class BaseData:
class Entity:
"""
Any data object needs a gateway_name as source
and should inherit base data.
Expand Down Expand Up @@ -310,7 +310,7 @@ def _asdict(self):
return asdict(self)


class TickData(BaseData):
class TickData(Entity):
"""
Tick data contains information about:
* last trade in market
Expand Down Expand Up @@ -371,7 +371,7 @@ def __post_init__(self):
self.local_symbol = f"{self.symbol}.{self.exchange.value}"


class BarData(BaseData):
class BarData(Entity):
"""
Candlestick bar data of a certain trading period.
"""
Expand Down Expand Up @@ -400,7 +400,8 @@ def __post_init__(self):
except AttributeError:
self.local_symbol = f"{self.symbol}.{self.exchange}"

class OrderData(BaseData):

class OrderData(Entity):
"""
Order data contains information for tracking lastest status
of a specific order.
Expand All @@ -418,6 +419,7 @@ class OrderData(BaseData):
traded: float = 0
status: Status = Status.SUBMITTING
time: str = ""
is_local = True

def __post_init__(self):
""""""
Expand Down Expand Up @@ -446,7 +448,7 @@ def create_cancel_request(self):
return req


class TradeData(BaseData):
class TradeData(Entity):
"""
Trade data contains information of a fill of an order. One order
can have several trade fills.
Expand All @@ -464,6 +466,7 @@ class TradeData(BaseData):
volume: float = 0
time: str = ""
order_time: str = ""
is_local = True

def __post_init__(self):
""""""
Expand All @@ -475,7 +478,7 @@ def __post_init__(self):
self.local_trade_id = f"{self.gateway_name}.{self.tradeid}"


class PositionData(BaseData):
class PositionData(Entity):
"""
Positon data is used for tracking each individual position holding.
"""
Expand All @@ -496,7 +499,7 @@ def __post_init__(self):
self.local_position_id = f"{self.local_symbol}.{self.direction}"


class AccountData(BaseData):
class AccountData(Entity):
"""
Account data contains information about balance, frozen and
available.
Expand All @@ -513,7 +516,7 @@ def __post_init__(self):
self.local_account_id = f"{self.gateway_name}.{self.accountid}"


class LogData(BaseData):
class LogData(Entity):
"""
Log data is used for recording log messages on GUI or in log files.
"""
Expand All @@ -526,7 +529,7 @@ def __post_init__(self):
self.time = datetime.now()


class LastData(BaseData):
class LastData(Entity):
symbol: str
exchange: Exchange
pre_open_interest: float
Expand All @@ -538,7 +541,7 @@ def __post_init__(self):
self.local_symbol = f"{self.symbol}.{self.exchange.value}"


class ContractData(BaseData):
class ContractData(Entity):
"""
Contract data contains basic information about each contract traded.
"""
Expand Down Expand Up @@ -645,7 +648,7 @@ def __post_init__(self):
self.local_symbol = f"{self.symbol}.{self.exchange.value}"


class SharedData(BaseData):
class SharedData(Entity):
local_symbol: str
datetime: datetime

Expand Down
19 changes: 14 additions & 5 deletions ctpbee/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,21 @@ def __init__(self):
}

def auth_time(self, current: datetime):
if str(current.date()) not in trade_dates:
return False
if ((current.today().weekday() == 6) or
(current.today().weekday() == 5 and current.time() > self.NIGHT_END) or
(current.today().weekday() == 0 and current.time() < self.DAY_START)):
current_string = str(current.date())

last_day = str((current + timedelta(days=-1)).date())
"""
如果前一天是交易日, 今天不是 那么交易到今晚晚上2点:30
如果前一天不是交易日,今天是 那么早盘前 不启动
如果前一天不是交易日, 今天也不是交易日 那么不启动
"""
if (last_day in trade_dates and current_string not in trade_dates and current.time() > self.NIGHT_END) or \
(last_day not in trade_dates and current_string in trade_dates and current.time() < self.DAY_START) or \
(last_day not in trade_dates and current_string not in trade_dates):
return False

if self.DAY_END >= current.time() >= self.DAY_START:
return True
if current.time() >= self.NIGHT_START:
Expand Down
5 changes: 3 additions & 2 deletions ctpbee/interface/ctp/td_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ def onRtnOrder(self, data: dict):
ordertype = ORDERTYPE_CTP2VT[data["OrderPriceType"]]
else:
ordertype = "non_support"
is_local = True if int(self.frontid) == int(frontid) and int(self.sessionid) == int(sessionid) else False
order = OrderData(
symbol=symbol,
exchange=exchange,
Expand All @@ -338,7 +339,8 @@ def onRtnOrder(self, data: dict):
traded=data["VolumeTraded"],
status=STATUS_CTP2VT[data["OrderStatus"]],
time=data["InsertTime"],
gateway_name=self.gateway_name
gateway_name=self.gateway_name,
is_local=is_local
)
self.on_event(type=EVENT_ORDER, data=order)
self.sysid_orderid_map[data["OrderSysID"]] = order_id
Expand All @@ -354,7 +356,6 @@ def onRtnTrade(self, data: dict):
return

order_id = self.sysid_orderid_map[data["OrderSysID"]]

trade = TradeData(
symbol=symbol,
exchange=exchange,
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ def run(self):
long_description = ""

pkgs = ['ctpbee', 'ctpbee.context', 'ctpbee.exceptions', 'ctpbee.data_handle', 'ctpbee.interface',
'ctpbee.interface.ctp', "ctpbee.interface.looper", 'ctpbee.jsond', "ctpbee.looper", "ctpbee.indicator",
"ctpbee.qa_support"]
'ctpbee.interface.ctp', "ctpbee.interface.looper", 'ctpbee.jsond', "ctpbee.looper", "ctpbee.indicator"]

setup(
name='ctpbee',
Expand Down

0 comments on commit 98b1ebe

Please sign in to comment.