-
Notifications
You must be signed in to change notification settings - Fork 5
/
tickers_latest.py
39 lines (35 loc) · 1.5 KB
/
tickers_latest.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
import requests
from concurrent.futures import ThreadPoolExecutor,as_completed
from log import logger
import time
import json
from constants import Constants
sigma = 3.862523415579312e-05
def place_order_if_condition_met(prices):
if prices['binance_bid'] and prices['huobi_ask']:
diff = abs(prices['binance_bid'] - prices['huobi_ask'])
if diff > 2 * sigma:
logger.info('here we need to take some positions')
elif diff < 0.1 * sigma:
logger.info('here we need to exit some positions')
if prices['binance_ask'] and prices['huobi_bid']:
diff = abs(prices['binance_ask'] - prices['huobi_bid'])
if diff > 2 * sigma:
logger.info('here we need to take some positions')
elif diff < 0.1 * sigma:
logger.info('here we need to exit some positions')
if __name__ == '__main__':
logger.info('main start')
while True:
url = Constants.AMBERDATA_BASE_MARKET + '/tickers/eth_btc/latest?exchange=binance,huobi'
headers = { 'x-api-key': Constants.AMBERDATA_API_KEY }
response = requests.get(url, headers=headers)
payload = response.json()['payload']
prices = {}
prices['binance_bid'] = payload['binance'].get('bid')
prices['binance_ask'] = payload['binance'].get('ask')
prices['huobi_bid'] = payload['huobi'].get('bid')
prices['huobi_ask'] = payload['huobi'].get('ask')
place_order_if_condition_met(prices)
time.sleep(60)
logger.info('main end')