Nowadays, many traders choose between quantitative investment and traditional stock trading, and they often choose automated trading and quantitative trading. After all, many trading software that can be developed now have quantitative characteristics and can grasp more in time. Profit opportunities, such as the commonly used Datongdaxin trading dll interface is an example. Through the Tongdaxin interface to transmit your own trading strategy, you can modify your own dll in the interface to call to realize programmatic transactions. Then, specifically, it is How?
Specifically:
Put the three files MetaTrade.dll, MetaTrade.lic, and MetaTrade.ini in the same directory as the application
-
- Call LoadLibrary to load MetaTrade.dll instance
- Call GetProcAddress to get the API function address
- Call the Init interface for API initialization
- Call the Logon interface to log in to the brokerage account and obtain the corresponding ClientId. One application instance can log in to multiple accounts at the same time
- Call other API interfaces through ClientId to query or place an order
- Call the Logoff interface to log out of the brokerage account
- Call the Deinit interface to clean up the API
- Call FreeLibrary to unload MetaTrade.dll instance
If the Tongdaxin transaction dll interface wants to automatically entrust orders through a piece of code, it needs the stock api transaction interface , and uses the various parameter functions of the interface to automatically place orders:
name |
Features |
|
basic function |
Heat |
|
Deinit |
||
Logon |
||
logoff |
||
QueryData |
||
QueryHistoryData |
||
SendOrder |
||
CancelOrder |
||
GetQuote |
||
Repay |
||
GetExpireDate |
||
Single Account Batch Function |
QueryDatas |
|
SendOrders |
||
CancelOrders |
||
GetQuotes |
||
Multi-account batch function |
QueryMultiAccountsDatas |
|
SendMultiAccountsOrders |
||
CancelMultiAccountsOrders |
||
GetMultiAccountsQuotes |
Code example:
import requests;
import time;
import json;
import pandas as pd;
def fenshishuju_dfcf(daima);
//Here we need to define an array to distinguish them, make the printing results more detailed, realize the real-time data captured by the stock trading interface in detail, and print them out accurately;
if daima[:2] == "sh" :
lsbl = '1.'+daima[2:]
else:
lsbl = '0.' + daima[2:]
wangzhi = "http://push2his.eastmoney.com/api/qt/stock/trends2/get? &fields1=f1%2Cf2%2Cf3%2Cf4%2Cf5%2Cf6%2Cf7%2Cf8%2Cf9" \
"%2Cf10%2Cf11%2Cf12%2Cf13&fields2=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cfut58&
" =7eea3edcaed734bea9cbfc24409ed989&ndays=1&iscr=0&secid="+lsbl+ \
"&_=1643253749790"+str(time.time)
resp = requests.get(wangzhi, timeout=6)
# print (resp)
#Print the status code of the request result
data = json.loads(resp.text)
shuju = {'date and time': [], 'latest price': [], 'average price': [], 'turnover': [ ]}
for k in data['data']['trends']:
lsbl = k.split(",")
shuju['date and time'].append(lsbl[0])
shuju['latest price']. append(lsbl[2])
shuju['average price'].append(lsbl[-1])
shuju['turnover'].append(lsbl[-2])
shuju = pd.DataFrame(shuju)
print(shuju )
return shuju
if __name__ == '__main__':
while 1:
fenshishuju_dfcf('sh603102')
time.sleep(3)
return{
}
Position data display:
Therefore, the parameter function invoked by Tongdaxin trading dll interface can accurately execute the trader's quantitative strategy, timely customize the entrustment and place an order, and realize programmatic trading.