Skip to content

Commit

Permalink
Update kiwoom core features
Browse files Browse the repository at this point in the history
  • Loading branch information
elbakramer committed Jan 14, 2022
1 parent 6a99be7 commit 60605d2
Show file tree
Hide file tree
Showing 22 changed files with 1,144 additions and 331 deletions.
6 changes: 4 additions & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ disable=print-statement,
exception-escape,
comprehension-escape,
bad-continuation,
bad-whitespace
bad-whitespace,
assignment-from-none,
assignment-from-no-return

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down Expand Up @@ -454,7 +456,7 @@ ignored-classes=optparse.Values,thread._local,_thread._local
# (useful for modules/projects where namespaces are manipulated during runtime
# and thus existing member attributes cannot be deduced by static analysis). It
# supports qualified module names, as well as Unix pattern matching.
ignored-modules=
ignored-modules=pythoncom,pywintypes

# Show a hint with possible names when a member name was not found. The aspect
# of finding the hint is based on edit distance.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
class KiwoomOpenApiPlusDispatchFunctions:
def CommConnect(self) -> int:
...

def CommTerminate(self) -> None:
...

def CommRqData(
self, sRQName: str, sTrCode: str, nPrevNext: int, sScreenNo: str
) -> int:
...

def GetLoginInfo(self, sTag: str) -> str:
...

def SendOrder(
self,
sRQName: str,
sScreenNo: str,
sAccNo: str,
nOrderType: int,
sCode: str,
nQty: int,
nPrice: int,
sHogaGb: str,
sOrgOrderNo: str,
) -> int:
...

def SendOrderFO(
self,
sRQName: str,
sScreenNo: str,
sAccNo: str,
sCode: str,
lOrdKind: int,
sSlbyTp: str,
sOrdTp: str,
lQty: int,
sPrice: str,
sOrgOrdNo: str,
) -> int:
...

def SetInputValue(self, sID: str, sValue: str) -> None:
...

def SetOutputFID(self, sID: str) -> int:
...

def CommGetData(
self,
sJongmokCode: str,
sRealType: str,
sFieldName: str,
nIndex: int,
sInnerFieldName: str,
) -> str:
...

def DisconnectRealData(self, sScnNo: str) -> None:
...

def GetRepeatCnt(self, sTrCode: str, sRecordName: str) -> int:
...

def CommKwRqData(
self,
sArrCode: str,
bNext: int,
nCodeCount: int,
nTypeFlag: int,
sRQName: str,
sScreenNo: str,
) -> int:
...

def GetAPIModulePath(self) -> str:
...

def GetCodeListByMarket(self, sMarket: str) -> str:
...

def GetConnectState(self) -> int:
...

def GetMasterCodeName(self, sTrCode: str) -> str:
...

def GetMasterListedStockCnt(self, sTrCode: str) -> int:
...

def GetMasterConstruction(self, sTrCode: str) -> str:
...

def GetMasterListedStockDate(self, sTrCode: str) -> str:
...

def GetMasterLastPrice(self, sTrCode: str) -> str:
...

def GetMasterStockState(self, sTrCode: str) -> str:
...

def GetDataCount(self, strRecordName: str) -> int:
...

def GetOutputValue(self, strRecordName: str, nRepeatIdx: int, nItemIdx: int) -> str:
...

def GetCommData(
self, strTrCode: str, strRecordName: str, nIndex: int, strItemName: str
) -> str:
...

def GetCommRealData(self, sTrCode: str, nFid: int) -> str:
...

def GetChejanData(self, nFid: int) -> str:
...

def GetThemeGroupList(self, nType: int) -> str:
...

def GetThemeGroupCode(self, strThemeCode: str) -> str:
...

def GetFutureList(self) -> str:
...

def GetFutureCodeByIndex(self, nIndex: int) -> str:
...

def GetActPriceList(self) -> str:
...

def GetMonthList(self) -> str:
...

def GetOptionCode(self, strActPrice: str, nCp: int, strMonth: str) -> str:
...

def GetOptionCodeByMonth(self, sTrCode: str, nCp: int, strMonth: str) -> str:
...

def GetOptionCodeByActPrice(self, sTrCode: str, nCp: int, nTick: int) -> str:
...

def GetSFutureList(self, strBaseAssetCode: str) -> str:
...

def GetSFutureCodeByIndex(self, strBaseAssetCode: str, nIndex: int) -> str:
...

def GetSActPriceList(self, strBaseAssetGb: str) -> str:
...

def GetSMonthList(self, strBaseAssetGb: str) -> str:
...

def GetSOptionCode(
self, strBaseAssetGb: str, strActPrice: str, nCp: int, strMonth: str
) -> str:
...

def GetSOptionCodeByMonth(
self, strBaseAssetGb: str, sTrCode: str, nCp: int, strMonth: str
) -> str:
...

def GetSOptionCodeByActPrice(
self, strBaseAssetGb: str, sTrCode: str, nCp: int, nTick: int
) -> str:
...

def GetSFOBasisAssetList(self) -> str:
...

def GetOptionATM(self) -> str:
...

def GetSOptionATM(self, strBaseAssetGb: str) -> str:
...

def GetBranchCodeName(self) -> str:
...

def CommInvestRqData(self, sMarketGb: str, sRQName: str, sScreenNo: str) -> int:
...

def SendOrderCredit(
self,
sRQName: str,
sScreenNo: str,
sAccNo: str,
nOrderType: int,
sCode: str,
nQty: int,
nPrice: int,
sHogaGb: str,
sCreditGb: str,
sLoanDate: str,
sOrgOrderNo: str,
) -> int:
...

def KOA_Functions(self, sFunctionName: str, sParam: str) -> str:
...

def SetInfoData(self, sInfoData: str) -> int:
...

def SetRealReg(
self, strScreenNo: str, strCodeList: str, strFidList: str, strOptType: str
) -> int:
...

def GetConditionLoad(self) -> int:
...

def GetConditionNameList(self) -> str:
...

def SendCondition(
self, strScrNo: str, strConditionName: str, nIndex: int, nSearch: int
) -> int:
...

def SendConditionStop(
self, strScrNo: str, strConditionName: str, nIndex: int
) -> None:
...

def GetCommDataEx(self, strTrCode: str, strRecordName: str) -> None:
...

def SetRealRemove(self, strScrNo: str, strDelCode: str) -> None:
...

def GetMarketType(self, sTrCode: str) -> int:
...
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from __future__ import annotations

from collections import OrderedDict
from typing import Dict, List

import pythoncom

from koapy.backend.kiwoom_open_api_plus.core.KiwoomOpenApiPlusOleItems import (
DISPATCH_OLE_ITEM,
)
from koapy.backend.kiwoom_open_api_plus.core.KiwoomOpenApiPlusSignature import (
KiwoomOpenApiPlusSignature,
)


class KiwoomOpenApiPlusDispatchSignature(KiwoomOpenApiPlusSignature):

DISPATCH_SIGNATURES_BY_NAME: dict[str, KiwoomOpenApiPlusDispatchSignature] = {}

@classmethod
def from_name(cls, name: str) -> KiwoomOpenApiPlusDispatchSignature:
return cls.DISPATCH_SIGNATURES_BY_NAME[name]

@classmethod
def names(cls) -> list[str]:
return list(cls.DISPATCH_SIGNATURES_BY_NAME.keys())


def LoadDispatchSignatures():
dispatch = DISPATCH_OLE_ITEM
if not dispatch:
return {}
dispatch_funcs = [
(name, entry)
for name, entry in dispatch.mapFuncs.items()
if not any(
[
entry.desc[9] & pythoncom.FUNCFLAG_FRESTRICTED
and entry.desc[0] != pythoncom.DISPID_NEWENUM,
entry.desc[3] != pythoncom.FUNC_DISPATCH,
entry.desc[0] == pythoncom.DISPID_NEWENUM,
]
)
]
dispatch_signatures_by_name = OrderedDict()
for func_name, entry in dispatch_funcs:
# pylint: disable=protected-access
signature = KiwoomOpenApiPlusDispatchSignature._from_entry(func_name, entry)
dispatch_signatures_by_name[func_name] = signature
return dispatch_signatures_by_name


KiwoomOpenApiPlusDispatchSignature.DISPATCH_SIGNATURES_BY_NAME = (
LoadDispatchSignatures()
)
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from concurrent.futures import Future
from inspect import Signature
from typing import Any, Callable, List, Tuple, Union
from typing import Any, Callable, List, Optional, Sequence, Tuple, Union

from koapy.backend.kiwoom_open_api_plus.core.KiwoomOpenApiPlusSignature import (
from koapy.backend.kiwoom_open_api_plus.core.KiwoomOpenApiPlusDispatchSignature import (
KiwoomOpenApiPlusDispatchSignature,
)
from koapy.compat.pyside2.QtAxContainer import QAxWidget
from koapy.compat.pyside2.QtCore import QObject, Qt, Signal


Expand All @@ -24,10 +25,10 @@ def run(self):
return
try:
result = self._fn(self._args)
except BaseException as exc:
except BaseException as exc: # pylint: disable=broad-except
self._future.set_exception(exc)
# break a reference cycle with the exception 'exc'
self = None
self = None # pylint: disable=self-cls-assignment
else:
self._future.set_result(result)

Expand All @@ -39,7 +40,12 @@ class KiwoomOpenApiPlusDynamicCallable(QObject):

readyRunnable = Signal(KiwoomOpenApiPlusDynamicCallableRunnable)

def __init__(self, control, name, parent=None):
def __init__(
self,
control: QAxWidget,
name: str,
parent: Optional[QObject] = None,
):
super().__init__(parent)

self._control = control
Expand All @@ -53,9 +59,8 @@ def __init__(self, control, name, parent=None):

self.readyRunnable.connect(self.onReadyRunnable, Qt.QueuedConnection)

self._call = self.call

self.__name__ = self._name
self.__signature__ = self._signature

def bind_dynamic_call_args(self, *args, **kwargs):
try:
Expand Down Expand Up @@ -87,10 +92,10 @@ def check_return_value(self, result):
)
return result

def dynamic_call(self, args):
def dynamic_call(self, args: Sequence[Any]):
return self._control.dynamicCall(self._function, args)

def dynamic_call_and_check(self, args):
def dynamic_call_and_check(self, args: Sequence[Any]):
result = self.dynamic_call(args)
self.check_return_value(result)
return result
Expand All @@ -109,8 +114,8 @@ def async_call(self, *args, **kwargs):
self.readyRunnable.emit(runnable)
return future

def onReadyRunnable(self, runnable):
def onReadyRunnable(self, runnable: KiwoomOpenApiPlusDynamicCallableRunnable):
runnable.run()

def __call__(self, *args, **kwargs):
return self._call(*args, **kwargs)
return self.call(*args, **kwargs)
Loading

0 comments on commit 60605d2

Please sign in to comment.