Skip to content

Commit

Permalink
Merge pull request #1 from Jedore/dev
Browse files Browse the repository at this point in the history
Add xtp/emt/tora channels
  • Loading branch information
Jedore authored Jul 19, 2024
2 parents 2a1d15a + d03503a commit d937707
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 20 deletions.
82 changes: 69 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@
- 展示所有通道
```shell
$ openctp-channels show
Support channels:
ctp - 官方实现
tts - openctp TTS
qq - 腾讯财经
sina - 新浪财经
```
- 展示当前通道
```shell
Expand All @@ -52,18 +47,79 @@

## 支持通道

- [x] TTS
- [x] 新浪财经
只能查询行情,不可以交易,[详情见](https://github.com/openctp/openctp/blob/master/ctp2Sina/readme.md)
- [x] 腾讯财经
只能查询行情,不可以交易,[详情见](https://github.com/openctp/openctp/blob/master/ctp2QQ/readme.md)
- [ ] 中泰XTP
- [ ] 华鑫TORA
- [x] TTS(tts)

| version | win x86 | win x64 | linux x64 |
|---------|--------------------|--------------------|--------------------|
| 6.3.15 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| 6.3.19 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| 6.5.1 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| 6.6.1 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| 6.6.7 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| 6.6.9 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| 6.7.0 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| 6.7.1 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| 6.7.2 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |

- [x] 华鑫证券奇点TORA

[详情跳转](https://github.com/openctp/openctp/tree/master/ctp2STP)

| version | win x86 | win x64 | linux x64 |
|---------|--------------------|--------------------|--------------------|
| 6.3.15 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| 6.3.19 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| 6.5.1 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| 6.6.1 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| 6.6.7 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| 6.6.9 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |

- [x] 东方财富EMT(emt)

[详情跳转](https://github.com/openctp/openctp/tree/master/ctp2EMT)

| version | win x64 | linux x64 |
|---------|--------------------|-----------|
| 6.3.15 | :heavy_check_mark: | :x: |
| 6.3.19 | :heavy_check_mark: | :x: |
| 6.5.1 | :heavy_check_mark: | :x: |
| 6.6.1 | :heavy_check_mark: | :x: |
| 6.6.7 | :heavy_check_mark: | :x: |

- [x] 中泰证券XTP(xtp)

[详情跳转](https://github.com/openctp/openctp/tree/master/ctp2XTP)

| version | win x86 | win x64 | linux x64 |
|---------|---------|--------------------|-----------|
| 6.6.1 | :x: | :heavy_check_mark: | :x: |

- [x] 新浪财经(sina)
只能查询行情,不可以交易,[详情跳转](https://github.com/openctp/openctp/blob/master/ctp2Sina/readme.md)

| version | win x86 | win x64 | linux x64 |
|---------|--------------------|--------------------|--------------------|
| 6.3.15 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| 6.3.19 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| 6.5.1 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| 6.6.1 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| 6.6.7 | :x: | :heavy_check_mark: | :x: |

- [x] 腾讯财经(qq)
只能查询行情,不可以交易,[详情跳转](https://github.com/openctp/openctp/blob/master/ctp2QQ/readme.md)

| version | win x86 | win x64 | linux x64 |
|---------|--------------------|--------------------|--------------------|
| 6.3.15 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| 6.3.19 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| 6.5.1 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| 6.6.1 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| 6.6.7 | :x: | :heavy_check_mark: | :x: |

- [ ] 易盛
- [ ] 易达
- [ ] 东方证券OST
- [ ] 量投QDP
- [ ] 东方财富EMT

## 代码示例

Expand Down
7 changes: 7 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.1.2

- Add `--version` option
- Add emt channel.
- Add xtp channel.
- Add tora channel.

## 0.1.1

2024-06-28
Expand Down
2 changes: 1 addition & 1 deletion src/openctp_ctp_channels/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.1.1'
__version__ = '0.1.2'
93 changes: 88 additions & 5 deletions src/openctp_ctp_channels/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
import requests

CHANNELS = {
'ctp': '官方实现',
'ctp': '上期技术',
'tts': 'openctp TTS',
'qq': '腾讯财经',
'sina': '新浪财经',
'emt': '东方财富EMT',
'xtp': '中泰证券XTP',
'tora': '华鑫证券奇点TORA',
}

BASE_DIR = Path(__file__).parent
Expand All @@ -31,9 +34,6 @@ def __init__(self, channel: str):
self._version_url = ''
self._platform_url = ''

self._ctp_dir = BASE_DIR / '_chan_ctp'
self.check_ctp_dir()

self._openctp_version = self._get_openctp_ctp_version()
self._ctp_version = '.'.join(self._openctp_version.split('.')[:3])
self._platform = self._get_platform()
Expand All @@ -44,6 +44,9 @@ def __init__(self, channel: str):

self._check_version()

self._ctp_dir = BASE_DIR / '_chan_ctp'
self.check_ctp_dir()

@property
def channel(self):
return self._channel
Expand Down Expand Up @@ -71,6 +74,8 @@ def _get_openctp_ctp_version():
for line in os.popen('pip show openctp-ctp').read().splitlines():
if 'Version' in line:
return line.split()[-1].strip()
print("openctp-ctp is not installed. Please install openctp-ctp first!")
exit(0)

@staticmethod
def _get_openctp_ctp_lib_path():
Expand Down Expand Up @@ -134,7 +139,7 @@ def download_lib(self, name: str, md5_string: str):
def _download_libs(self):
rsp = requests.get(self._platform_url)
if 404 == rsp.status_code:
print(f'Channel {self._channel} don\'t support {self._ctp_version} on {self._platform}. Please reselect!')
print(f'Warning: Channel {self._channel} don\'t support {self._ctp_version} on {self._platform}!')
exit(0)
elif 200 != rsp.status_code:
raise Exception(f'Parse libs failed: {rsp.status_code} {rsp.text}')
Expand Down Expand Up @@ -249,7 +254,15 @@ def current_channel(self):

return channel

def _del_old_files(self):
for _, _, filenames in os.walk(self._ctp_lib_path):
for filename in filenames:
if not filename.startswith("msvcp140"):
os.remove(self._ctp_lib_path / filename)

def _copy_libs(self):
self._del_old_files()

lib_dict = {}
for lib_name in self._get_libs():
s1, s2 = lib_name.split('-')
Expand All @@ -269,12 +282,19 @@ def _copy_libs(self):

shutil.copyfile(self._channel_dir / filename, dst)

def _copy_files(self, files: list):
for file in files:
dst = self._ctp_lib_path / file
shutil.copyfile(self._channel_dir / file, dst)


class CTPChannel(Channel):
def __init__(self):
super().__init__('ctp')

def _copy_libs(self):
self._del_old_files()

for _, _, filenames in os.walk(self._channel_dir):
for filename in filenames:
if self._check_lib_prefix(filename):
Expand Down Expand Up @@ -349,6 +369,69 @@ def switch(self):
self._copy_libs()


class EMTChannel(Channel):

def __init__(self):
super().__init__('emt')

def switch(self):
if self.current_channel() == self._channel:
print('Current channel is', self._channel)
return

print(f'Switch to {self._channel} channel.')

self._download()
self._backup()
self._copy_libs()

def _copy_libs(self):
super()._copy_libs()
self._copy_files(['emt_api.dll', 'emt_quote_api.dll'])


class XTPChannel(Channel):

def __init__(self):
super().__init__('xtp')

def switch(self):
if self.current_channel() == self._channel:
print('Current channel is', self._channel)
return

print(f'Switch to {self._channel} channel.')

self._download()
self._backup()
self._copy_libs()

def _copy_libs(self):
super()._copy_libs()
self._copy_files(['xtpquoteapi.dll', 'xtptraderapi.dll'])


class ToraChannel(Channel):

def __init__(self):
super().__init__('tora')

def switch(self):
if self.current_channel() == self._channel:
print('Current channel is', self._channel)
return

print(f'Switch to {self._channel} channel.')

self._download()
self._backup()
self._copy_libs()

def _copy_libs(self):
super()._copy_libs()
self._copy_files(['fasttraderapi.dll', 'xfastmdapi.dll'])


if __name__ == '__main__':
# c = TTSChannel()
# c.switch()
Expand Down
9 changes: 8 additions & 1 deletion src/openctp_ctp_channels/cli.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import click
from openctp_ctp_channels import channels
from openctp_ctp_channels import channels, __about__


@click.group()
@click.version_option(version=__about__.__version__)
def main():
pass

Expand All @@ -24,6 +25,12 @@ def switch(channel):
channel = channels.QQChannel()
elif 'sina' == channel:
channel = channels.SinaChannel()
elif 'emt' == channel:
channel = channels.EMTChannel()
elif 'xtp' == channel:
channel = channels.XTPChannel()
elif 'tora' == channel:
channel = channels.ToraChannel()
else:
print("Unsupported channel!")
return
Expand Down

0 comments on commit d937707

Please sign in to comment.