finnhubio / Finnhub-API

Finnhub API provides institutional-grade financial data to investors, fintech startups and investment firms. We support real-time stock price, global fundamentals and alternative data. https://finnhub.io/docs/api
97 stars 6 forks source link

Connection gets Closed prematurely #378

Open PedroAguiar opened 3 years ago

PedroAguiar commented 3 years ago

When establishing a websocket connection to the trades endpoint, and respecting the ping / pong strategy. Then my connection gets closed by finnhub's server after 3 hours of communication.

2020-12-02T12:22:52.054-03:00 | 2020-12-02 15:22:52,054 CRITICAL MainProcess --- [MainThread] harvest : Connection is already closed.
-- | --

Im using the following client: https://pypi.org/project/websocket_client/

Here's my configuration:


# This function gets called when the message type == 'ping'
def pong(ws):
    logging.info('Sending pong')
    payload = json.dumps({
        'type': 'pong'
    })
    ws.send(payload, opcode=websocket.ABNF.OPCODE_PONG)

def on_ping(ws, message):
    logging.info('Received ping')

def on_pong(ws, message):
    logging.info('Received pong')

ws = websocket.WebSocketApp(
    "wss://ws.finnhub.io?token=<token>",
    on_message=on_message,
    on_error=on_error,
    on_close=on_close,
    on_pong=on_pong,
    on_ping=on_ping
)

def main():
    ws.on_open = on_open
    ws.run_forever(ping_interval=600)

I'm trying to connect to the trades endpoint throughout the entire system hours described here: https://iextrading.com/trading/

But my connection is always getting closed after 3 hours of being connected and successfully receiving/transmitting messages.

zbot473 commented 3 years ago

I can also reproduce this. It's super annoying to keep reconnecting.

finnhubio commented 3 years ago

Hi guys,

We have issued a fix for this issue. Plz try again when the market opens.

Our apology for the inconvenience. Let us know if you still encounter any further issues.