Introduction to common codes for stock and futures data interfaces

When we design our own stock and futures data interface, we inevitably need to use some codes. Today we will introduce a few common codes, hoping to be helpful to all investors.

As we all know, although futures trading is one of the ways of securities trading, many of the trading models and terms are very different from stock trading. Because of this, the programming of the stock futures data interface will also be different from the stock trading interface. Let me first introduce to you a few sets of codes that are commonly used in futures trading:

    #Click on the contract information

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

    #Information screenshot

    time.sleep(1)

    #Click settlement hedging

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

    time.sleep(1)

    pyautogui.screenshot(r'C:\Users\Administrator\Desktop\Futures Trading\Settlement Hedging.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\Futures Trading\Settlement Hedging.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\Futures Trading\Settlement Hedging.xlsx')

    df=pd.read_excel(r'C:\Users\Administrator\Desktop\Futures Trading\Settlement Hedging.xlsx')

    #Process the extracted data into table data

    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({'Time':date,'Settlement price':price,'Buy speculation ratio':buy_ratio_tj,'Buy transaction ratio':buy_ratio_trader,

    'Sell investment ratio':sell_ratio_tj,'Sell transaction ratio':sell_ratio_trader})

    print(now_df)

    now_df.to_excel(r'C:\Users\Administrator\Desktop\Futures Trading\Settlement Hedging.xlsx')

    pyttsx3.speak('Futures settlement hedging data extraction successful')

In general, although the stock and futures data interface can help us better conduct quantitative futures trading, it does not necessarily mean that we can make money with this set of tools. In many cases, no matter how good the tools are, people’s thinking does not change. It is difficult to achieve many results.

Guess you like

Origin blog.csdn.net/QQ2037696191/article/details/126969081