当前位置:网站首页>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
边栏推荐
猜你喜欢
Vscode LeetCode 教程
高维前缀和和子集dp(状压dp的一种)
Cyanine5 tetrazine,Cy5 tetrazineCY5四嗪,1427705-31-4
开源一夏 | 疫情期间闲来无事,我自制了一个按钮展示框特效来展示我的博客
CF1716D(“按顺序“的完全背包)
什么是服务网格?在微服务体系中又是如何使用的?
2 prerequisites for the success of "digital transformation" of enterprises!
发光的几何图形canvasjs特效
超越CLIP的多模态模型,只需不到1%的训练数据!南加大最新研究来了
为什么MySQL的主键查询这么快
随机推荐
软件测试的价值
基于simulink的风力机房温度控制系统仿真
中金证券股票开户流程是什么,我需要准备身份证吗,安全吗
arxiv国内镜像——快速下载
C语言中变量在内存中的保存与访问
MySQL中怎么对varchar类型排序问题
前缀和的本质
章节小测一
【CC3200AI 实验教程4】疯壳·AI语音人脸识别(会议记录仪/人脸打卡机)-GPIO
Cyanine5 tetrazine,Cy5 tetrazineCY5四嗪,1427705-31-4
用皮肤“听”音乐,网友戴上这款装备听音乐会:仿佛住在钢琴里
Cuda Anaconda tensorflow 版本对应
How big is 1dp!
钱放在股票账户安全吧?
JVM内存模型和结构详解(五大模型图解)
The difference between rv and sv
多线程之不可变对象
【目标检测】YOLOv5:标签中文显示/自定义颜色
C人脸识别
开源一夏 | RuntimeException 子类