just trying to save websockets to CSV’s. But it just doesnt make the file. Nothing in the directory. Tried running VScvode as admin, moving folder out of C: drive to documents .. nothing. no csv file, and no error. and no information on the internet about this either.
So i kept stripping down the code to the most basic, and it still wont create the file
The dataframe is in-tact and working, and printing the dataframe gets this :
JavaScript
x
8
1
e E s k
2
B kline 1659568703134 ETHUSDT 0
3
L kline 1659568703134 ETHUSDT 920866977
4
Q kline 1659568703134 ETHUSDT 166707.65228800
5
T kline 1659568703134 ETHUSDT 1659568739999
6
V kline 1659568703134 ETHUSDT 103.43430000
7
c kline 1659568703134 ETHUSDT 1611.00000000
8
… (continued)
JavaScript
1
20
20
1
import websocket, json, numpy, pandas
2
from binance.client import Client
3
from binance.enums import *
4
5
SOCKET = "wss://stream.binance.com:9443/ws/ethusdt@kline_1m/btcusdt@kline_1m"
6
#lol
7
def on_open(ws):
8
print('opened connection')
9
10
def on_close(ws):
11
print('closed connection')
12
13
def on_message(ws, message):
14
df = pandas.read_json(message)
15
print(df)
16
df.to_csv('my_new_file.csv')
17
18
ws = websocket.WebSocketApp(SOCKET, on_open=on_open, on_close=on_close, on_message=on_message)
19
ws.run_forever()
20
Advertisement
Answer
Try this:
JavaScript
1
4
1
import os
2
3
print(os.getcwd())
4
This will give you the file directory that the file is currently running on, so you can drop the file there.