Coder Social home page Coder Social logo

ECONNRESET cпустя минут 5-10 после начала получения свечей из стрима about invest-openapi HOT 6 CLOSED

tinkoff avatar tinkoff commented on August 16, 2024
ECONNRESET cпустя минут 5-10 после начала получения свечей из стрима

from invest-openapi.

Comments (6)

koshkoshka avatar koshkoshka commented on August 16, 2024 1
const WebSocketClient = require('websocket');
const axios = require('axios');
const readline = require('readline');
const mysql = require('mysql2');
const mysqlUtilities = require('mysql-utilities');
const delay = require('delay');
  
let url='wss://api-invest.tinkoff.ru/openapi/md/v1/md-openapi/ws';
let sandbox="https://api-invest.tinkoff.ru/openapi/sandbox";
let intervals=["1min","2min","3min","5min","10min","15min","30min","hour","2hour","4hour","day","week","month"];

let headers={"Authorization": "Bearer ТУТВСТАВЬТЕТОКЕНSANDBOX"};

let useinstrument='BBG000R607Y3';

let ws = new WebSocketClient.client();
ws.connect(url,[],'',headers);
ws.on('connect',ws1 => {
    ws1.on('message', message => {
        let msg=JSON.parse(message.utf8Data);
        console.log(msg);
        switch(msg.event){
          case 'instrument_info':
            //ТУТ я работаю с SQL
            break;
          case 'candle':
            with(msg.payload){
              let time1=new Date(time).getTime()/1000;
              //тут я работаю с SQL
              
            }
            break;
        }
    });
    ws1.on('error',err => {
      console.log(err);
    });
const orderbook_subscribe=(figi,depth=1)=>{
      ws1.send(JSON.stringify({"event": "orderbook:subscribe","figi": figi,"depth":depth}));
    }
    
    const orderbook_unsubscribe=(figi,depth=1)=>{
      ws1.send(JSON.stringify({"event": "orderbook:unsubscribe","figi": figi,"depth":depth}));
    }
    
    const info_subscribe=(figi)=>{
      ws1.send(JSON.stringify({"event": "instrument_info:subscribe","figi": figi}));
    }
    
    const info_unsubscribe=(figi)=>{
      ws1.send(JSON.stringify({"event": "instrument_info:unsubscribe","figi": figi}));
    }
    
    const candle_subscribe=(figi,interval)=>{
      if(intervals.indexOf(interval)>-1){
        ws1.send(JSON.stringify({"event": "candle:subscribe","figi": figi,"interval":interval}));
      }
    }
    
    const candle_unsubscribe=(figi,interval)=>{
      if(intervals.indexOf(interval)>-1){
        ws1.send(JSON.stringify({"event": "candle:unsubscribe","figi": figi,"interval":interval}));
      }
    }
    intervals.forEach(element =>{
      candle_subscribe(useinstrument,element);
    });
});
ws.on('connectFailed',ws=>{
    console.log(ws);
});

from invest-openapi.

Gordondalos avatar Gordondalos commented on August 16, 2024 1

Спасибо за выложенный пример!!! он работает

from invest-openapi.

koshkoshka avatar koshkoshka commented on August 16, 2024

Подписка у меня при этом на 13 свечей (по количеству интервалов) на одну акцию.

from invest-openapi.

NikitaMelnikov avatar NikitaMelnikov commented on August 16, 2024

Можете привести код как воспроизвести? Возможно сетевая проблема и ваша библиотека не обрабатывает переподключение

from invest-openapi.

koshkoshka avatar koshkoshka commented on August 16, 2024

Можете привести код как воспроизвести? Возможно сетевая проблема и ваша библиотека не обрабатывает переподключение

Скинул пример кода в Node JS

from invest-openapi.

NikitaMelnikov avatar NikitaMelnikov commented on August 16, 2024

На сколько я понимаю, ваш клиент автоматически не пересоздает подключение, попробуйте этот вариант: https://github.com/websockets/ws/wiki/Websocket-client-implementation-for-auto-reconnect

from invest-openapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.