Skip to content

Commit

Permalink
Merge pull request #1 from zsrl/develop
Browse files Browse the repository at this point in the history
perf: 修改创建参数
  • Loading branch information
zsrl authored Jul 14, 2024
2 parents 1105f59 + 6bc98b5 commit 5bdab7e
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 58 deletions.
92 changes: 66 additions & 26 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,78 @@
name: Python package

on:
push:
tags:
- "v*.*.*"
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
Test:
runs-on: windows-latest
permissions: write-all

env:
POETRY_HTTP_TIMEOUT: 600

steps:
- uses: actions/checkout@v2
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Ensure full history for semantic-release

- name: Set up Python
uses: actions/setup-python@v2
- name: Set up Python 3.9
uses: actions/setup-python@v5
with:
python-version: '3.9' # You can specify your required Python version here

- name: Install dependencies
- name: Install Poetry and Build
run: |
python -m pip install --upgrade pip
pip install pyyaml
pip install auto-changelog
pip install poetry setuptools cython
python setup.py build_ext --inplace
shell: bash

- name: Build and publish to PyPI
uses: JRubics/[email protected]
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
ignore_dev_requirements: "yes"
pypi_token: ${{ secrets.PYPI_TOKEN }}
python-version: '3.10' # You can specify your required Python version here

- name: Changelog
uses: ardalanamini/auto-changelog@master
id : changelog
- name: Check release status
id: release-status
run: |
pip install python-semantic-release
if semantic-release --noop --strict version; then
echo "::set-output name=released::true"
else
echo "::set-output name=released::false"
fi
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create Release
uses: softprops/action-gh-release@v1
env :
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
body : |
${{ steps.changelog.outputs.changelog }}
prerelease: ${{ steps.changelog.outputs.prerelease }}
- name: Semantic Release Version
if: steps.release-status.outputs.released == 'true'
run: |
semantic-release version
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}

- name: Release to PyPI
if: steps.release-status.outputs.released == 'true'
run: |
poetry config pypi-token.pypi $PYPI_TOKEN
poetry publish --build
shell: bash
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}

- name: Release to GitHub
if: steps.release-status.outputs.released == 'true'
run: |
git fetch --tags
for file in ./dist/*; do
gh release upload "${{ steps.release-status.outputs.tag }}" $file
done
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ authors = ["pluto <[email protected]>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.8"
python = ">=3.9, <3.13"
backtrader = "^1.9.78.123"
pandas = "^2.0.2"
schedule = "^1.2.0"
xtquant = "^240613.1.1"
matplotlib = "^3.9.0"


[tool.poetry.group.dev.dependencies]
Expand Down
41 changes: 10 additions & 31 deletions qmtbt/qmtstore.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import random
import sys
import importlib.util
from xtquant import xtdata, xttrader, xttype

import backtrader as bt
from backtrader.metabase import MetaParams
Expand Down Expand Up @@ -39,42 +38,22 @@ def getbroker(self, *args, **kwargs):
'''Returns broker with *args, **kwargs from registered ``BrokerCls``'''
return self.__class__.BrokerCls(*args, **kwargs)

def __init__(self, mini_qmt_path, xtquant_path, account, token=None):
def __init__(self):

self.mini_qmt_path = mini_qmt_path
self.xtquant_path = xtquant_path
self.account = account
self.mini_qmt_path = ''
self.code_list = []
self.last_tick = None
self.token = token

# 创建模块spec
spec = importlib.util.spec_from_file_location('xtquant', f'{self.xtquant_path}\__init__.py')

# 创建模块实例
module = importlib.util.module_from_spec(spec)

# 加载模块到当前Python环境
spec.loader.exec_module(module)

sys.modules['xtquant'] = module

from xtquant import xtdata, xttrader, xttype

self.xtdata = xtdata
self.xttrader = xttrader
self.xttype = xttype
self.xt_trader = None
self.token = None

def connect(self):
def connect(self, mini_qmt_path, account):

try:
self.xtdata.connect()
xtdata.connect()
except:
return -1

session_id = int(random.randint(100000, 999999))
xt_trader = self.xttrader.XtQuantTrader(self.mini_qmt_path, session_id)
xt_trader = xttrader.XtQuantTrader(mini_qmt_path, session_id)

xt_trader.start()

Expand All @@ -83,7 +62,7 @@ def connect(self):
if connect_result == 0:
print('连接成功')

self.stock_account = self.xttype.StockAccount(self.account)
self.stock_account = xttype.StockAccount(account)

xt_trader.subscribe(self.stock_account)

Expand Down Expand Up @@ -122,8 +101,8 @@ def _fetch_history(self, symbol, period, start_time='', end_time='', count=-1, d
"""
if download:
self.xtdata.download_history_data(stock_code=symbol, period=period, start_time=start_time, end_time=end_time)
res = self.xtdata.get_local_data(stock_list=[symbol], period=period, start_time=start_time, end_time=end_time, count=count, dividend_type=dividend_type)
xtdata.download_history_data(stock_code=symbol, period=period, start_time=start_time, end_time=end_time)
res = xtdata.get_local_data(stock_list=[symbol], period=period, start_time=start_time, end_time=end_time, count=count, dividend_type=dividend_type)
res = res[symbol]
if period == 'tick':
res = self._auto_expand_array_columns(res)
Expand Down

0 comments on commit 5bdab7e

Please sign in to comment.