证券同花顺股票交易接口是实现自动量化交易重要系统之一,主要是指在证券市场中,通过对交易资金及交易报价等数据进行批量比对后,分别找出资金数据及价格数据的运作规律,并根据这种规律进行投资交易。那么,同花顺股票交易接口怎样执行挂单程序?
import numpy as np
import pandas as pd
# 同花顺股票交易接口支持期货策略类,包括开仓、买入、止盈、止损方法与策略执行主函数
class StockStrategy:
df = None
open_offset_num = 5
buy_in_offset_num = 0
stop_win_offset_num = 0
stop_lose_num = 0
price_list = []
price_stop_lose = []
flag_buy_in = False
need_sell_out = False
stop_lose_rate = 3
# 初始化策略类StockStrategy
def __init__(self, df: pd.DataFrame) -> None:
self.df = df
# 设置止损模块,止损比例
def set_stop_lose_rate(self, slr) -> None:
self.stop_lose_rate = slr
# 设置偏移量: 开仓偏移、买入偏移和止盈偏移,如需修改止损量,需重写set_stop_lose_num(self, date)方法
def set_offset_num(self, oon: int, bion: int, swon: int) -> None:
if oon is not None:
self.open_offset_num = oon # 开仓偏移量
if bion is not None:
self.buy_in_offset_num = bion # 买入偏移量
if swon is not None:
self.stop_win_offset_num = swon # 卖出偏移量
# 返回买卖结果
def get_buy_sell_list(self) -> list:
return self.stock_strategy_main()
# 准备开仓模块
def strategy_open(self, i) -> bool:
df = self.df
if df['hl'][i] <= (df['支撑线'][i] + self.open_offset_num):
return True
else:
return False
# 买入策略模块
def strategy_buy_in(self, i) -> bool:
df = self.df
if df['hl'][i] >= (df['阻力线'][i] + self.buy_in_offset_num):
return True
else:
return False