In [2]:
# import scipy
import numpy as np
import matplotlib.pyplot as plt
import math
import pandas as pd
%matplotlib inline
In [60]:
TRADE_COLS = ['timestamp', 'symbol', 'side', 'price', 'size', 'tickDirection']
a = pd.read_csv('/Users/felipe/Downloads/20180701-trades.csv.gz')[TRADE_COLS].iloc[:5000]
a = a[a.price > 1]
a = a.query('symbol == "XBTUSD"')
a.timestamp = a.timestamp.apply(lambda s: pd.Timestamp(s.replace('D', 'T')))
a = a.set_index('timestamp')
In [65]:
a.to_csv('/Users/felipe/bitme/data/20180701-6h.csv.gz', compression='gzip')
In [64]:
a.index[-1] - a.index[0]
Out[64]:
In [66]:
'FELIPE'.lower()
Out[66]:
In [68]:
'felipe'[-10:]
Out[68]:
In [107]:
b = a.head(10).copy()
In [ ]:
In [ ]:
In [108]:
b
Out[108]:
In [109]:
def combine(x):
y = x.iloc[0].copy()
y['size'] = x['size'].sum()
return y
c = b.groupby(['timestamp','price']).apply(combine).reset_index('price', drop=True).drop(columns=['timestamp'])
In [102]:
c
Out[102]:
In [106]:
c.groupby(['price', 'timestamp']).apply(lambda x: x.iloc[0])
Out[106]:
In [181]:
c = a.resample('1min').agg({'symbol': 'last', 'price': 'ohlc', 'size': 'sum'})
In [184]:
c
Out[184]:
In [215]:
c.columns = c.columns.get_level_values(1)
In [216]:
c
Out[216]:
In [218]:
from collections import deque
import queue
In [221]:
q = queue.Queue()
In [223]:
a = deque([1,2,3])
In [225]:
for i in a:
print(i)
a.pop()
In [19]:
a = pd.read_csv('/Users/felipe/bitme/data/20180701-1h-trades.csv.gz')
b = pd.read_csv('/Users/felipe/bitme/data/20180701-1h-quotes.csv.gz')
In [34]:
a.index = pd.DatetimeIndex([pd.Timestamp(i) for i in a['timestamp']])
b.index = pd.DatetimeIndex([pd.Timestamp(i) for i in b['timestamp']])
b['askPrice'] = 6388
In [35]:
b[['bidPrice', 'askPrice']].plot()
a['price'].plot()
Out[35]:
In [33]:
b.loc[pd.
Timestamp('2018-07-01 00:00:57.237578')]
Out[33]:
In [28]:
def nearest(items, pivot):
return min(items, key=lambda x: abs(x - pivot))
In [ ]: