質問編集履歴
1
要点を明確化
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
c
|
1
|
+
ddeclient.pyの167行目でDDE.ClientTransactionがFalseと値を返しているみたいなのですが
|
test
CHANGED
@@ -10,6 +10,24 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
|
13
|
+
ddeclient.pyのrequest関数の中で条件分岐で
|
14
|
+
|
15
|
+
if not hDdeData:
|
16
|
+
|
17
|
+
raise DDEError("Unable to request item", self._idInst)
|
18
|
+
|
19
|
+
hDdeDataがFalseみたいです。
|
20
|
+
|
21
|
+
self._idInstとhszItemはきちんと値が入っています。
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
どうすればいいでしょうか。
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
|
13
31
|
**ddeclient.pyの一部**
|
14
32
|
|
15
33
|
```ddeclient.pyの一部
|
@@ -304,6 +322,102 @@
|
|
304
322
|
|
305
323
|
|
306
324
|
|
325
|
+
def __del__(self):
|
326
|
+
|
327
|
+
"""Cleanup any active connections."""
|
328
|
+
|
329
|
+
if self._hConv:
|
330
|
+
|
331
|
+
DDE.Disconnect(self._hConv)
|
332
|
+
|
333
|
+
if self._idInst:
|
334
|
+
|
335
|
+
DDE.Uninitialize(self._idInst)
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
def advise(self, item, stop=False):
|
340
|
+
|
341
|
+
"""Request updates when DDE data changes."""
|
342
|
+
|
343
|
+
from ctypes import byref
|
344
|
+
|
345
|
+
hszItem = DDE.CreateStringHandle(self._idInst, item, 1200)
|
346
|
+
|
347
|
+
hDdeData = DDE.ClientTransaction(LPBYTE(), 0, self._hConv, hszItem, CF_TEXT, XTYP_ADVSTOP if stop else XTYP_ADVSTART, TIMEOUT_ASYNC, LPDWORD())
|
348
|
+
|
349
|
+
DDE.FreeStringHandle(self._idInst, hszItem)
|
350
|
+
|
351
|
+
if not hDdeData:
|
352
|
+
|
353
|
+
raise DDEError("Unable to %s advise" % ("stop" if stop else "start"), self._idInst)
|
354
|
+
|
355
|
+
DDE.FreeDataHandle(hDdeData)
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
def execute(self, command, timeout=5000):
|
360
|
+
|
361
|
+
"""Execute a DDE command."""
|
362
|
+
|
363
|
+
pData = c_char_p(command)
|
364
|
+
|
365
|
+
cbData = DWORD(len(command) + 1)
|
366
|
+
|
367
|
+
hDdeData = DDE.ClientTransaction(pData, cbData, self._hConv, HSZ(), CF_TEXT, XTYP_EXECUTE, timeout, LPDWORD())
|
368
|
+
|
369
|
+
if not hDdeData:
|
370
|
+
|
371
|
+
raise DDEError("Unable to send command", self._idInst)
|
372
|
+
|
373
|
+
DDE.FreeDataHandle(hDdeData)
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
def request(self, item, timeout=5000):
|
378
|
+
|
379
|
+
"""Request data from DDE service."""
|
380
|
+
|
381
|
+
from ctypes import byref
|
382
|
+
|
383
|
+
hszItem = DDE.CreateStringHandle(self._idInst, item, 1200)
|
384
|
+
|
385
|
+
hDdeData = DDE.ClientTransaction(LPBYTE(), 0, self._hConv, hszItem, CF_TEXT, XTYP_REQUEST, timeout, LPDWORD())
|
386
|
+
|
387
|
+
DDE.FreeStringHandle(self._idInst, hszItem)
|
388
|
+
|
389
|
+
print(self._hConv, hszItem)
|
390
|
+
|
391
|
+
if not hDdeData:
|
392
|
+
|
393
|
+
raise DDEError("Unable to request item", self._idInst)
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
if timeout != TIMEOUT_ASYNC:
|
398
|
+
|
399
|
+
pdwSize = DWORD(0)
|
400
|
+
|
401
|
+
pData = DDE.AccessData(hDdeData, byref(pdwSize))
|
402
|
+
|
403
|
+
if not pData:
|
404
|
+
|
405
|
+
DDE.FreeDataHandle(hDdeData)
|
406
|
+
|
407
|
+
raise DDEError("Unable to access data", self._idInst)
|
408
|
+
|
409
|
+
# TODO: use pdwSize
|
410
|
+
|
411
|
+
DDE.UnaccessData(hDdeData)
|
412
|
+
|
413
|
+
else:
|
414
|
+
|
415
|
+
pData = None
|
416
|
+
|
417
|
+
DDE.FreeDataHandle(hDdeData)
|
418
|
+
|
419
|
+
return pData
|
420
|
+
|
307
421
|
```
|
308
422
|
|
309
423
|
**rakuten_rss.pyのコード**
|
@@ -318,174 +432,80 @@
|
|
318
432
|
|
319
433
|
def rss(code, item):
|
320
434
|
|
435
|
+
dde = DDEClient("rss", str(code))
|
436
|
+
|
437
|
+
try:
|
438
|
+
|
439
|
+
res = dde.request(item).decode('sjis').strip()
|
440
|
+
|
441
|
+
except:
|
442
|
+
|
443
|
+
print('fail: code@', code)
|
444
|
+
|
445
|
+
res = 0
|
446
|
+
|
447
|
+
finally:
|
448
|
+
|
449
|
+
dde.__del__()
|
450
|
+
|
451
|
+
return res
|
452
|
+
|
453
|
+
|
454
|
+
|
455
|
+
|
456
|
+
|
457
|
+
def rss_dict(code, *args):
|
458
|
+
|
459
|
+
dde = DDEClient("rss", str(code))
|
460
|
+
|
461
|
+
res = {}
|
462
|
+
|
463
|
+
try:
|
464
|
+
|
465
|
+
for item in args:
|
466
|
+
|
467
|
+
res[item] = dde.request(item).decode('sjis').strip()
|
468
|
+
|
469
|
+
except:
|
470
|
+
|
471
|
+
print('fail: code@', code)
|
472
|
+
|
473
|
+
res = {}
|
474
|
+
|
475
|
+
finally:
|
476
|
+
|
477
|
+
dde.__del__()
|
478
|
+
|
479
|
+
return res
|
480
|
+
|
481
|
+
|
482
|
+
|
483
|
+
|
484
|
+
|
485
|
+
def fetch_open(code):
|
486
|
+
|
321
|
-
"""
|
487
|
+
""" 始値を返す(SQ計算用に関数切り出し,入力int)
|
488
|
+
|
489
|
+
|
322
490
|
|
323
491
|
Parameters
|
324
492
|
|
325
493
|
----------
|
326
494
|
|
327
|
-
code :
|
495
|
+
code : int
|
328
|
-
|
329
|
-
株価や先物のコード 例:東京電力の場合'9501.T'
|
330
|
-
|
331
|
-
item :
|
332
|
-
|
333
|
-
Returns
|
334
|
-
|
335
|
-
-------
|
336
|
-
|
337
|
-
str
|
338
|
-
|
339
|
-
|
340
496
|
|
341
497
|
Examples
|
342
498
|
|
343
|
-
---------
|
499
|
+
---------
|
344
|
-
|
345
|
-
|
346
|
-
|
500
|
+
|
347
|
-
>>>
|
501
|
+
>>> fetch_open(9551)
|
348
|
-
|
349
|
-
|
502
|
+
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
>>>rss('9501.T' , '現在値')
|
354
|
-
|
355
|
-
'669.00'
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
>>>rss('9501.T' , '銘柄名称')
|
360
|
-
|
361
|
-
'東京電力HD'
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
>>>rss('9501.T' , '現在値詳細時刻')
|
366
|
-
|
367
|
-
|
503
|
+
50050
|
368
|
-
|
369
|
-
|
370
504
|
|
371
505
|
"""
|
372
506
|
|
373
507
|
|
374
508
|
|
375
|
-
dde = DDEClient("rss", str(code))
|
376
|
-
|
377
|
-
try:
|
378
|
-
|
379
|
-
res = dde.request(item).decode('sjis').strip()
|
380
|
-
|
381
|
-
except:
|
382
|
-
|
383
|
-
print('fail: code@', code)
|
384
|
-
|
385
|
-
res = 0
|
386
|
-
|
387
|
-
finally:
|
388
|
-
|
389
|
-
dde.__del__()
|
390
|
-
|
391
|
-
return res
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
def rss_dict(code, *args):
|
398
|
-
|
399
|
-
"""
|
400
|
-
|
401
|
-
楽天RSSから辞書形式で情報を取り出す(複数の詳細情報問い合わせ可)
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
Parameters
|
406
|
-
|
407
|
-
----------
|
408
|
-
|
409
|
-
code : str
|
410
|
-
|
411
|
-
args : *str
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
Returns
|
416
|
-
|
417
|
-
-------
|
418
|
-
|
419
|
-
dict
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
Examples
|
424
|
-
|
425
|
-
----------
|
426
|
-
|
427
|
-
>>>rss_dict('9502.T', '始値','銘柄名称','現在値')
|
428
|
-
|
429
|
-
{'始値': '1739.50', '現在値': '1661.50', '銘柄名称': '中部電力'}
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
"""
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
dde = DDEClient("rss", str(code))
|
440
|
-
|
441
|
-
res = {}
|
442
|
-
|
443
|
-
try:
|
444
|
-
|
445
|
-
for item in args:
|
446
|
-
|
447
|
-
res[item] = dde.request(item).decode('sjis').strip()
|
448
|
-
|
449
|
-
except:
|
450
|
-
|
451
|
-
print('fail: code@', code)
|
452
|
-
|
453
|
-
res = {}
|
454
|
-
|
455
|
-
finally:
|
456
|
-
|
457
|
-
dde.__del__()
|
458
|
-
|
459
|
-
return res
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
def fetch_open(code):
|
466
|
-
|
467
|
-
""" 始値を返す(SQ計算用に関数切り出し,入力int)
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
Parameters
|
472
|
-
|
473
|
-
----------
|
474
|
-
|
475
|
-
code : int
|
476
|
-
|
477
|
-
Examples
|
478
|
-
|
479
|
-
---------
|
480
|
-
|
481
|
-
>>> fetch_open(9551)
|
482
|
-
|
483
|
-
50050
|
484
|
-
|
485
|
-
"""
|
486
|
-
|
487
|
-
|
488
|
-
|
489
509
|
return float(rss(str(code) + '.T', '始値'))
|
490
510
|
|
491
511
|
```
|
@@ -505,7 +525,3 @@
|
|
505
525
|
![イメージ説明](299765a605623166d626a73b095e2da5.png)
|
506
526
|
|
507
527
|
![イメージ説明](71f733e87822eec9ca55fe6ef246b755.png)
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
要は、_hconvつまりHCONV(), つまりc_void_pがないから、rakuten_rss.pyの仕様でエラーを返すみたいなので、そうならないようにするにはどうすればいいでしょうか。
|