Thursday, September 3, 2020

Plogon Python for Alpaca

 # Be sure to pip install websocket-client

# Details: https://pypi.org/project/websocket-client/

import websocket
import json
def on_message(wsmessage):
    with open('data.txt''a'as outfile:
        json.dump(message, outfile)
    print(message)
    

def on_error(wserror):
    print(error)

def on_close(ws):
    #print("### closed ###")
    f.close

def on_open(ws):
    ws.send('{"action":"auth","params":"XXXXX"}')
    ws.send('{"action":"subscribe","params":"A.AAPL"}')

f = open("demofile.txt""a")
if __name__ == "__main__":
    # websocket.enableTrace(True)
    ws = websocket.WebSocketApp("wss://socket.polygon.io/stocks",
                              on_message = on_message,
                              on_error = on_error,
                              on_close = on_close)
    ws.on_open = on_open
    

    ws.run_forever()

1 comment:

  1. Borgata to open new casino in Las Vegas - JTM Hub
    The Borgata Hotel Casino & 전라남도 출장샵 Spa 파주 출장안마 in 강원도 출장안마 Atlantic City is located 광주광역 출장샵 on the East Coast's second 아산 출장안마 major shopping circuit. The casino's hotel-casino

    ReplyDelete