-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathtmp_get_interferences.py
42 lines (34 loc) · 1.14 KB
/
tmp_get_interferences.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import collections
import datetime
import subprocess
import argparse
import psycopg2.extras
import time
from backtest.utils import connect_db
db = connect_db()
curr = db.cursor()
parser = argparse.ArgumentParser()
parser.add_argument('ID', type=int)
args = parser.parse_args()
curr.execute('SELECT start_block, end_block FROM block_samples WHERE priority = %s', (args.ID,))
start_block, end_block = curr.fetchone()
print(f'Querying for id={args.ID} from {start_block} to {end_block}')
curr.execute(
'''
INSERT INTO interference_edges (i1, i2)
SELECT c1.id, c2.id
FROM (SELECT * FROM candidate_arbitrage_campaigns WHERE gas_pricer = 'median' AND %s <= block_number_start and block_number_end <= %s) c1
JOIN (SELECT * FROM candidate_arbitrage_campaigns WHERE gas_pricer = 'median') c2 ON
int4range(c1.block_number_start, c1.block_number_end + 1) &&
int4range(c2.block_number_start, c2.block_number_end + 1)
AND
c1.id < c2.id
AND
c1.exchanges && c2.exchanges
WHERE c1.gas_pricer = 'median' AND
c2.gas_pricer = 'median'
''',
(start_block, end_block)
)
print('done')
db.commit()