forked from jasonweiyi/XAPI2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXSpi.py
More file actions
68 lines (49 loc) · 1.92 KB
/
XSpi.py
File metadata and controls
68 lines (49 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# import pydevd
from .XStruct import *
import logging
logger = logging.getLogger("XApi")
class XSpi(object):
def OnConnectionStatus(self, api, status, pUserLogin, size1):
logger.info('OnConnectionStatus={0}'.format(ConnectionStatus[status]))
if size1 > 0:
logger.info(pUserLogin)
def OnRtnError(self, api, pError):
logger.error(pError)
def OnRtnInstrumentStatus(self, api, pInstrumentStatus):
logger.debug(pInstrumentStatus)
def OnLog(self, api, pLog):
logger.info(pLog)
def OnRspQryInstrument(self, api, pInstrument, size1, bIsLast):
if size1 > 0:
logger.info(pInstrument)
def OnRspQryTradingAccount(self, api, pAccount, size1, bIsLast):
if size1 > 0:
logger.info(pAccount)
def OnRspQryInvestorPosition(self, api, pPosition, size1, bIsLast):
if size1 > 0:
logger.info(pPosition)
def OnRspQryOrder(self, api, pOrder, size1, bIsLast):
if size1 > 0:
logger.info(pOrder)
def OnRspQryInvestor(self, api, pInvestor, size1, bIsLast):
if size1 > 0:
logger.info(pInvestor)
def OnRtnOrder(self, api, pOrder):
logger.info(pOrder)
def OnRtnTrade(self, api, pTrade):
logger.info(pTrade)
def OnRtnDepthMarketData(self, api, ptr1, size1):
# 这是从交易接口拿到的行情
obj = cast(ptr1, POINTER(DepthMarketDataNField)).contents
logger.info(obj)
# 打印N档行情
for i in range(obj.get_ticks_count()):
p = ptr1 + sizeof(DepthMarketDataNField) + sizeof(DepthField) * i
d = cast(p, POINTER(DepthField)).contents
logger.info(d)
def OnRspQrySettlementInfo(self, api, ptr1, size1, bIsLast):
if size1 > 0:
obj = cast(ptr1, POINTER(SettlementInfoField)).contents
logger.info(obj)