Esempio n. 1
0
 def __init__(self, instrument, granularity, profitpips):
     self.instrument = instrument
     self.granularity = granularity
     self.subc = None
     self.profit = tradelib.pip2Price(profitpips, instrument)
     self.unitsecs = tradelib.getUnitSecs(granularity)
     self.pipprice = tradelib.pip2Price(1, instrument)
     self.id = -1
     self.curr_side = env.SIDE_BUY
     self.now = -1
Esempio n. 2
0
def insertMonoPricedata(instrument, granularity, startprice, start, end,
                        direction, pipdiff):
    db = MSSQLDB()
    pricetbl = lib.names.getPriceTable(instrument, granularity)
    priceunit = tradelib.pip2Price(1, instrument)
    unitsecs = tradelib.getUnitSecs(granularity)
    start -= (start % unitsecs)
    end -= (end % unitsecs)

    curr = start
    price = startprice
    cnt = 0
    while curr <= end:
        i = cnt % 3
        if i == 2:
            price -= pipdiff * priceunit * direction
        else:
            price += pipdiff * priceunit * direction
        if direction == 1:
            o = price
            c = price + 2 * pipdiff * priceunit
        else:
            o = price + 2 * pipdiff * priceunit
            c = price
        sql = "insert into %s ([ep],[dt],[o],[h],[l],[c],[v]) \
            values (%d,'%s',%f,%f,%f,%f,%d)" % (
            pricetbl, curr, lib.epoch2str(curr, "%Y-%m-%d %H:%M:%S"), o,
            price + 2 * pipdiff * priceunit, price, c, (i + 1) * 10)
        db.execute(sql)
        curr += unitsecs
        cnt += 1
Esempio n. 3
0
    def __init__(self,
                 instrument,
                 granularity,
                 startep=-1,
                 endep=-1,
                 peakspan=12 * 6,
                 peaksize=5,
                 analspan=12 * 4):

        self.instrument = instrument
        self.granularity = granularity
        self.subc = SubChart("PriceAction",
                             self.instrument,
                             self.granularity,
                             startep=startep,
                             endep=endep,
                             nbars=peakspan + peaksize * 2)

        self.peaks = PeakIndex(self.subc, peaksize, peakspan)
        self.analspan = analspan
        self.hist = MultiObjHistory(analspan)
        self.candleshapes = CandleShapeIndex(self.subc,
                                             statistics_span=analspan)
        self.unitsecs = tradelib.getUnitSecs(granularity)
        self.pipprice = tradelib.pip2Price(1, instrument)
        self.nowi = -1
        self.now = -1

        self.linehists = {
            const_candles.LINE_TPTREND: {},  # dict of History()
            const_candles.LINE_BTTREND: {},
            const_candles.LINE_MAX: {},
            const_candles.LINE_MIN: {}
        }
Esempio n. 4
0
 def __init__(self, instrument, granularity, startep, endep, spread=NORMAL_SPREAD):
     self.prices = getterlib.getPrices(instrument, granularity, startep, endep)
     self.ticker_type = env.TICKTYPE_OFFLINE
     self.spread_price = tradelib.pip2Price(spread, instrument)
     self.digit = tradelib.getDecimalPlace(instrument)
     self.spread_price = round(self.spread_price, self.digit+1)
     self.pos = 0
     self.now = -1