現(xiàn)貨合約跟單交易所系統(tǒng)開發(fā)技術(shù)詳細(對接API火幣/幣安OK/歐易)案例分析/方案源碼
合約量化系統(tǒng)是一種自動化交易工具,它通過計算機程序?qū)崿F(xiàn)交易決策和執(zhí)行。
合約量化系統(tǒng)的工作原理如下:
1.Traders send trading instructions to the contract quantification system through the front-end interface,包括交易品種、交易數(shù)量、交易時間等信息。
2.After receiving trading instructions from traders,the contract quantification system will analyze and verify the trading instructions.If the trading instructions comply with regulations,the contract quantification system will execute the transaction.
3.合約量化系統(tǒng)會通過區(qū)塊鏈網(wǎng)絡(luò)接收交易數(shù)據(jù),并對交易數(shù)據(jù)進行驗證和計算。
4.The contract quantification system will,based on trading strategies and risk management rules,對交易數(shù)據(jù)進行分析和決策。
5.如果交易策略生效,合約量化系統(tǒng)將會執(zhí)行交易,And provide feedback on the trading results to the traders.
import os
import pandas as pd
import tushare as ts
import numpy as np
from pathlib import Path
import matplotlib.pyplot as plt
import mplfinance as mpf
import matplotlib as mpl
from cycler import cycler#用于定制線條顏色
import time
def dividend(ts_code):
df=pro.dividend(ts_code=ts_code)
df.to_csv('dividend.csv',encoding='utf_8_sig')
def draw_finance(ts_codes,begin_count,end_count=-1):
df=load_data(ts_codes)
fig=plt.figure()
ax=fig.add_subplot(111)
opens=df['open'].values[begin_count:end_count]
closes=df['close'].values[begin_count:end_count]
highs=df['high'].values[begin_count:end_count]
lows=df['low'].values[begin_count:end_count]
dates=df['trade_date'].values[begin_count:end_count]
vols=df['vol'].values[begin_count:end_count]
data=[dates,opens,closes,highs,lows,vols]
data=np.transpose(data)#矩陣轉(zhuǎn)置
df=pd.DataFrame(data,columns=['Date','Open','Close','High','Low','Volume'])
df['Date']=pd.to_datetime(df['Date'])
df.set_index(['Date'],inplace=True)
#df.index.name='Date'
#設(shè)置基本參數(shù)
#type:繪制圖形的類型,有candle,renko,ohlc,line等
#此處選擇candle,即K線圖
#mav(moving average):均線類型,此處設(shè)置7,30,60日線
#volume:布爾類型,設(shè)置是否顯示成交量,默認False
#title:設(shè)置標(biāo)題
#y_label:設(shè)置縱軸主標(biāo)題
#y_label_lower:設(shè)置成交量圖一欄的標(biāo)題
#figratio:設(shè)置圖形縱橫比
#figscale:設(shè)置圖形尺寸(數(shù)值越大圖像質(zhì)量越高)
kwargs=dict(
type='candle',
mav=(5,10,20),
volume=True,
title='nA_stock%s candle_line'%(ts_codes),
ylabel='OHLC Candles',
ylabel_lower='SharesnTraded Volume',
figratio=(50,30),
figscale=15)