def serialize_object():
    oanda = OandaAPI(instrument='AUD_USD',
                     granularity='D',
                     settingf='../../data/settings.ini')

    oanda.run(start='2015-01-25T22:00:00', count=10)

    oanda.serialize_data(outfile="../../data/out.data")
Example #2
0
def test_serialize_data():
    '''
    test of function 'serialize_data'
    '''
    oanda = OandaAPI(instrument='AUD_USD',
                     granularity='D',
                     settingf='../../data/settings.ini')

    oanda.run(start='2015-01-25T22:00:00', count=10)

    oanda.serialize_data(outfile="../../data/out.data")
                 settingf=args.settingf)

period = None
if args.tf == "D":
    period = 24
else:
    period = int(args.tf.replace('H', ''))

candles = []
startO = datetime.datetime.strptime(str(args.start), '%Y-%m-%dT%H:%M:%S')
endO = datetime.datetime.strptime(str(args.end), '%Y-%m-%dT%H:%M:%S')
while startO < endO:
    start = startO.isoformat()
    startO = startO + datetime.timedelta(hours=int(args.no_candles) * period)
    if startO >= endO:
        if startO > datetime.datetime.now():
            end = (datetime.datetime.now() -
                   datetime.timedelta(days=2)).strftime('%Y-%m-%dT%H:%M:%S')
        else:
            end = endO.isoformat()
    else:
        end = startO.isoformat()
    print("Processing: {0}-{1}".format(start, end))
    oanda.run(start=start, end=end)
    candles = candles + oanda.data['candles']
    startO = startO + datetime.timedelta(hours=1 * period)

del oanda.data['candles']
oanda.data['candles'] = candles
oanda.serialize_data(outfile=args.outfile)