4
Follow
15
Followers
以前,他の人のために代写したことがあるので,多くの友人が状況監視策を実行し,特殊な状況が発生するとすぐに警報を出すことを発見しましたが,常にリールディスクを起動していることに満足していません.
ps: python が使われていますが, サーバーの配置はここで説明しません.
A. 準備する
- コントロールパネル
ここでは,ファイルをサーバーにアップロードする目的でポータルパネルを使用していますが,もちろん,他の方法も使用できます. 経路を覚えておいてください. (作者のサーバーはUbuntuシステムなので,以下のすべてのコマンドはこれを準用して,他のシステムコマンドは自分で閲覧できます)
- ダウンロード
wget -O install.sh http://download.bt.cn/install/install-ubuntu_6.0.sh && sudo bash install.sh
完了するとアドレスが取得され,ログインします (アドレスが開かない場合はポート8888を開きます).
- Screen
screen は,ターミナルshh の接続後でもプログラムを実行できるようにするための,Linux のウィンドウの重複管理プログラムである.
- ダウンロード
sudo apt-get install screen
- 通常の命令
スクリーンを起動し,パスを起動し,ファイルを起動します.[[name]のタグは自分で設定できます.
screen -S [name]
スクリーンショートキーから退く
ctrl+a+d
スクリーンが背景で動いていることを確認する
screen -ls
プロセス終了 (pid番号はプロセスで確認できます)
kill -9 [pid号]
スクリーンで死んだプロセスの情報をクリアする
screen -wipe
- 釘の設定
Hukybo大<unk>の記事に引用して,原理の実装は説明されず,簡潔なパッケージコードのみが示され,参考にのみ.
https://www.fmz.com/digest-topic/5840
# 钉钉输出接口
class DING:
# 向钉钉群输出信息
def msg(self,text):
token ="***"
headers = {'Content-Type': 'application/json;charset=utf-8'} # 请求头
api_url = f"***={token}"
json_text = {
"msgtype": "text", # 信息格式
"text": {
"content": text
}
}
# 发送并打印信息
requests.post(api_url, json.dumps(json_text), headers=headers).content
#拼接输出信息
def dd(self,logging):
bj_dt = str(datetime.datetime.now())
bj_dt = bj_dt.split('.')[0] # 处理时间
text = f'{bj_dt}\n' # 定义信息内容
text = text + logging # 处理信息内容
log.msg(text) # 调用msg函数,输出信息
2. コード実装
取引は,Binance api を介して取得され,U本位契約のfapi インターフェースが使用されます.以下のコードは,Binance api を簡単に包装し,参照のみです.
import requests,json,time,hmac,hashlib,datetime
# APIKEY填写位置
apikey = '***'
Secret_KEY = '***'
#币安接口
class bian:
#拼接请求参数
def param2string(self,param):
s = ''
for k in param.keys():
s += k
s += '='
s += str(param[k])
s += '&'
return s[:-1]
# 参数为get,post请求方式,路径,body
def IO(self,method,request_path,body):
header = {
'X-MBX-APIKEY': apikey,
}
#选择请求方式
if body != '':
#签名
body['signature'] = hmac.new(Secret_KEY.encode('utf-8'), self.param2string(body).encode('utf-8'), hashlib.sha256).hexdigest()
if method == 'GET':
body = self.param2string(body)
tell = 'https://fapi.binance.com{0}?{1}'.format(request_path,body)
response = requests.get(url=tell, headers=header).json()
return response
elif method == 'POST':
response = requests.post(url='https://fapi.binance.com'+str(request_path), headers=header, data=body).json()
return response
else:
response = requests.get(url='https://fapi.binance.com'+str(request_path), headers=header).json()
return response
策略は価格のインターフェースのみを使用しているため,ここでは簡単なデモのみを行います. 他のインターフェースは同様です.
#封装获取价格接口
def price(self,Name):
body = {"symbol":str(Name)}
info = self.IO("GET","/fapi/v1/ticker/price",body)
for i in info:
if i == "code":
#设计一个接口错误容错功能
time.sleep(0.5)
letgo = '调用price函数接口返回错误,再次尝试 返回错误代码:{0}'.format(str(info))
log.dd(str(letgo))
exchange.price(Name)
return info["price"]
監視コードの実装です.
# 监控币种&&监控价格一一对应
ccy = ["BTCUSDT","ETHUSDT","LTCUSDT"]
PriceTIME = ["100000;28000","500000000;1200","500;100"]
#行情监控逻辑
def pricewarm():
#轮询获取当前价格
for i in range(len(PriceTIME)):
info = exchange.price(str(PriceTIME[i]))
priceindex = PriceTIME[i].find(";") #提取价格区间
#价格上限
priceup = PriceTIME[i][:priceindex]
#价格下限
pricedown = PriceTIME[i][priceindex+1:]
if float(info) >= float(priceup): #钉钉接口输出
letgo = f'当前价格{info}USDT大于所设定上限{priceup}USDT'
log.dd(letgo)
elif float(info) <= float(pricedown):
letgo = f'当前价格{info}USDT小于等于设定下限{pricedown}USDT'
log.dd(letgo)
time.sleep(0.2)
# 主函数
def main():
global exchange,log
log = DING
exchange = bian
while True:
try:
pricewarm()
time.sleep(1)
except:
time.sleep(1)
if __name__ == "__main__":
main()
3 運営
コードが完了すると,経路を記憶して,端末実行画面を開きます.
screen -S [名称]
cd [路径]
python3 [文件名]
確認手続きの実行後に退出できます.
政策の住所:簡単に価格を教えてくれるロボット
Related Recommendations
Use the extended API on FMZ Quant to realize "TradingView" alert signal tradingMain Interface Overview and Structure of FMZ Quant Trading PlatformHow to Pend Market orders (Only Passively Traded) and Place Orders in Batch on BitMEX (IO Demo)FMZ Launched Python Local Backtest EngineFMZ Feedback to New and Old Users by AffiliationFMZ Quant Simulation Level Backtest Mechanism DescriptionFMZ Backtest Mechanism DescriptionLinux Docker Installation and Update StepsQuick Start for PythonQuick Start for JavaScript




