8
Follow
1369
Followers
マルチロボット市場シェアリングソリューション
Created 2020-07-15 16:25:20 Updated 2024-12-10 10:11:04
4
2634
マルチロボット市場シェアリングソリューション
デジタル通貨定量取引ロボットを使用する場合、複数のロボットがサーバー上で実行され、異なる取引所にアクセスすると、大きな問題は発生せず、API リクエスト頻度の問題も発生しません。複数のロボットを同時に実行する必要があり、それらすべてが同じ取引所と同じ取引ペアに対して定量的な取引戦略を実行している場合。現時点では、API リクエスト頻度制限の問題があります。では、最小限の数のサーバーを使用しながら、複数のロボットがインターフェースにアクセスするという問題を解決するにはどうすればよいでしょうか?
このロボット 1 つだけを使用して、取引所のインターフェースにアクセスし、市場情報やその他のデータを取得できる市場転送ロボットを実装できます。他の取引戦略ロボットは、この市場転送ロボットからデータを要求するだけです。
市場転送ロボットの例
取引所の見積インターフェースにアクセスしてデータを取得し、他のロボットに見積情報を提供する役割のみを果たします。使用Pythonこの例では、K ライン データのみを取得して共有を提供します。これを拡張して、深度データや集計市場データなどを追加できます。
python
import _thread
import threading
import json
import math
from http.server import HTTPServer, BaseHTTPRequestHandler
from urllib.parse import parse_qs, urlparse
Records = None
lock = threading.RLock()
Counter = {}
def url2Dict(url):
query = urlparse(url).query
params = parse_qs(query)
result = {key: params[key][0] for key in params}
return result
class Provider(BaseHTTPRequestHandler):
def do_GET(self):
global Records, lock, Counter
try:
self.send_response(200)
self.send_header("Content-type", "application/json")
self.end_headers()
dictParam = url2Dict(self.path)
# Log("服务接收到请求,self.path:", self.path, "query 参数:", dictParam)
lock.acquire()
# 记录
if dictParam["robotId"] not in Counter:
Counter[dictParam["robotId"]] = {"NumberOfRequests" : 0}
Counter[dictParam["robotId"]]["NumberOfRequests"] += 1
lock.release()
# 写入数据应答
self.wfile.write(json.dumps(Records).encode())
except BaseException as e:
Log("Provider do_GET error, e:", e)
def createServer(host):
try:
server = HTTPServer(host, Provider)
Log("Starting server, listen at: %s:%s" % host)
server.serve_forever()
except BaseException as e:
Log("createServer error, e:", e)
raise Exception("stop")
def main():
global Records, Counter
LogReset(1)
try:
# _thread.start_new_thread(createServer, (("localhost", 9090), )) # 本机测试
_thread.start_new_thread(createServer, (("0.0.0.0", 9090), )) # VPS服务器上测试
Log("启动服务", "#FF0000")
except BaseException as e:
Log("启动服务失败!")
Log("错误信息:", e)
raise Exception("stop")
while True:
r = exchange.GetRecords()
if not r :
Log("K线行情获取失败", "#FF0000")
continue
else :
Records = r
# Counter
tbl = {
"type" : "table",
"title" : "统计信息",
"cols" : ["请求数据的机器人id", "请求次数"],
"rows" : [],
}
for k in Counter:
tbl["rows"].append([k, Counter[k]["NumberOfRequests"]])
LogStatus(_D(), "数据收集中!", "\n", "`" + json.dumps(tbl) + "`")
Sleep(500)
データロボット戦略コードを要求する
データを要求するロボットは、トレーディング戦略ロボットです。ただし、テスト目的のため、要求されたデータ (K ライン データ) の書き込みとデータの描画のみを行います。JavaScript絵を描くには、「線画ライブラリ」を確認する必要があります。このライブラリは戦略広場で検索してコピーできます。コピー後は戦略編集ページのテンプレート参照欄で確認できます。
javascript
var FuncGetRecords = exchange.GetRecords
exchange.GetRecords = function() {
// 可以填写「行情转发机器人」所在设备的IP地址xxx.xxx.xxx.xxx
var ret = HttpQuery("http://xxx.xxx.xxx.xxx:9090?robotId=" + _G())
var records = null
try {
records = JSON.parse(ret)
} catch(e) {
Log(e)
records = null
}
return records
}
function main(){
LogReset(1)
while(1) {
var records = exchange.GetRecords()
LogStatus(_D(), "机器人ID:", _G())
if (!records) {
Log("获取数据失败!", "#FF0000")
Sleep(1000)
continue
}
Log(records)
$.PlotRecords(records, "K")
Sleep(1000)
}
}
実際の運用
このようにして、3 台または N 台のロボットが特定の取引ペアの K ライン データを共有できます。
これは単なる出発点に過ぎません。ぜひメッセージを残してください。
Related Recommendations
Robot WeChat message push implementation schemeGraphical Martingale Trading StrategyPython version iceberg commission strategyThe Logic of Crypto Currency Futures TradingBottom shape ZDZB strategySolution of numerical calculation accuracy problem in JavaScript strategy designTeach you to encapsulate a Python strategy into a local fileFMEX trading unlocks the optimal order volume optimization Part 2FMEX trading unlocks the optimal order volume optimizationAnalysis and Realization of Commodity Futures Volume Footprint Chart
Comment
All comments (2)
- 1






