Skip to content

Commit

Permalink
get custom studies from TOS
Browse files Browse the repository at this point in the history
  • Loading branch information
xxwikkixx committed Oct 30, 2019
1 parent c181d1f commit de2e109
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
31 changes: 20 additions & 11 deletions TOSTest.py
Expand Up @@ -8,11 +8,11 @@

tosdb.init(dllpath=r"C:\TOSDataBridge\bin\Release\x64\tos-databridge-0.9-x64.dll")
block = tosdb.TOSDB_DataBlock(100000, True)
block.add_items('/ES:XCME')
block.add_topics('OPEN', 'HIGH', 'LOW', 'bid', 'ask', 'volume', 'LAST', 'LASTX', 'BIDX', 'ASKX', 'LAST_SIZE')
block.add_items('/MES:XCME', '/MYM:XCBT')
block.add_topics('OPEN', 'HIGH', 'LOW', 'bid', 'ask', 'volume', 'LAST', 'LASTX', 'BIDX', 'ASKX', 'LAST_SIZE', 'CUSTOM5')
### NOTICE WE ARE SLEEPING TO ALLOW DATA TO GET INTO BLOCK ###
print("Sleeping for 1 second")
time.sleep(1)
print("Sleeping for 2 second")
time.sleep(2)

def getLastPrice(symbol):
# Bool value to check if its connected: True
Expand Down Expand Up @@ -44,8 +44,6 @@ def getLastPrice(symbol):
def tosDBohlc():
block = ohlc.tosdb.TOSDB_ThreadSafeDataBlock(10000)
intrv = ohlc.TOSDB_OpenHighLowCloseIntervals(block, 60)
intrv.add_items('/ES:XCME')
intrv.add_topics('OPEN', 'HIGH', 'LOW')
print(intrv.get('/ES:XCME', 'OPEN'))

tosdb.clean_up()
Expand All @@ -71,12 +69,23 @@ def test():
def RTDdata():
pass

def tosCustomStudyData():
while True:
esval, estimes = block.get('/MES:XCME', 'CUSTOM5', date_time=True)
ymval, ymtimes = block.get('/MYM:XCBT', 'CUSTOM5', date_time=True)
if esval == "1.0":
print("ES LONG")
elif esval == "0.0":
print("ES SHORT")
# tosdb.clean_up()

if __name__ == '__main__':
# tosDBohlc()
# # tosDBohlc()

# while True:
# print(getLastPrice('/ES:XCME'))
# # print(getLastPrice('/ES:XCME'))
# data, times = block.get('/ES:XCME', 'LAST', date_time=True)
# print(data, times)
# time.sleep(.5)
#
while True:
data, data2 = block.get('/ES:XCME', 'LAST', date_time=True)

tosStudyData()
12 changes: 9 additions & 3 deletions miscTest.py
@@ -1,4 +1,5 @@
import time
import talib
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
Expand All @@ -7,24 +8,29 @@
from timeit import default_timer

def plotMaxMin():
# data = pd.read_csv('cltick.csv')
data = pd.read_csv('Harmonics/file.csv')
data = pd.read_csv('cltick.csv')
data['time'] = pd.to_datetime(data['time'], format='%d.%m.%Y %H:%M:%S.%f')
data = data.set_index(data['time'])
data = data.drop_duplicates(keep=False)
price = data['Close']
price = price.drop_duplicates(keep=False)

# Finds the maximums index
max_idx = np.argmax(price.values)
# Finds the minimums index
min_idx = np.argmin(price.values)

SmaOutput = talib.SMA(price, 9)

print(max_idx)
print(min_idx)

plt.title('Close Price')
# plt.figure(dpi=600)
plt.plot(price.values)

plt.plot(SmaOutput.values)

plt.scatter(max_idx, max(price.values), c='r')
plt.scatter(min_idx, min(price.values), c='r')
plt.show()
Expand Down Expand Up @@ -88,4 +94,4 @@ def supres(ltp, n):
return support, resistance

if __name__ == '__main__':
plotMaxMin()
plotMaxMin()

0 comments on commit de2e109

Please sign in to comment.