当前位置:网站首页>Multi robot market share solution
Multi robot market share solution
2020-11-06 20:21:54 【Inventor quantification】
Multi robot market sharing solution
When trading digital money, use robots , When you have to run multiple robots on a server , If you visit different exchanges , It's not a big problem at this time , There will be no API The frequency of requests . If you need to have multiple robots running at the same time , And they all do the same exchange , The quantitative trading strategy of the same trading pair . At this time there is API The request frequency limit problem . How to use the least number of server interfaces to solve the problem ?
We can implement a market forwarding robot , Access to the exchange interface to obtain market data and other data, only this robot to complete . Other trading strategy robots forward robot request data to this market .
Quote forwarding robot example
Only responsible for accessing the exchange market interface to obtain data , And offer other robots a market . Use Python
To write , In the example, we only get K Line data , And provide sharing , Can be expanded to increase depth data , Aggregate market data, etc .
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(" The service received the request ,self.path:", self.path, "query Parameters :", dictParam)
lock.acquire()
# Record
if dictParam["robotId"] not in Counter:
Counter[dictParam["robotId"]] = {"NumberOfRequests" : 0}
Counter[dictParam["robotId"]]["NumberOfRequests"] += 1
lock.release()
# Write data response
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), )) # Native test
_thread.start_new_thread(createServer, (("0.0.0.0", 9090), )) # VPS Test on server
Log(" Start the service ", "#FF0000")
except BaseException as e:
Log(" Failed to start service !")
Log(" error message :", e)
raise Exception("stop")
while True:
r = exchange.GetRecords()
if not r :
Log("K Line market acquisition failed ", "#FF0000")
continue
else :
Records = r
# Counter
tbl = {
"type" : "table",
"title" : " Statistics ",
"cols" : [" Robots that request data id", " Number of requests "],
"rows" : [],
}
for k in Counter:
tbl["rows"].append([k, Counter[k]["NumberOfRequests"]])
LogStatus(_D(), " Data collection !", "\n", "`" + json.dumps(tbl) + "`")
Sleep(500)
Request data robot policy code
The robot that requests data is the trading strategy robot , It's just that we use , Write only the request data (K Line data ) And draw the data , It can be used JavaScript
To write , For drawing , You need to check 「 Draw line class library 」 You can search and copy this library in strategy square , After copying, you can check the column of template reference in the policy editing page .
var FuncGetRecords = exchange.GetRecords
exchange.GetRecords = function() {
// Can be filled in 「 Market forwarding robot 」 Of the device IP Address 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(), " robot ID:", _G())
if (!records) {
Log(" Failed to get data !", "#FF0000")
Sleep(1000)
continue
}
Log(records)
$.PlotRecords(records, "K")
Sleep(1000)
}
}
Actual operation
-
Start the market forwarding robot
-
Start the test robot ,ID:206353
-
Start the test robot ,ID:206359
-
Start the test robot ,ID:206360
In this way, three or even N A robot for a deal for K Sharing of line data .
throw away a brick in order to get a gem , Welcome to leave a message .
版权声明
本文为[Inventor quantification]所创,转载请带上原文链接,感谢
边栏推荐
- C++ 数字、string和char*的转换
- C++学习——centos7上部署C++开发环境
- C++学习——一步步学会写Makefile
- C++学习——临时对象的产生与优化
- C++学习——对象的引用的用法
- C++编程经验(6):使用C++风格的类型转换
- Won the CKA + CKS certificate with the highest gold content in kubernetes in 31 days!
- C + + number, string and char * conversion
- C + + Learning -- capacity() and resize() in C + +
- C + + Learning -- about code performance optimization
猜你喜欢
-
C + + programming experience (6): using C + + style type conversion
-
Latest party and government work report ppt - Park ppt
-
在线身份证号码提取生日工具
-
Online ID number extraction birthday tool
-
️野指针?悬空指针?️ 一文带你搞懂!
-
Field pointer? Dangling pointer? This article will help you understand!
-
HCNA Routing&Switching之GVRP
-
GVRP of hcna Routing & Switching
-
Seq2Seq实现闲聊机器人
-
【闲聊机器人】seq2seq模型的原理
随机推荐
- LeetCode 91. 解码方法
- Seq2seq implements chat robot
- [chat robot] principle of seq2seq model
- Leetcode 91. Decoding method
- HCNA Routing&Switching之GVRP
- GVRP of hcna Routing & Switching
- HDU7016 Random Walk 2
- [Code+#1]Yazid 的新生舞会
- CF1548C The Three Little Pigs
- HDU7033 Typing Contest
- HDU7016 Random Walk 2
- [code + 1] Yazid's freshman ball
- CF1548C The Three Little Pigs
- HDU7033 Typing Contest
- Qt Creator 自动补齐变慢的解决
- HALCON 20.11:如何处理标定助手品质问题
- HALCON 20.11:标定助手使用注意事项
- Solution of QT creator's automatic replenishment slowing down
- Halcon 20.11: how to deal with the quality problem of calibration assistant
- Halcon 20.11: precautions for use of calibration assistant
- “十大科学技术问题”揭晓!|青年科学家50²论坛
- "Top ten scientific and technological issues" announced| Young scientists 50 ² forum
- 求反转链表
- Reverse linked list
- js的数据类型
- JS data type
- 记一次文件读写遇到的bug
- Remember the bug encountered in reading and writing a file
- 单例模式
- Singleton mode
- 在这个 N 多编程语言争霸的世界,C++ 究竟还有没有未来?
- In this world of N programming languages, is there a future for C + +?
- es6模板字符
- js Promise
- js 数组方法 回顾
- ES6 template characters
- js Promise
- JS array method review
- 【Golang】️走进 Go 语言️ 第一课 Hello World
- [golang] go into go language lesson 1 Hello World