Skip to content

Instantly share code, notes, and snippets.

@eduedix
eduedix / bt_latency1.py
Created Aug 28, 2018
latency between system and bt clock
View bt_latency1.py
import datetime
import backtrader as bt
import pytz
import pandas as pd
from utils.constants import getIBFX
class TickerStrat(bt.Strategy):
View bt_latency_log.txt
2018-08-28 11:30:35.884373
AUD.CAD-CASH-IDEALPRO_tick 2018-08-28 11:30:35.010730 0.95016 ***
AUD.NZD-CASH-IDEALPRO_tick 2018-08-28 11:30:35.014552 1.09518 ---
AUD.USD-CASH-IDEALPRO_tick 2018-08-28 11:30:34.992353 0.73443 ***
2018-08-28 11:30:35.885761
AUD.CAD-CASH-IDEALPRO_tick 2018-08-28 11:30:35.010730 0.95016 ***
AUD.NZD-CASH-IDEALPRO_tick 2018-08-28 11:30:35.014552 1.09518 ***
AUD.USD-CASH-IDEALPRO_tick 2018-08-28 11:30:35.018213 0.73444 ---
View bt latency log2.txt
2018-08-28 12:13:12.595505
AUD.CAD-CASH-IDEALPRO_tick 2018-08-28 12:13:08.424882 0.95026 ***
AUD.NZD-CASH-IDEALPRO_tick 2018-08-28 12:13:08.530424 1.09545 ***
AUD.USD-CASH-IDEALPRO_tick 2018-08-28 12:13:08.527748 0.73544 ***
CAD.CHF-CASH-IDEALPRO_tick 2018-08-28 12:13:08.693720 0.7551 ***
CAD.JPY-CASH-IDEALPRO_tick 2018-08-28 12:13:08.669510 85.936 ***
CHF.JPY-CASH-IDEALPRO_tick 2018-08-28 12:13:04.470377 113.802 ***
EUR.AUD-CASH-IDEALPRO_tick 2018-08-28 12:13:08.291379 1.59258 ***
EUR.CAD-CASH-IDEALPRO_tick 2018-08-28 12:13:08.688057 1.51335 ***
EUR.CHF-CASH-IDEALPRO_tick 2018-08-28 12:13:08.311837 1.14277 ***
View ib_insync test
def onPending(tickers):
for ticker in tickers:
d_time = datetime.datetime.utcnow() - ticker.time.replace(tzinfo=None)
print(d_time.total_seconds(), datetime.datetime.utcnow(), ticker.time, ticker.marketPrice())
0.000197 2018-08-28 13:01:55.538025 2018-08-28 13:01:55.537808+00:00 1.2928700000000002
0.000697 2018-08-28 13:01:55.538526 2018-08-28 13:01:55.537808+00:00 1.29088