1

I start playing with RxPy but I can't find a way to stream a csv file which represents stock ticker with timestamp. Can someone help me to understand how to use scheduler to go back to my first tick and then stream each line from the csv at the exact timestamp ?

from rx import Observable
from rx.concurrency import HistoricalScheduler
import pandas as pd
from datetime import datetime

df = pd.read_csv("eurusd.csv", names=['Symbol', 'Date', 'Bid', 'Ask'])
df['Date'] = pd.to_datetime(df['Date'])

startTime = df['Date'][0]
scheduler = HistoricalScheduler(startTime)

observable = Observable.from_iterable(df, scheduler=scheduler).timestamp(scheduler=scheduler)
observable.map(lambda l: l)
observable.subscribe(lambda s: print(s))

scheduler.start()

You can download the csv file here.

EDIT:

I tried to convert the RxJS code from this blog without success:

observable = Observable.for_in(df, lambda t: Observable.timer(t['Date'].timestamp.date(), scheduler).map(lambda l: l)) 
observable.subscribe(lambda s: print(s))

Can someone help me on this matter?

Taylor Buchanan
  • 4,155
  • 1
  • 28
  • 40
wbeuil
  • 87
  • 1
  • 10

0 Answers0