增加交易策略、交易指标、量化库代码等文件夹

This commit is contained in:
Win_home
2025-04-27 15:54:09 +08:00
parent ca3b209096
commit f57150dae8
589 changed files with 854346 additions and 1757 deletions

View File

@@ -11,10 +11,10 @@ GetOrderFlow_dj(kData): 计算订单流的信号指标。
from multiprocessing import Process, Queue
import queue
import threading
from AlgoPlus.CTP.MdApi import run_tick_engine
from AlgoPlus.CTP.FutureAccount import get_simulate_account
from AlgoPlus.CTP.FutureAccount import FutureAccount
from AlgoPlus.CTP.TraderApiBase import TraderApiBase
from vnpy.trader.object import TickData, OrderData, TradeData
from vnpy.trader.constant import Exchange, Direction, Offset, OrderType
from vnpy.trader.engine import MainEngine
from vnpy_ctp import CtpGateway
# from AlgoPlus.ta.time_bar import tick_to_bar
import pandas as pd
@@ -202,7 +202,73 @@ class ParamObj:
self.周期 = 周期
class MyTrader(TraderApiBase):
class MyTrader:
def __init__(self, main_engine, symbol, exchange):
self.main_engine = main_engine
self.symbol = symbol
self.exchange = exchange
self.param_dict = {}
self.queue_dict = {}
self.品种 = " "
self.tick_subscribed = False
self.last_tick = None
self.previous_volume = 0
def subscribe_tick(self):
if not self.tick_subscribed:
req = self.main_engine.get_gateway("CTP").subscribe(
[
{
"symbol": self.symbol,
"exchange": self.exchange
}
]
)
self.tick_subscribed = True
def on_tick(self, tick: TickData):
if self.last_tick is not None:
last_volume = tick.volume - self.last_tick.volume
else:
last_volume = 0
self.last_tick = tick
if last_volume == 0:
return
tick_dict = {
"symbol": tick.symbol,
"created_at": tick.datetime,
"price": tick.last_price,
"last_volume": last_volume,
"bid_p": tick.bid_price_1,
"bid_v": tick.bid_volume_1,
"ask_p": tick.ask_price_1,
"ask_v": tick.ask_volume_1,
"UpperLimitPrice": tick.upper_limit,
"LowerLimitPrice": tick.lower_limit,
"TradingDay": tick.trading_day,
"cum_volume": tick.volume,
"cum_amount": tick.turnover,
"cum_position": tick.open_interest,
}
self.process_tick(tick_dict)
def process_tick(self, tick):
# 这里可复用原有的tick处理逻辑
pass
def send_order(self, price, volume, direction, offset):
order_req = {
"symbol": self.symbol,
"exchange": self.exchange,
"direction": direction,
"offset": offset,
"price": price,
"volume": volume,
"order_type": OrderType.LIMIT,
}
self.main_engine.send_order(order_req, "CTP")
# 其他原有方法可继续保留适配vnpy数据结构
def __init__(
self,