-
Notifications
You must be signed in to change notification settings - Fork 0
/
spot_market.py
57 lines (45 loc) · 2.05 KB
/
spot_market.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import time
from shared import *
import requests
# whole list of spot markets
def spot_markets_list():
return requests.request('GET', host + prefix + spot_currency_pairs_url, headers=headers).json()
'''
spot usdt markets-filtered from spot_market_list
param: quote - USDT/BTC/ETH
'''
def spot_quote_tradable_markets(spot_market_list):
return [quote_market for quote_market in spot_market_list if
quote_market.get('quote') in ('USDT', 'BTC', 'ETH') and quote_market['trade_status'] == 'tradable']
# spot ticker information to get last price of ticker
def spot_ticker_information(ticker=None):
query_param = f'currency_pair={ticker}' if ticker else ''
try:
spot_ticker_info = requests.request('GET', host + prefix + spot_ticker_info_url, headers=headers,
params=query_param).json()
return float(spot_ticker_info['last']) if ticker else spot_ticker_info
except Exception:
return False, False
# spot ticker order book to get low asks and high bids
def spot_order_book(ticker, order_initialized=False):
query_param = f'currency_pair={ticker}'
try:
ticker_order_book = requests.request('GET', host + prefix + spot_order_book_url + "?" + query_param,
headers=headers).json()
if order_initialized:
return ticker_order_book['asks'][0], ticker_order_book['bids'][0]
return ticker_order_book['asks'][0][0], ticker_order_book['bids'][0][0]
except Exception:
return 0, 0
# live spot ticker data(10s) to be used with live future data (close price as last_price)
def live_spot_data(ticker):
try:
query_param = {
'currency_pair': ticker,
'interval': '10s',
'limit': 1}
live_spot = requests.request('GET', host + prefix + spot_candlestick_url, params=query_param,
headers=headers).json()
return live_spot[0][2]
except Exception:
return 0