当前位置:网站首页>Multi robot market share solution
Multi robot market share solution
2020-11-06 20:21:00 【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]所创,转载请带上原文链接,感谢
边栏推荐
- (1) ASP.NET Introduction to core3.1 Ocelot
- C#和C/C++混合编程系列5-内存管理之GC协同
- 【自学unity2d传奇游戏开发】如何让角色动起来
- 【:: 是什么语法?】
- How to turn data into assets? Attracting data scientists
- Swagger 3.0 brushes the screen every day. Does it really smell good?
- It is really necessary to build a distributed ID generation service
- Jmeter——ForEach Controller&Loop Controller
- Live broadcast preview | micro service architecture Learning Series live broadcast phase 3
- The difference between gbdt and XGB, and the mathematical derivation of gradient descent method and Newton method
猜你喜欢
Discussion on the technical scheme of text de duplication (1)
The AI method put forward by China has more and more influence. Tianda et al. Mined the development law of AI from a large number of literatures
JVM内存分配 -Xms128m -Xmx512m -XX:PermSize=128m -XX:MaxPermSize=512m
给字节的学姐讲如何准备“系统设计面试”
With the advent of tensorflow 2.0, can pytoch still shake the status of big brother?
FastThreadLocal 是什么鬼?吊打 ThreadLocal 的存在!!
It's time for your financial report to change to a more advanced style -- financial analysis cockpit
For a while, a dynamic thread pool was created, and the source code was put into GitHub
事务的隔离级别与所带来的问题
用一个例子理解JS函数的底层处理机制
随机推荐
Markdown tricks
Analysis of partial source codes of qthread
Introduction to X Window System
Xmppmini project details: step by step from the principle of practical XMPP technology development 4. String decoding secrets and message package
一篇文章教会你使用Python网络爬虫下载酷狗音乐
【自学unity2d传奇游戏开发】如何让角色动起来
For a while, a dynamic thread pool was created, and the source code was put into GitHub
零基础打造一款属于自己的网页搜索引擎
Python saves the list data
Electron application uses electronic builder and electronic updater to realize automatic update
Basic usage of GDB debugging
JVM内存分配 -Xms128m -Xmx512m -XX:PermSize=128m -XX:MaxPermSize=512m
Using NLP and ml to extract and construct web data
理解格式化原理
How to hide part of barcode text in barcode generation software
C + + and C + + programmers are about to be eliminated from the market
The dynamic thread pool in Kitty supports Nacos and Apollo multi configuration centers
React design pattern: in depth understanding of react & Redux principle
美团内部讲座|周烜:华东师范大学的数据库系统研究
前端未來趨勢之原生API:Web Components