股票期货数据接口常见的代码介绍

Connor 元宇宙概念股 2022-10-20 253 0

我们在自己设计股票期货数据接口时,少不了要用到一些代码,今日我们就来介绍几个比较常见的代码,希望能对各位投资者有帮助。

众所周知,虽然期货交易是证券交易的其中一种方式,但当中有很多交易模式和术语跟股票交易是很不一样的,正因如此,股票期货数据接口的编程也会跟股票交易接口不一样,下面就先来给大家介绍几个期货交易过程中比较常用的几组代码:

#点击合约资料

pyautogui.click(x=969,y=51)

#信息截图

time.sleep(1)

#点击结算套保

pyautogui.click(x=1343,y=151)

time.sleep(1)

pyautogui.screenshot(r'C:\Users\Administrator\Desktop\期货交易\结算套保.png',region=(553,293,1671-553,639-293))

options={'language':'chn_eng'}

aipcor=AipOcr(app_id,api_key,secret_key)

image=open(r'C:\Users\Administrator\Desktop\期货交易\结算套保.png','rb')

image1=image.read()

text_list=aipcor.general(image1,options=options)

展开全文

df1=pd.json_normalize(text_list['words_result'])

df1.to_excel(r'C:\Users\Administrator\Desktop\期货交易\结算套保.xlsx')

df=pd.read_excel(r'C:\Users\Administrator\Desktop\期货交易\结算套保.xlsx')

#将提取的数据处理成表格数据

df_words=df['words'][10:]

date=[]

price=[]

buy_ratio_tj=[]

buy_ratio_trader=[]

sell_ratio_tj=[]

sell_ratio_trader=[]

for i in range(0,len(df_words.tolist()),6):

date.append(df_words.tolist()[i])

price.append(df_words.tolist()[i+1])

buy_ratio_tj.append(df_words.tolist()[i+2])

buy_ratio_trader.append(df_words.tolist()[i+3])

sell_ratio_tj.append(df_words.tolist()[i+4])

sell_ratio_trader.append(df_words.tolist()[i+5])

now_df=pd.DataFrame({'时间':date,'结算价格':price,'买入投机比例':buy_ratio_tj,'买入交易比例':buy_ratio_trader,

'卖出投资比例':sell_ratio_tj,'卖出交易比例':sell_ratio_trader})

print(now_df)

now_df.to_excel(r'C:\Users\Administrator\Desktop\期货交易\结算套保.xlsx')

pyttsx3.speak('期货结算套保数据提取成功')

总的来说,股票期货数据接口虽然可以帮助我们更好地进行期货量化交易,但并不代码有了这套工具我们就一定能赚钱,很多时候,工具再好,人的思维不转变,也是很难有好多成果的。

评论