我的代码如下:
from pymongo import MongoClient
client = MongoClient()
client = MongoClient('localhost', 27017)
db = client.local
orderbook = db.orderbook_update.find({'lastUpdated': 1538584913932}).limit(1)
for order in orderbook:
timestamp = order['lastUpdated']
timestamp = timestamp - (timestamp%60000)
timestamp_target = timestamp + 60000
orderbook_target = db.orderbook_update.find({'lastUpdated': {'$lt':timestamp_target}}).limit(1)
def to_millis(time):
return int(pd.to_datetime(time).value / 1000000)
print(timestamp_target)
for orderb in orderbook_target:
topAsk = orderb['asks'][0][0]
topBid = orderb['bids'][0][0]
conn = psycopg2.connect("dbname=monty user=postgres host=localhost password=postgres")
cur = conn.cursor()
cur.execute("SELECT * FROM binance.zrxeth_aggregated;")
row = cur.fetchall()
for r in row:
ts = to_millis(r[0])
ts_target = ts- (ts%60000)
if ts_target == timestamp_target:
query = 'INSERT INTO binance.zrxeth_aggregated(topBid,topAsk) VALUES (topBid,topAsk)'
print(query)
cur. execute(query)
conn.commit()
conn.close()
最后一个if永远都不为真,因为ts_target以毫秒为单位:1538589840000,timestamp_target以科学形式:1.53858492e+12
有谁知道如何将此数字转换为毫秒?谢谢!
答案 0 :(得分:4)
将其转换为float
或int
。那可能有用。
In [153]: a = 1.53858492e+12
In [154]: float(a)
Out[154]: 1538584920000.0
In [155]: int(a)
Out[155]: 1538584920000