Ejemplo n.º 1
0
    def testGetOandaPrice(self):
        st = lib.str2epoch("2019/04/02 09:00", "%Y/%m/%d %H:%M")
        ed = lib.str2epoch("2019/04/02 12:00", "%Y/%m/%d %H:%M")
        o = OandaGetter("USD_JPY", "H1")

        t, o, h, l, c, v = o.getPrice(st, ed)
        self.assertEqual(t[0], 1554195600)
        self.assertEqual(t[-1], 1554206400)
        self.assertEqual(len(t), 4)
        self.assertEqual(v[0], 372)
        self.assertEqual(o[0], 111.394)
Ejemplo n.º 2
0
def launchDataGetter(instrument, granularity):
    name = lib.names.getDataGetterName(instrument, granularity)
    if name in env.dataGetters.keys():
        dg = env.dataGetters[name]
    else:    
        datagetter_type = env.conf["datagetter_type"]
        if datagetter_type == "mssqloanda":
            from data_getter.mssql import MSSQLGetter
            from data_getter.oanda import OandaGetter
            dg = MSSQLGetter(OandaGetter(instrument, granularity))
            env.dataGetters[name] = dg
        '''
        Add here more data getters
        '''
    return dg
Ejemplo n.º 3
0
 def testGetH1MSSQLPrices(self):
     env.run_mode = env.MODE_UNITTEST
     from db.mssql import MSSQLDB
     msgetter.N_REQUEST_ROWS = 10
     d = MSSQLDB()
     
     instrument = "USD_JPY"
     granularity = "M5"
     pTable = names.getPriceTable(instrument, granularity)
     d.execute("drop table if exists %s;" % pTable)
     
     fmt = "%Y/%m/%d %H:%M"
     og = msgetter.MSSQLGetter(OandaGetter(instrument, granularity))
     
     def _verify(ststr, edstr, tcnt, rcnt, openp, vol):
         st = lib.str2epoch(ststr, fmt)
         ed = lib.str2epoch(edstr, fmt)
         t, o, h, l, c, v = og.getPrice(st, ed)
         self.assertEqual(d.countTable(pTable),tcnt)
         self.assertEqual(t[0], st)
         self.assertEqual(t[-1], ed)
         self.assertEqual(len(t), rcnt)
         self.assertEqual(v[0], vol)
         self.assertEqual(o[0], openp)
     
     # 11:00 - 11:20    
     _verify("2019/11/13 11:00", "2019/11/13 11:20", 5,5, 108.94, 39)
     
     # 11:00 - 11:40
     _verify("2019/11/13 11:30", "2019/11/13 11:40", 9,3, 108.963, 21)
     
     # 10:40 - 11:40
     _verify("2019/11/13 10:40", "2019/11/13 10:50", 13,3, 108.906, 32)
     
     # 10:35 - 11:40
     _verify("2019/11/13 10:35", "2019/11/13 10:55", 14,5, 108.916, 39)
     
     # 10:35 - 11:50
     _verify("2019/11/13 11:30", "2019/11/13 11:50", 16,5, 108.963, 21)
     
     # 10:35 - 12:50
     _verify("2019/11/13 11:30", "2019/11/13 12:50", 28,17, 108.963, 21)
Ejemplo n.º 4
0
        (ep, o, h, l, c, v) = self.selectData(startep, endep)
        return (ep, o, h, l, c, v)


if __name__ == "__main__":
    import env
    from data_getter.oanda import OandaGetter
    env.run_mode = env.MODE_UNITTEST
    from db.mssql import MSSQLDB
    d = MSSQLDB()

    d.execute("drop table if exists USD_JPY_M1_prices;")
    d.execute("drop table if exists USD_JPY_M1_metainf;")

    og = MSSQLGetter(OandaGetter("USD_JPY", "M1"))
    st = lib.str2epoch("2019/04/01 00:10", "%Y/%m/%d %H:%M")
    ed = lib.str2epoch("2019/04/01 00:15", "%Y/%m/%d %H:%M")
    t, o, h, l, c, v = og.getPrice(st, ed)

    og = MSSQLGetter(OandaGetter("USD_JPY", "M1"))
    st = lib.str2epoch("2019/03/31 23:55", "%Y/%m/%d %H:%M")
    ed = lib.str2epoch("2019/04/01 00:00", "%Y/%m/%d %H:%M")
    t, o, h, l, c, v = og.getPrice(st, ed)

    og = MSSQLGetter(OandaGetter("USD_JPY", "M1"))
    st = lib.str2epoch("2019/04/01 00:00", "%Y/%m/%d %H:%M")
    ed = lib.str2epoch("2019/04/01 00:05", "%Y/%m/%d %H:%M")
    t, o, h, l, c, v = og.getPrice(st, ed)

    og = MSSQLGetter(OandaGetter("USD_JPY", "M1"))
Ejemplo n.º 5
0
        l = [n] * size
        c = [n] * size
        v = [n] * size
        return (ep, o, h, l, c, v)


if __name__ == "__main__":
    import env
    from data_getter.oanda import OandaGetter
    env.run_mode = env.MODE_UNITTEST
    from db.mssql import MSSQLDB
    from data_getter.mssql import MSSQLGetter
    from data_getter.oanda import OandaGetter
    import lib
    d = MSSQLDB()

    d.execute("drop table if exists USD_JPY_H1_prices;")
    d.execute("drop table if exists USD_JPY_H1_metainf;")

    og = DataGetter(MSSQLGetter(OandaGetter("USD_JPY", "H1")))
    st = lib.str2epoch("2019/04/02 09:00", "%Y/%m/%d %H:%M")
    ed = lib.str2epoch("2019/04/02 17:00", "%Y/%m/%d %H:%M")

    og.retrievePrice(st, ed)

    st = lib.str2epoch("2019/04/02 11:00", "%Y/%m/%d %H:%M")
    ed = lib.str2epoch("2019/04/02 13:00", "%Y/%m/%d %H:%M")
    (t, o, h, l, c, v) = og.getPrice(st, ed)
    print(t)
    print(o)
Ejemplo n.º 6
0
class PandasGetter(DataGetter):
    def getPrice(self, startep, endep):
        (ep, o, h, l, c, v) = super(PandasGetter,
                                    self).getPrice(startep, endep)
        na = np.array([o, h, l, c, v])
        d = []
        for t in ep:
            d.append(lib.epoch2dt(t))

        df = pd.DataFrame(na.T, index=d, columns=["o", "h", "l", "c", "v"])
        return df


if __name__ == "__main__":
    from data_getter.mssql import MSSQLGetter
    from data_getter.oanda import OandaGetter

    env.run_mode = env.MODE_UNITTEST

    og = PandasGetter(MSSQLGetter(OandaGetter("USD_JPY", "H1")))

    st = lib.str2epoch("2019/04/02 07:00", "%Y/%m/%d %H:%M")
    ed = lib.str2epoch("2019/04/02 12:00", "%Y/%m/%d %H:%M")
    og.retrievePrice(st, ed)
    df = og.getPrice(st, ed)

    print(df)

    print("finished")