当前位置:网站首页>Digital currency perpetual contract exchange development and development functions and code presentation
Digital currency perpetual contract exchange development and development functions and code presentation
2022-08-08 17:48:00 【User I34I63353I9】
The development of the digital currency exchange system, as the name implies, is a place or platform for certain information and item transactions, etc. The digital currency spot option contract exchange needs a fixed place or platform called an exchange.The digital asset exchange is to use the information platform to realize the sharing of property rights information, remote transactions, and unified coordination.
What are the functions of digital asset trading system development?
1. A real blockchain interface that supports multiple virtual coins, as well as the outbound management of Taiwan dollars.
2. Currency transactions, multi-virtual currency exchange transactions, real-time K-line market quotations, entrusted transactions, market price transactions
3. Over-the-counter transactions, different buyers and sellers can conduct transactions through this platform, and legal coins can be exchanged for virtual coins.
4. Wallet function, multiple virtual currency in and out, lock release, candy delivery, etc.
5. Security management, ensuring asset security from programs, databases, servers, blockchain interfaces, hot and cold wallet management, double-layer encryption, etc.
The exchange matching engine needs to meet the following three requirements:
1. Powerful to abnormal performance: The larger the scale of the exchange, the more concurrent transactions, and the performance of the matching engine directly restricts the development of the exchange business.
2. A variety of order types are fully compatible: commonly used order types include limit orders, market orders, take-profit and stop-loss orders, etc.
3. Contract function support: In the current exchange industry, contract trading has almost become a necessary function, and the implementation of contract matching is much more complicated than spot, and the technical requirements will be higher.
huobipro=ccxt.huobipro({
'apiKey':'',
'secret':'',
})
First use ccxt to obtain the instance of the exchange, then obtain the historical K-line, and the obtained data is accepted in the dataframe format
huobipro.fetch_ohlcv(symbol=symbol,limit=limit_num,timeframe=timeframe)
Then use the function provided by pandas to calculate MA,
df['median_short']=df['close'].rolling(n_short,min_periods=1).mean()
df['median_long']=df['close'].rolling(n_long,min_periods=1).mean()
Then look for buy and sell signals,
#Find a buy signal
condition1=df['median_short']>df['median_long']#The short moving average crosses the long moving average
condition2=df['median_short'].shift(1)<=df['median_long'].shift(1)
df.loc[condition1&condition2,'signal']=1#The K line that generates the buy signal is marked as 1
#Find a sell signal
condition1=df['median_short'] condition2=df['median_short'].shift(1)>=df['median_long'].shift(1) df.loc[condition1&condition2,'signal']=0#The K line that generates the sell signal is marked as 0 With the trading signal, you can get the signal, and then judge to place an order (huobipro.create_limit_buy/sell_order()) Step 5: In fact, the fourth step is to trade, and the fifth step is backtesting. Generally speaking, backtesting is performed first, and then a strategy is selected according to the backtesting results, and finally the real market is carried out There are many kinds of back-testing analysis, and I don't know much about it. At present, I am still used to using accumulated profits for analysis. #Calculate the actual daily position by signal df['pos']=df['signal'].shift() df['pos'].fillna(method='ffill',inplace=True) df['pos'].fillna(value=0,inplace=True) Here, the position signal is available, and the accumulated profit can be calculated according to the position and the price of the historical K-line. df['change']=df['close'].pct_change(1)#Calculate the change according to the closing price df['by_at_open_change']=df['close']/df['open']-1#The change from opening to closing df['sell_next_open_change']=df['open'].shift(-1)/df['close']-1#The change from the close of this root to the opening of the next root df.at[len(df)-1,'sell_next_open_change']=0#Complete the empty value df.at[4,'B'] #Select opening conditions condition1=df['pos']==1 condition2=df['pos']!=df['pos'].shift(1) open_pos_condition=condition1&condition2 #Select closing conditions condition1=df['pos']==0 condition2=df['pos']!=df['pos'].shift(1) close_pos_condition=condition1&condition2 #Group each transaction df.loc[open_pos_condition,'start_time']=df['open_time'] df['start_time'].fillna(method='ffill',inplace=True) df.loc[df['pos']==0,'start_time']=pd.NaT init_cash=1000#initial capital #Calculate position changes #Position when opening a position df.loc[open_pos_condition,'position']=init_cash*(1+df['by_at_open_change']) group_num=len(df.groupby('start_time')) if group_num>1: temp=df.groupby('start_time').apply(lambda x:x['close']/x.iloc[0]['close']*x.iloc[0]['position']) temp=temp.reset_index(level=[0]) df['position']=temp['close'] df['position_max']=df['position']*df['high']/df['close'] df['position_min']=df['position']*df['low']/df['close'] ##Position when closing the position #df.loc[close_pos_condition,'position']*=(1+df.loc[close_pos_condition,'sell_next_open_change']) #Calculate position profit df['porfit']=(df['position']-init_cash)*df['pos']#Position profit or loss #df.loc[df['pos']==1,'porfit_min']=(df['position_min']-init_cash)*df['pos']#minimum position profit or loss #df.loc[df['pos']==0,'porfit_max']=(df['position_max']-init_cash)*df['pos'] #Calculate the actual amount of funds df['cash']=init_cash+df['porfit']#actual funds #Calculate the capital curve df['equity_change']=df['cash'].pct_change() #Open day rate of return df.loc[open_pos_condition,'equity_change']=df.loc[open_pos_condition,'cash']/init_cash-1 df['equity_change'].fillna(value=0,inplace=True) df['equity_curve']=(1+df['equity_change']).cumprod() df['equity_curve']=df['equity_curve']*init_cash
边栏推荐
猜你喜欢
随机推荐
CF803F(容斥原理+莫比乌斯函数)
多线程之不可变对象
Debug和Release的区别
Reprinted, the fragment speaks very well, the big guy
记录贴:pytorch学习Part5
XDOJ - count the number of positive integers
js切换新闻列表样式
21天学习第五天--数组
【目标检测】YOLOv5:标签中文显示/自定义颜色
vlan同步—VTP通告
【目标检测】小脚本:根据xml批量复制jpg图片
差分信号简述
比较器是否可以当做运放使用?
21天学习第三天--常用运算符
史上最强IDEA工具使用教程,你想要的全都有!
目标检测、目标跟踪、图像分类最新进展
【FPGA教程案例45】图像案例5——基于FPGA的图像均值滤波verilog实现,通过MATLAB进行辅助验证
poj1961 Period(KMP)
@Transactional
KITTI数据集简介(一)—— 传感器介绍