Volatility 100, print every 2 ticks - Python

edited January 25 in General

Hi everybody,
I would like to make this code print every 2 ticks. However, when adding durations, the code does not read.
How can I print every 2 ticks?

import websocket
import json

def on_open(ws):
    json_data = json.dumps({'ticks':'R_100', 'duration': 2})
    ws.send(json_data)

def on_message(ws, message):
    print('ticks update: %s' % message)

if __name__ == "__main__":
    apiUrl = "wss://ws.binaryws.com/websockets/v3?app_id=1089"
    ws = websocket.WebSocketApp(apiUrl, on_message = on_message, on_open = on_open)
    ws.run_forever()

Comments

  • @luiz_hvac If you only want to print every second tick you will need to handle that in your code. There is no parameter that you can send to the API to only get ever second tick.
    something like should work,

    import websocket
    import json
    count = 0
    
    def on_open(ws):
        json_data = json.dumps({'ticks':'R_100'})
        ws.send(json_data)
    
    def on_message(ws, message):
        global count
        if count == 1:
            print('ticks update: %s' % message)
            count = 0
        else:
            count = 1 
    
    if __name__ == "__main__":
        apiUrl = "wss://ws.binaryws.com/websockets/v3?app_id=1089"
        ws = websocket.WebSocketApp(apiUrl, on_message = on_message, on_open = on_open)
        ws.run_forever()
    
Sign In or Register to comment.