Skip to content

Commit

Permalink
Merge pull request #3 from Edanflame/main
Browse files Browse the repository at this point in the history
[Fix]修复无法撤单的Bug
  • Loading branch information
vnpy committed Oct 28, 2021
2 parents 08e933e + 760da71 commit e69c448
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 36 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ if __name__ == "__main__":

## 注意

连接前请先修改libcrypto.so为libcrypto.so.10,libssl.so为libssl.so.10。
连接前请先将运行的python下lib/site-packages文件夹下vnpy_sgit/api中的rsa.pk文件放到运行目录。并修改libcrypto.so为libcrypto.so.10,libssl.so为libssl.so.10。
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ install_requires =
importlib_metadata

[options.package_data]
* = *.dll, *.so, *.pyd
* = *.dll, *.so, *.pyd, *.pk
Binary file modified vnpy_sgit/.DS_Store
Binary file not shown.
Binary file modified vnpy_sgit/api/.DS_Store
Binary file not shown.
9 changes: 9 additions & 0 deletions vnpy_sgit/api/rsa.pk
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu4T0uym4ysdtcMGMii3X
GOfdR3eePt+jaB7iDcEiBG+L+xhwPaMlsiXH1dcI+NZwIBWU6Y5ZyStir1xWtIqo
Yn1IOoy+f9rCw7bX9nn61Re2kGY6IYHSmh4s3JHnTf1+HoSS4tHu4AQW/cev7B4r
4f87I5/yPkMMiSR8NsJWWWOVErz907F7xNKuiQInQKk2RGxQQwykYdwh+6U5mu8r
uEaHRE3RrGZQksH+VPoOF0Dmh2cpNrQf1XRl7EuJKQDoivP/TYm0GWob7v3H5APj
WOyqZxe1buW2AhDMwEZ8Ra51z8C4Fd/GkPyiq59HdyU1Jqrlkw5xInGd2Wnyihc+
SwIDAQAB
-----END PUBLIC KEY-----
Binary file added vnpy_sgit/gateway/.DS_Store
Binary file not shown.
49 changes: 15 additions & 34 deletions vnpy_sgit/gateway/sgit_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,25 +418,13 @@ def onFrontConnected(self) -> None:
"""服务器连接成功回报"""
self.gateway.write_log("交易服务器连接成功")

if self.auth_code:
self.authenticate()
else:
self.login()
self.login()

def onFrontDisconnected(self, reason: int) -> None:
"""服务器连接断开回报"""
self.login_status: bool = False
self.gateway.write_log(f"交易服务器连接断开,原因{reason}")

def onRspAuthenticate(self, data: dict, error: dict, reqid: int, last: bool) -> None:
"""用户授权验证回报"""
if not error['ErrorID']:
self.auth_status: bool = True
self.gateway.write_log("交易服务器授权验证成功")
self.login()
else:
self.gateway.write_error("交易服务器授权验证失败", error)

def onRspUserLogin(self, data: dict, error: dict, reqid: int, last: bool) -> None:
"""用户登录请求回报"""
if not error["ErrorID"]:
Expand Down Expand Up @@ -629,8 +617,12 @@ def onRtnOrder(self, data: dict) -> None:
orderid: str = data["OrderRef"]
self.order_ref = max(self.order_ref, int(orderid))

timestamp: str = f"{data['InsertDate']} {data['InsertTime']}"
dt: datetime = datetime.strptime(timestamp, "%Y%m%d %H:%M:%S")
if data['InsertDate']:
timestamp: str = f"{data['InsertDate']} {data['InsertTime']}"
dt: datetime = datetime.strptime(timestamp, "%Y%m%d %H:%M:%S")
else:
timestamp: str = f"{data['InsertTime']}"
dt: datetime = datetime.strptime(timestamp, "%H:%M:%S")
dt: datetime = CHINA_TZ.localize(dt)

order: OrderData = OrderData(
Expand Down Expand Up @@ -661,8 +653,12 @@ def onRtnTrade(self, data: dict) -> None:

orderid: str = self.sysid_orderid_map[data["OrderSysID"]]

timestamp: str = f"{data['TradeDate']} {data['TradeTime']}"
dt: datetime = datetime.strptime(timestamp, "%Y%m%d %H:%M:%S")
if data['TradeDate']:
timestamp: str = f"{data['TradeDate']} {data['TradeTime']}"
dt: datetime = datetime.strptime(timestamp, "%Y%m%d %H:%M:%S")
else:
timestamp: str = f"{data['TradeTime']}"
dt: datetime = datetime.strptime(timestamp, "%H:%M:%S")
dt: datetime = CHINA_TZ.localize(dt)

trade: TradeData = TradeData(
Expand Down Expand Up @@ -706,23 +702,6 @@ def connect(
self.init()

self.connect_status: bool = True
else:
self.authenticate()

def authenticate(self) -> None:
"""发起授权验证"""
req: dict = {
"UserID": self.userid,
"BrokerID": self.brokerid,
"AuthCode": self.auth_code,
"AppID": self.appid
}

if self.product_info:
req["UserProductInfo"] = self.product_info

self.reqid += 1
self.reqAuthenticate(req, self.reqid)

def login(self) -> None:
"""用户登录"""
Expand All @@ -733,6 +712,7 @@ def login(self) -> None:
"UserID": self.userid,
"Password": self.password,
"BrokerID": self.brokerid,
"AuthCode": self.auth_code,
"AppID": self.appid
}

Expand Down Expand Up @@ -803,6 +783,7 @@ def cancel_order(self, req: CancelRequest) -> None:
"ActionFlag": THOST_FTDC_AF_Delete,
"BrokerID": self.brokerid,
"InvestorID": self.userid,
"UserID": self.userid
}

self.reqid += 1
Expand Down

0 comments on commit e69c448

Please sign in to comment.