Apprendre à hacher des données dans mql4 - page 3

 
Reshetov:

Le problème est que l'on peut calculer les frais généraux, mais que l'on ne peut pas voir le bénéfice qui se cache derrière.

Je suis déjà rentable et pas mal, tout est une question de chiffrage.
 
TheXpert:

Tout d'abord, ce n'est pas SHA256, c'est HMAC SHA512.

c'est sur BTC-e
 
sanyooooook:
Je profite déjà, et pas mal, c'est juste une question de chiffrage.

Après ce message, il est trop tard pour crypter les bénéfices : les racketteurs sont déjà au courant et vont bientôt passer. Et il ne leur faut pas longtemps pour la trouver : la maison sans toit à la périphérie est celle où sanyooooook crypte les bénéfices.

 
Reshetov:

Après ce message, il est trop tard pour crypter les bénéfices : les racketteurs sont déjà au courant et vont bientôt passer. Et ils n'ont pas à chercher longtemps : la maison sans toit dans la banlieue est celle où sanyooooook crypte les bénéfices.

"nous n'avons pas peur du loup gris")
 
sanyooooook:
C'est sur BTC-e.

Je l'ai. Vous ne devriez pas avoir peur, d'ailleurs. Avec winapi, d'ailleurs, vous devez d'abord faire un code fonctionnel, puis le traduire en mql. Et pour écrire quelque chose en mql qui soit un programme indépendant... le point ?

Si vous ne voulez pas apprendre Sharp, vous devez apprendre Python. Si tu veux de l'argent, tu devras apprendre.

 
TheXpert:

Je l'ai. Vous ne devriez pas avoir peur, d'ailleurs. Avec winapi, d'ailleurs, vous devez d'abord faire un code fonctionnel, puis le traduire en mql. Et pour écrire quelque chose en mql qui soit un programme indépendant... le point ?

Vous ne voulez pas apprendre Sharp, apprenez Python. Si tu veux du pognon, tu devras apprendre.

Merde, regarde ça :

1. l'api d'échange, envoyez une demande de poste au format json (json n'est pas difficile)

2. dans cette requête une partie des données est hachée, ici j'ai un problème, mais ce n'est pas un problème, je l'ai résolu (temporairement j'ai reporté l'implémentation du code par un stupide hachage des données d'entrée).

3. Ce truc n'envoie rien, peut-être que je fais mal le post ?

//+------------------------------------------------------------------+
//|                                                     POSTBTCE.mq4 |
//|                      Copyright © 2012, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#include <stdlib.mqh>

#import "wininet.dll"

#define  INTERNET_OPEN_TYPE_DIRECT       0
#define  INTERNET_OPEN_TYPE_PRECONFIG    1
#define  INTERNET_OPEN_TYPE_PROXY        3

// Had to cut the following two defines because of silly MQL4 identifier limits

#define _IGNORE_REDIRECT_TO_HTTP        0x00008000
#define _IGNORE_REDIRECT_TO_HTTPS       0x00004000

#define  INTERNET_FLAG_KEEP_CONNECTION   0x00400000
#define  INTERNET_FLAG_NO_AUTO_REDIRECT  0x00200000
#define  INTERNET_FLAG_NO_COOKIES        0x00080000
#define  INTERNET_FLAG_RELOAD            0x80000000
#define  INTERNET_FLAG_NO_CACHE_WRITE    0x04000000
#define  INTERNET_FLAG_DONT_CACHE        0x04000000
#define  INTERNET_FLAG_PRAGMA_NOCACHE    0x00000100
#define  INTERNET_FLAG_NO_UI             0x00000200

#define  HTTP_ADDREQ_FLAG_ADD            0x20000000
#define  HTTP_ADDREQ_FLAG_REPLACE        0x80000000

#define  INTERNET_SERVICE_HTTP           3
#define  INTERNET_DEFAULT_HTTP_PORT      80

#define  ICU_ESCAPE                      0x80000000
#define  ICU_USERNAME                    0x40000000
#define  ICU_NO_ENCODE                   0x20000000
#define  ICU_DECODE                      0x10000000
#define  ICU_NO_META                     0x08000000
#define  ICU_ENCODE_PERCENT              0x00001000
#define  ICU_ENCODE_SPACES_ONLY          0x04000000
#define  ICU_BROWSER_MODE                0x02000000

#define  AGENT                           "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Q312461)"
#define  BUFSIZ                          128

#define  REQUEST_FILE                    "_req.txt"

////////////// PROTOTYPES

bool InternetCanonicalizeUrlA(string lpszUrl, string lpszBuffer, int& lpdwBufferLength[], int dwFlags);

int InternetOpenA(string sAgent, int lAccessType, string sProxyName="", string sProxyBypass="", int lFlags=0);

int InternetOpenUrlA(int hInternetSession, string sUrl, string sHeaders="", int lHeadersLength=0, int lFlags=0,
   int lContext=0);

int InternetReadFile(int hFile, string sBuffer, int lNumBytesToRead, int& lNumberOfBytesRead[]);

int InternetCloseHandle(int hInet);

int InternetConnectA(int handle, string host, int port, string user, string pass, int service, int flags, int context);

bool HttpSendRequestA(int handle, string headers, int headersLen, int& optional[], int optionalLen);

bool HttpAddRequestHeadersA(int handle, string headers, int headersLen, int modifiers);

int HttpOpenRequestA(int hConnect, string lpszVerb, string lpszObjectName, string lpszVersion,
 string lpszReferer, string& lplpszAcceptTypes[], int dwFlags, int dwContext);

#import

//////// CODE

bool HttpGET(string strUrl, string& strWebPage)
{
  int hSession = InternetOpenA(AGENT, INTERNET_OPEN_TYPE_DIRECT, "0", "0", 0);

  int hReq = InternetOpenUrlA(hSession, strUrl, "0", 0,
        INTERNET_FLAG_NO_CACHE_WRITE |
        INTERNET_FLAG_PRAGMA_NOCACHE |
        INTERNET_FLAG_RELOAD, 0);

  if (hReq == 0) {
    return(false);
  }

  int     lReturn[]  = {1};
  string  sBuffer    = "";

  while (TRUE) {
    if (InternetReadFile(hReq, sBuffer, BUFSIZ, lReturn) <= 0 || lReturn[0] == 0) {
      break;
    }
    strWebPage = StringConcatenate(strWebPage, StringSubstr(sBuffer, 0, lReturn[0]));
  }

  InternetCloseHandle(hReq);
  InternetCloseHandle(hSession);

  return (true);
}

/////////// POST

bool HttpPOST(string host, string script, string params[][], string filenames[][], string& strWebPage)
{
  int hIntrn = InternetOpenA(AGENT, INTERNET_OPEN_TYPE_DIRECT, "0", "0", 0);
  if (hIntrn == 0) {
    return (false);
  }

  int hConn = InternetConnectA(hIntrn,
                              host,
                              INTERNET_DEFAULT_HTTP_PORT,
                              NULL,
                              NULL,
                              INTERNET_SERVICE_HTTP,
                              0,
                              NULL);

  if (hConn == 0) {
    return (false);
  }

  int dwOpenRequestFlags =   // _IGNORE_REDIRECT_TO_HTTP |
                             // _IGNORE_REDIRECT_TO_HTTPS |
                             // INTERNET_FLAG_KEEP_CONNECTION |
                             // INTERNET_FLAG_NO_AUTO_REDIRECT |
                             // INTERNET_FLAG_NO_COOKIES |
                             // INTERNET_FLAG_NO_CACHE_WRITE |
                             INTERNET_FLAG_NO_UI |
                             INTERNET_FLAG_RELOAD;

  string accept[] = {"Accept: text/*\r\n"};

  int hReq = HttpOpenRequestA(hConn,
                             "POST",
                             script,
                             "HTTP/1.0",
                             NULL,
                             accept,
                             dwOpenRequestFlags,
                             NULL);

  string strBoundary = "---------------------------HOFSTADTER";
  string strContentHeader = "Content-Type: multipart/form-data; boundary=" + strBoundary;

  HttpAddRequestHeadersA(hReq, strContentHeader, StringLen(strContentHeader), HTTP_ADDREQ_FLAG_REPLACE);

  int i     = 0,
      idx   = 0,
      r     = 0,
      len   = 0
  ;

  string hdr = "";

  int _req = FileOpen(REQUEST_FILE, FILE_BIN|FILE_WRITE);
  if(_req <= 0) {
    return (false);
  }

  // Add parameters to request body

  for (i = ArrayRange(params, 0) - 1; i >= 0; i--) {
    hdr = StringConcatenate(
      "--", strBoundary, "\r\n",
      "Content-Disposition: form-data; name=\"", params[i][0], "\"\r\n\r\n",
      params[i][1], "\r\n");
    FileWriteString(_req, hdr, StringLen(hdr));
  }

  // Add files to request body
  
  for (i = ArrayRange(filenames, 0) - 1; i >= 0; i--) {
    hdr = StringConcatenate(
      "--", strBoundary, "\r\n",
      "Content-Disposition: form-data; name=\"", filenames[i][0], "\"; filename=\"", filenames[i][1], "\"\r\n",
      "Content-Type: application/octet-stream\r\n\r\n");

    FileWriteString(_req, hdr, StringLen(hdr));

    int handle = FileOpen(filenames[i][1], FILE_BIN|FILE_READ);
    if(handle <= 0) {
      return (false);
    }
    len = FileSize(handle);
    for (int b = 0; b < len; b++) {
      FileWriteInteger(_req, FileReadInteger(handle, CHAR_VALUE), CHAR_VALUE);
    }
    FileClose(handle);
  }

  string boundaryEnd = "\r\n--" + strBoundary + "--\r\n";
  FileWriteString(_req, boundaryEnd, StringLen(boundaryEnd));

  FileClose(_req);

  // Re-reads saved POST data byte-to-byte from file in the pseudo-character array
  //  we need to send with HttpSendRequestA. This is due to the fact I know no clean
  //  way to cast strings _plus_ binary file contents to a character array in MQL.
  //  If you know how to do it properly feel free to contact me.

  int request[];

  _req = FileOpen(REQUEST_FILE, FILE_BIN|FILE_READ);
  if (_req <= 0) {
    return (false);
  }
  len = FileSize(_req);

  ArrayResize(request, len);
  ArrayInitialize(request, 0);

  for (i = 0; i < len; i++) {
    request[r] |= FileReadInteger(_req, CHAR_VALUE) << (idx * 8);
    idx = (idx + 1) %4;
    if (idx == 0) {
      r++;
    }
  }
  FileClose(_req);

  if (!HttpSendRequestA(hReq, NULL, 0, request, len)) {
    return (false);
  }

  // Read response

  int     lReturn[]  = {1};
  string  sBuffer    = "";

  while (TRUE) {
    if (InternetReadFile(hReq, sBuffer, BUFSIZ, lReturn) <= 0 || lReturn[0] == 0) {
      break;
    }
    strWebPage = StringConcatenate(strWebPage, StringSubstr(sBuffer, 0, lReturn[0]));
  }

  InternetCloseHandle(hReq);
  InternetCloseHandle(hConn);
  InternetCloseHandle(hIntrn);

  return (true);
}


//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
string params[2][2];

params[0][0] = "key1";

params[0][1] = "value1";
params[1][0] = "key2";

params[1][1] = "value2";
// for multiple file upload

string filenames[2][2];
filenames[0][0] = "uploaded1"; // name of form field for file upload

filenames[0][1] = "test1.txt"; // file name in experts/files/ subfolder
filenames[1][0] = "uploaded2";
filenames[1][1] = "test2.txt";

string response;
string Signature="DZeZIy/6H6fXGPEk8sdfgYJOYl0gGIlfivZqcfjbIzKk=";
string s="{"+CharToStr(34)+"Login"+CharToStr(34)+":"+CharToStr(34)+"B8yQVM4tGWijT"+CharToStr(34)+","
            +CharToStr(34)+"Wmid"+CharToStr(34)+":"+CharToStr(34)+""+CharToStr(34)+","
            +CharToStr(34)+"Culture"+CharToStr(34)+":"+CharToStr(34)+"ru-RU"+CharToStr(34)+","
            +CharToStr(34)+"Signature"+CharToStr(34)+":"+CharToStr(34)+Signature+CharToStr(34)+"}";Print(s);
HttpPOST("https://secure.indx.ru/api/v1/tradejson.asmx", s, params, filenames, response);

Print(response);
//----
   return(0);
  }
//+------------------------------------------------------------------+
 

dès que vous pouvez envoyer une demande, vous disposez d'un ensemble de fonctions de négociation

graines de tournesol mais il ne me renvoie rien (( !)

La chaîne de caractères s'affiche correctement lors de la demande, mais je dois utiliser la mauvaise fonction POST.

 
sanyooooook:
Donc je dis qu'il faut l'écrire dans n'importe quel langage normal et trouver où est le problème, puis le traduire en MQL.
 

sanyooooook:

3. Cette infestation ne veut rien envoyer, peut-être que je fais mal le post ?

...
string response;
string Signature="DZeZIy/6H6fXGPEk8sdfgYJOYl0gGIlfivZqcfjbIzKk=";
string s="{"+CharToStr(34)+"Login"+CharToStr(34)+":"+CharToStr(34)+"B8yQVM4tGWijT"+CharToStr(34)+","
            +CharToStr(34)+"Wmid"+CharToStr(34)+":"+CharToStr(34)+"364823817435"+CharToStr(34)+","
            +CharToStr(34)+"Culture"+CharToStr(34)+":"+CharToStr(34)+"ru-RU"+CharToStr(34)+","
            +CharToStr(34)+"Signature"+CharToStr(34)+":"+CharToStr(34)+Signature+CharToStr(34)+"}";Print(s);
HttpPOST("https://secure.indx.ru/api/v1/tradejson.asmx", s, params, filenames, response);
...

En fait, dans les requêtes GET et POST, tout est transmis sous la forme : id=value, c'est-à-dire le nom du paramètre et la valeur avec un signe égal. De plus, tous les caractères qui ne sont pas des lettres et des chiffres latins sont codés avec % (code de caractère).

Par exemple, si nous supposons que le tableau params stocke les identifiants des paramètres passés, alors la variable s devrait aussi être un tableau de la même taille pour passer les valeurs correspondant aux paramètres ?

 
Reshetov:


C'est-à-dire que si nous supposons que le tableau params stocke les identifiants des paramètres à passer, alors la variable s doit certainement être un tableau de la même taille pour passer les valeurs correspondant aux paramètres.?

Vous me le demandez ?

Raison: