0
Perhatian
72
Peminat

Antara muka dengan robot FMZ menggunakan penunjuk "Tradingview"

Dicipta pada: 2020-06-19 11:08:22, Dibaharui pada: 2025-01-14 20:34:25
comments   0
hits   1090

Interfacing with FMZ robot using “Tradingview” indicator

Pengenalan latar belakang

TradingView adalah alat menarik harga pasaran yang baik.

Peraturanpineskrip juga wujud yang kuat!

Pengujian balik, penggera, dan pelbagai penghubung adalah alat kewangan yang sangat lengkap.

Tetapi ada dua isu yang telah menyeksa kita...

  • Satu adalah sistem keahlian yang mahal
  • Yang kedua adalah bahawa terdapat sangat sedikit pertukaran di mana isyarat boleh diperdagangkan secara langsung, ia kelihatan dua atau tiga.

Hari ini artikel kami adalah untuk membawa anda untuk menyelesaikan masalah pertukaran masalah docking.

Pelaksanaan

Idea keseluruhan adalah seperti ini:

TV ((TradingView)pineskrip -> isyarat penggerawebhook-> tempatanwebhook serverpermintaan penyampaian -> FMZ bot menerima permintaan untuk beroperasi

Mari kita pergi langkah demi langkah.

Pergi ke laman web TradingView:

https://www.tradingview.com/

Seterusnya, kita mula-mula menciptaAlert, lihat gambar di bawah untuk butiran

Interfacing with FMZ robot using “Tradingview” indicator

Beberapa aspek dalam gambar perlu memberi perhatian kepada, apabila menjanaAlert.

Tempoh kelayakan,webhookalamat, danmessageKandungan mesti dibuat dengan baik.

Tarikh tamat tempoh, yang ini akan tahu dengan sekilas, dan ia akan menjadi tidak sah apabila ia tamat tempoh...


```Message``` here, it is best we have a clear explanation, in order to let the ```bot``` distinguish from ```Alert``` messages.

I generally set it like this: XXX strategy, order quantity and trading direction

So far, the TradingView part is basically done!

Next, let's get the local ```webhook``` service job done!

This kind of work, Google it will show you lots of results. this article will skip this part, you can do it by yourself.

here is a simple framework for python:

GitHub:https://github.com/shawn-sterling/gitlab-webhook-receiver


Safe, worry-free and convenient, but there are also issues.

This little frame, it will!! Suicide!! Please pay attention to this issue!

So, I wrote another script on the server, When "die" or "offline" appears in the log, I will restart it. later on, i still feel not safe, so i set it restart regularly. Find an unimportant time every hour... Give it a restart, it has been safely running for two months now and there is no more signal losses.

In addition, TradingView only recognizes the port 80, so don't mess up the service port.

So far, We have done the ```Message``` from ```Alert``` part. Next, how do we get Bot?

I don't know if you have paid attention to the interface API document of FMZ at the bottom:

 ![Interfacing with FMZ robot using "Tradingview" indicator](/upload/asset/6e82463afe0dfbc15d96.png) 

We can pass some commands to our little Bot through API!
The specific request example is here, the red box is the request we need.

 ![Interfacing with FMZ robot using "Tradingview" indicator](/upload/asset/6e8cc24e284428b14724.png) 

Here also needs some preparation work.
FMZ API (avatar->account settings->API interface),
A Bot that has been started (we want to get its ID, so we create a new ID first), the number in the URL of a general robot is the ID.

 ![Interfacing with FMZ robot using "Tradingview" indicator](/upload/asset/6e6055878d778eea6265.png) 

Next, we transform the webhook service so that after receiving the message, it will be automatically forwarded to the FMZ Bot.

Finally, don’t forget to fill in the completed ```webhook``` address in the TradingView Alert(format: http://xx.xx.xx.xx:80)

The following is the ```service``` code I changed, you can use it as a reference:

#!/usr/bin/python -tt

-- kod: UTF-8 --

dari BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer Import json Pengangkutan log Import logging.pengendali Pengimport Pengimportan import shutil Subproses import Masa import import ssl ssl._create_default_https_context = ssl._create_unverified_context

Cuba: import md5 import urllib2 dari urllib import urlencode kecuali: Import hashlib sebagai md5 Import urllib.request sebagai urllib2 dari urllib.parse import urlencode

############################################################

Anda mungkin perlu mengubah beberapa perkara di bawah

fail log untuk skrip ini

log_file = /root/webhook/VMA/webhook.log

Lesen bot api

accessKey = rahsiaKey =

Pengaturan HTTP

log_max_size = 25165824 # 24 MB log_level = logging.INFO #log_level = logging.DEBUG # DEBUG agak banyak perkataan

dengar_port = 80

Anda harus berhenti mengubah sesuatu kecuali anda tahu apa yang anda lakukan

##############################################################################

log = logging.getLogger(log) log.setLevel ((log_level) log_handler = logging.handlers.RotatingFileHandler(log_file, maxBytes=log_max_size, backupCount=4) f = logging.Formatter(%(asctime) s %(nama fail) s %(nama peringkat) s %(pesan) s, %B %d %H:%M:%S) log_handler.setFormatter ((f) log.addHandler ((log_handler)

kelas webhookReceiver ((BaseHTTPRequestHandler):

def run_it(self, cmd):
    """
        runs a command
    """
    p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE,
                         stderr=subprocess.STDOUT)
    log.debug('running:%s' % cmd)
    p.wait()
    if p.returncode != 0:
        log.critical("Non zero exit code:%s executing: %s" % (p.returncode,
                                                              cmd))
    return p.stdout

def bot_conmand(self, method, *args):
    """
        send conmand request to bot api
    """
    d = {
        'version': '1.0',
        'access_key': accessKey,
        'method': method,
        'args': json.dumps(list(args)),
        'nonce': int(time.time() * 1000),
        }
    d['sign'] = md5.md5(('%s|%s|%s|%d|%s' % (d['version'], d['method'], d['args'], d['nonce'], secretKey)).encode('utf-8')).hexdigest()
    return json.loads(urllib2.urlopen('https://www.fmz.com/api/v1', urlencode(d).encode('utf-8')).read().decode('utf-8'))

def do_POST(self):
    """
        receives post, handles it
    """
    log.debug('got post')
    message = 'OK'
    self.rfile._sock.settimeout(5)
    data_string = self.rfile.read(int(self.headers['Content-Length']))
    log.info(data_string)
    self.send_response(200)
    self.send_header("Content-type", "text")
    self.send_header("Content-length", str(len(message)))
    self.end_headers()
    self.wfile.write(message)
    log.debug('TV connection should be closed now.')
    #log.info(self.bot_conmand('GetRobotList', -1, -1, -1)) # GetRobotList(offset, length, robotStatus int)Pass -1 to get all
    log.info(self.bot_conmand('CommandRobot', 169788, data_string))  # CommandRobot(robotId int64, cmd string)Send commands to the robot

def log_message(self, formate, *args):
    """
        disable printing to stdout/stderr for every post
    """
    return

def utama ((): acara utama. Cuba: pelayan = HTTPServer (((, listen_port), webhookReceiver) log.info ((memulakan pelayan web...) server.serve_forever() kecuali KeyboardInterrupt: log.info ((ctrl-c ditekan, menutup.) server.socket.close (()

jikanama == ‘utama: utama (()


# Implementation within FMZ platform trading strategy

All the above described the communication implementation, our Bot trading strategy also needs to be processed accordingly, in order for us to fix our receiving signal process.

For example, the Alert Message designed at the beginning, You can play it according to your preferences and specific needs. 

The code is as follows, get the information, filter them, do the operation, and end.

fungsi get_Command() { //Fungsi yang bertanggungjawab untuk interaksi, secara interaktif mengemas kini nilai yang berkaitan dalam masa, pengguna boleh mengembangkan sendiri var cara = sifar; // laluan var cmd = GetCommand(); // Dapatkan API arahan interaktif var cmd_arr = cmd.split ((,);

 if (cmd) {
     // Define the route
     if (cmd.indexOf("BUY,1") != -1) {
         way = 1;
     }
     if (cmd.indexOf("SELL,1") != -1) {
         way = 2;
     }
     if (cmd.indexOf("BUY,2") != -1) {
         way = 3;
     }
     if (cmd.indexOf("SELL,2") != -1) {
        way = 4;
     }
     // Branch selection operation
     switch (way) {
         case 1:
             xxx
             break;
         case 2:
             xxx
             break;
         case 3:
             xxx
             break;
         case 4:
             xxx
             break;
         default:
             break;
     }
 }

} “`

Artikel ini berakhir, semoga ia dapat membantu anda!

Rekomendasi
Lebih lanjut