当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
Detailed explanation of JVM memory model and structure (five model diagrams)
grpc服务发现&负载均衡
arm交叉编译
数字货币永续合约交易所开发开发功能以及代码呈现
Qt——获取文件夹下所有子文件名称
【目标检测】YOLOv5:标签中文显示/自定义颜色
How banner displays drawable images
发光的几何图形canvasjs特效
Regular use in js
js温度计插件自定义数值
离线安装 Anaconda + TensorFlow
CF187C(堆优化BFS)
记录贴:pytorch学习Part4
盘点检索任务中的损失函数
21天学习第五天--数组
The new version of squirrel as source change operation
dp, dpi, px knowledge supplement
CS231n:11 生成模型
CF696C(计数推公式+欧拉降幂)
QT With OpenGL(泛光)(Bloom)









