FX31337 / FX-BT-Scripts

:page_facing_up: Useful scripts for backtesting.
MIT License
34 stars 39 forks source link

how usage stream candles ? #112

Closed rahmangunawans closed 1 year ago

rahmangunawans commented 1 year ago

please i need example :(.

kenorb commented 1 year ago

Which script you're referring to? Can you elaborate?

rahmangunawans commented 1 year ago

Which script you're referring to? Can you elaborate?

from iqoptionapi.stable_api import IQ_Option
import time, threading
import pandas as pd
import queue
input_queue = queue.Queue(maxsize=1000)
iq=IQ_Option("", "")
def start_price_stream(symbol,timeframe):
    timeframe = (timeframe) # size , 1 = 1 sec.
    iq.start_candles_stream(symbol,int(timeframe),1)
    time.sleep(0.5)
    vela = iq.get_realtime_candles(symbol,int(timeframe))
    for velas in  list(vela):
        date = vela[velas]["from"]
        open = vela[velas]["open"]
        high = vela[velas]["max"]
        low = vela[velas]["min"]
        close = vela[velas]["close"]
        volume = vela[velas]["volume"]
        data = [ date, open,  high,  low,  close]

        df = pd.DataFrame ([data], columns = ['date','open','high','low','close'])

        main = df.set_index(['date'])
        main.index = pd.to_datetime(main.index, unit='s')
        #print(symbol)
    return data

 def check():
    print("starting stream")
    symbol = input_queue.get()
    while 1:
        try:
            up = start_price_stream(symbol, 1)
            print(symbol, up)
            input_queue.task_done()
        except:
            pass

def threads():
    try:
        for x in range(int(5)):
            t = threading.Thread(target=check)
            t.setDaemon(True)
            t.start()
        for y in open("symbol.txt", 'r').readlines(): #EURUSD-OTC GBPUSD-OTC
            input_queue.put(y.strip())
        input_queue.join()
    except:
        pass

 threads()

multi pair data iq option on mt4 with output hst streaming tick. convert_iq_to_mt.py or convert_csv_to_mt.py please i need multi pair output hst. for simple example.

kenorb commented 1 year ago

with output hst streaming tick.

HST format is for historical candle data, for ticks you need to use FXT format. Unless you mean candles, not ticks.