Skip to content

Commit 4651aff

Browse files
#31 refactor poloniex package
1 parent a4ed126 commit 4651aff

29 files changed

+176
-159
lines changed

binance/constants.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
BINANCE_GET_TICKER = "https://api.binance.com/api/v1/ticker/allBookTickers" # Yeah, it just return EVERYTHING
2+
BINANCE_GET_TICKER = "https://api.binance.com/api/v1/ticker/allBookTickers" # Yeah, it just return EVERYTHING
33

44
# OHLC ~ canddle stick urls
55
# https://api.binance.com/api/v1/klines?symbol=XMRETH&interval=15m&startTime=

binance/order_book_utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from enums.status import STATUS
1212

1313

14-
def get_order_book_binance_url(currency, timest):
14+
def get_order_book_binance_url(currency):
1515
# https://api.binance.com/api/v1/depth?symbol=XMRETH
1616
final_url = BINANCE_GET_ORDER_BOOK + currency
1717

@@ -23,7 +23,7 @@ def get_order_book_binance_url(currency, timest):
2323

2424
def get_order_book_binance(pair_name, timest):
2525

26-
final_url = get_order_book_binance_url(pair_name, timest)
26+
final_url = get_order_book_binance_url(pair_name)
2727

2828
err_msg = "get_order_book_binance called for {pair} at {timest}".format(pair=pair_name, timest=timest)
2929
error_code, r = send_request(final_url, err_msg)

binance/ticker_utils.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from enums.status import STATUS
1212

1313

14-
def get_tickers_binance_url(currency_names, timest):
14+
def get_tickers_binance_url(pair_name):
1515
final_url = BINANCE_GET_TICKER
1616

1717
if should_print_debug():
@@ -20,33 +20,33 @@ def get_tickers_binance_url(currency_names, timest):
2020
return final_url
2121

2222

23-
def get_tickers_binance(currency_names, timest):
23+
def get_tickers_binance(pair_name, timest):
2424

2525
"""
2626
{"symbol":"ETHBTC","bidPrice":"0.04039700","bidQty":"4.50700000","askPrice":"0.04047500","askQty":"1.30600000"},
2727
{"symbol":"LTCBTC","bidPrice":"0.00875700","bidQty":"0.24000000","askPrice":"0.00876200","askQty":"0.01000000"},
2828
29-
:param currency_names:
29+
:param pair_name:
3030
:param timest:
3131
:return:
3232
"""
3333

34-
final_url = get_tickers_binance_url(currency_names, timest)
34+
final_url = get_tickers_binance_url(pair_name)
3535

3636
err_msg = "get_tickers_binance called for list of pairS at {timest}".format(timest=timest)
3737
error_code, r = send_request(final_url, err_msg)
3838

3939
res = []
4040
if error_code == STATUS.SUCCESS and r is not None:
4141
for entry in r:
42-
if entry["symbol"] in currency_names:
42+
if entry["symbol"] in pair_name:
4343
res.append(Ticker.from_binance(entry["symbol"], timest, entry))
4444

4545
return res
4646

4747

4848
def get_ticker_binance(pair_name, timest):
49-
final_url = get_tickers_binance_url(pair_name, timest)
49+
final_url = get_tickers_binance_url(pair_name)
5050

5151
err_msg = "get_ticker_binance called for {pair} at {timest}".format(pair=pair_name, timest=timest)
5252
error_code, json_document = send_request(final_url, err_msg)

bittrex/ohlc_utils.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ def get_ohlc_bittrex_result_processor(json_document, pair_name, date_start, date
4040

4141
for record in json_document["result"]:
4242
new_candle = Candle.from_bittrex(record, pair_name)
43-
if new_candle.timest >= date_start: # NOTE: API V2 tend to ignore time parameter - so we have to filter it manually
43+
# NOTE: API V2 tend to ignore time parameter - so we have to filter it manually
44+
if new_candle.timest >= date_start:
4445
result_set.append(new_candle)
4546

4647
return result_set

bittrex/order_book_utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from enums.status import STATUS
1212

1313

14-
def get_order_book_bittrex_url(pair_name, timest):
14+
def get_order_book_bittrex_url(pair_name):
1515
# https://bittrex.com/api/v1.1/public/getorderbook?type=both&market=BTC-LTC
1616
final_url = BITTREX_GET_ORDER_BOOK + pair_name
1717

@@ -23,7 +23,7 @@ def get_order_book_bittrex_url(pair_name, timest):
2323

2424
def get_order_book_bittrex(pair_name, timest):
2525

26-
final_url = get_order_book_bittrex_url(pair_name, timest)
26+
final_url = get_order_book_bittrex_url(pair_name)
2727

2828
err_msg = "get_order_book_bittrex called for {pair} at {timest}".format(pair=pair_name, timest=timest)
2929
error_code, r = send_request(final_url, err_msg)

bittrex/ticker_utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from enums.status import STATUS
1313

1414

15-
def get_ticker_bittrex_url(pair_name, timest):
15+
def get_ticker_bittrex_url(pair_name):
1616
# https://bittrex.com/api/v1.1/public/getticker?market=BTC-LTC
1717
final_url = BITTREX_GET_TICKER + pair_name
1818

@@ -24,7 +24,7 @@ def get_ticker_bittrex_url(pair_name, timest):
2424

2525
def get_ticker_bittrex(pair_name, timest):
2626

27-
final_url = get_ticker_bittrex_url(pair_name, timest)
27+
final_url = get_ticker_bittrex_url(pair_name)
2828

2929
err_msg = "get_ticker_bittrex called for {pair} at {timest}".format(pair=pair_name, timest=timest)
3030
error_code, json_document = send_request(final_url, err_msg)

dao/order_book_utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def get_order_book_speedup(date_start, date_end, processor):
5858
pair_name = get_currency_pair_name_by_exchange_id(pair_id, exchange_id)
5959
if pair_name:
6060
method_for_url = get_order_book_url_by_exchange_id(exchange_id)
61-
request_url = method_for_url(pair_name, date_end)
61+
request_url = method_for_url(pair_name)
6262
constructor = get_order_book_constructor_by_exchange_id(exchange_id)
6363

6464
order_book_async_requests.append(WorkUnit(request_url, constructor, pair_name, date_end))
@@ -77,7 +77,7 @@ def get_order_books_for_arbitrage_pair(cfg, date_end, processor):
7777
assert pair_name is None
7878

7979
method_for_url = get_order_book_url_by_exchange_id(exchange_id)
80-
request_url = method_for_url(pair_name, date_end)
80+
request_url = method_for_url(pair_name)
8181
constructor = get_order_book_constructor_by_exchange_id(exchange_id)
8282

8383
order_book_async_requests.append(WorkUnit(request_url, constructor, pair_name, date_end))

dao/ticker_utils.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@
2727
def get_ticker_constructor_by_exchange_id(exchange_id):
2828
"""
2929
Return functor that expect following arguments:
30-
json_array,
30+
json_document - response of exchange,
3131
exchange specific name of currency
32-
date_start
33-
date_end
32+
timest - current time
3433
It will return array of object from data/* folder
3534
"""
3635
return {
@@ -54,7 +53,7 @@ def get_ticker_speedup(timest, processor):
5453
continue
5554

5655
method_for_url = get_ticker_url_by_exchange_id(exchange_id)
57-
request_url = method_for_url(pair_name, timest)
56+
request_url = method_for_url(pair_name)
5857
constructor = get_ticker_constructor_by_exchange_id(exchange_id)
5958

6059
ohlc_async_requests.append(WorkUnit(request_url, constructor, pair_name, timest))
@@ -118,7 +117,7 @@ def get_ticker_for_arbitrage(pair_id, timest, exchange_list, processor):
118117
assert pair_name is None
119118

120119
method_for_url = get_ticker_url_by_exchange_id(exchange_id)
121-
request_url = method_for_url(pair_name, timest)
120+
request_url = method_for_url(pair_name)
122121
constructor = get_ticker_constructor_by_exchange_id(exchange_id)
123122

124123
async_requests.append(WorkUnit(request_url, constructor, pair_name, timest))

huobi/buy_utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from utils.file_utils import log_to_file
1212
from utils.string_utils import float_to_str
13-
from huobi.rest_api import generate_body_and_url_get_request, send_post_request_with
13+
from huobi.rest_api import generate_body_and_url_get_request, send_post_request_with_logging
1414

1515
BUY_URL = HUOBI_API_URL + HUOBI_BUY_ORDER + "?"
1616

@@ -45,4 +45,4 @@ def add_buy_order_huobi(key, pair_name, price, amount):
4545
err_msg = "add_buy_order_huobi called for {pair} for amount = {amount} with price {price}".format(
4646
pair=pair_name, amount=amount, price=price)
4747

48-
return send_post_request_with(post_details, err_msg)
48+
return send_post_request_with_logging(post_details, err_msg)

huobi/market_utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from huobi.constants import HUOBI_CANCEL_ORDER, HUOBI_API_URL, HUOBI_API_ONLY, \
1111
HUOBI_POST_HEADERS
1212
from huobi.error_handling import is_error
13-
from huobi.rest_api import init_body, send_post_request_with
13+
from huobi.rest_api import init_body, send_post_request_with_logging
1414

1515

1616
def cancel_order_huobi(key, order_id):
@@ -41,7 +41,7 @@ def cancel_order_huobi(key, order_id):
4141

4242
err_msg = "cancel huobi order with id {id}".format(id=order_id)
4343

44-
return send_post_request_with(post_details, err_msg)
44+
return send_post_request_with_logging(post_details, err_msg)
4545

4646

4747
def parse_order_id_huobi(json_document):

huobi/order_book_utils.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
from enums.status import STATUS
1212

1313

14-
def get_order_book_huobi_url(pair_name, timest):
15-
#
14+
def get_order_book_huobi_url(pair_name):
1615
final_url = HUOBI_GET_ORDER_BOOK + pair_name + "&type=step0"
1716

1817
if should_print_debug():
@@ -23,7 +22,7 @@ def get_order_book_huobi_url(pair_name, timest):
2322

2423
def get_order_book_huobi(pair_name, timest):
2524

26-
final_url = get_order_book_huobi_url(pair_name, timest)
25+
final_url = get_order_book_huobi_url(pair_name)
2726

2827
err_msg = "get_order_book_huobi called for {pair} at {timest}".format(pair=pair_name, timest=timest)
2928
error_code, json_document = send_request(final_url, err_msg)

huobi/rest_api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def generate_body_and_url_get_request(key, base_url, path):
5252
return body, _urlencode(body)
5353

5454

55-
def send_post_request_with(post_details, err_msg):
55+
def send_post_request_with_logging(post_details, err_msg):
5656
res = send_post_request_with_header(post_details, err_msg, max_tries=HUOBI_NUM_OF_DEAL_RETRY,
5757
timeout=HUOBI_DEAL_TIMEOUT)
5858

huobi/sell_utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from huobi.constants import HUOBI_SELL_ORDER, HUOBI_API_URL, HUOBI_API_ONLY, HUOBI_POST_HEADERS
44
from huobi.account_utils import get_huobi_account
5-
from huobi.rest_api import generate_body_and_url_get_request, send_post_request_with
5+
from huobi.rest_api import generate_body_and_url_get_request, send_post_request_with_logging
66

77
from data_access.classes.post_request_details import PostRequestDetails
88
from utils.string_utils import float_to_str
@@ -34,4 +34,4 @@ def add_sell_order_huobi(key, pair_name, price, amount):
3434
err_msg = "add_sell_order huobi called for {pair} for amount = {amount} with price {price}".format(
3535
pair=pair_name, amount=amount, price=price)
3636

37-
return send_post_request_with(post_details, err_msg)
37+
return send_post_request_with_logging(post_details, err_msg)

huobi/ticker_utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from enums.status import STATUS
1313

1414

15-
def get_ticker_huobi_url(pair_name, timest):
15+
def get_ticker_huobi_url(pair_name):
1616
final_url = HUOBI_GET_TICKER + pair_name
1717

1818
if should_print_debug():
@@ -23,7 +23,7 @@ def get_ticker_huobi_url(pair_name, timest):
2323

2424
def get_ticker_huobi(pair_name, timest):
2525

26-
final_url = get_ticker_huobi_url(pair_name, timest)
26+
final_url = get_ticker_huobi_url(pair_name)
2727

2828
err_msg = "get_ticker_huobi called for {pair} at {timest}".format(pair=pair_name, timest=timest)
2929
error_code, json_document = send_request(final_url, err_msg)

kraken/order_book_utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from debug_utils import print_to_console, LOG_ALL_DEBUG, ERROR_LOG_FILE_NAME, should_print_debug
1313

1414

15-
def get_order_book_kraken_url(pair_name, timest):
15+
def get_order_book_kraken_url(pair_name):
1616
# https://api.kraken.com/0/public/Depth?pair=XETHXXBT
1717
final_url = KRAKEN_GET_ORDER_BOOK + pair_name
1818

@@ -24,7 +24,7 @@ def get_order_book_kraken_url(pair_name, timest):
2424

2525
def get_order_book_kraken(pair_name, timest):
2626

27-
final_url = get_order_book_kraken_url(pair_name, timest)
27+
final_url = get_order_book_kraken_url(pair_name)
2828

2929
err_msg = "get_order_book_kraken called for {pair} at {timest}".format(pair=pair_name, timest=timest)
3030
error_code, json_document = send_request(final_url, err_msg)

kraken/ticker_utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from utils.file_utils import log_to_file
1212

1313

14-
def get_ticker_kraken_url(pair_name, timest):
14+
def get_ticker_kraken_url(pair_name):
1515
# https://api.kraken.com/0/public/Ticker?pair=DASHXBT
1616
final_url = KRAKEN_GET_TICKER + pair_name
1717

@@ -23,7 +23,7 @@ def get_ticker_kraken_url(pair_name, timest):
2323

2424
def get_ticker_kraken(pair_name, timest):
2525

26-
final_url = get_ticker_kraken_url(pair_name, timest)
26+
final_url = get_ticker_kraken_url(pair_name)
2727

2828
err_msg = "get_ticker_kraken called for {pair} at {timest}".format(pair=pair_name, timest=timest)
2929
error_code, json_document = send_request(final_url, err_msg)

management/classes/ProcessDetails.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
class ProcessDetails():
2+
class ProcessDetails(object):
33
def __init__(self, cmd, pid):
44
self.cmd = cmd
55
self.pid = pid
@@ -10,4 +10,4 @@ def get_pair_id(self):
1010

1111
def _parse_cmd(self, cmd):
1212
# FIXME NOTE parsing
13-
return ""
13+
return ""

management/classes/ServerDetails.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
class ServerDetails():
1+
# FIXME NOTE: https://unix.stackexchange.com/questions/267478/getting-public-ip-address-of-ec2-instance-from-outside-using-aws-cli
2+
3+
4+
class ServerDetails(object):
25
def __init__(self, server_name, server_id):
36
self.server_name = server_name
4-
self.server_id = server_id
5-
6-
# FIXME NOTE: https://unix.stackexchange.com/questions/267478/getting-public-ip-address-of-ec2-instance-from-outside-using-aws-cli
7+
self.server_id = server_id

management/monitoring.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ def register_node(config):
88

99
# enter data to the redis
1010

11+
"""
1112
12-
13-
14-
13+
:param config:
14+
:return:
15+
"""

poloniex/buy_utils.py

+6-20
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,16 @@
1-
from poloniex.constants import POLONIEX_BUY_ORDER, POLONIEX_NUM_OF_DEAL_RETRY, POLONIEX_DEAL_TIMEOUT
1+
from poloniex.constants import POLONIEX_BUY_ORDER
2+
from poloniex.rest_api import generate_body, send_post_request_with_logging
23

34
from data_access.classes.post_request_details import PostRequestDetails
4-
from data_access.internet import send_post_request_with_header
5-
from data_access.memory_cache import generate_nonce
65

76
from debug_utils import print_to_console, LOG_ALL_MARKET_RELATED_CRAP, get_logging_level
87

98
from utils.file_utils import log_to_file
109
from utils.key_utils import signed_body
11-
from utils.string_utils import float_to_str
1210

1311

1412
def add_buy_order_poloniex_url(key, pair_name, price, amount):
15-
body = {
16-
"command": "buy",
17-
"currencyPair": pair_name,
18-
"rate": float_to_str(price),
19-
"amount": float_to_str(amount),
20-
"nonce": generate_nonce()
21-
}
13+
body = generate_body(pair_name, price, amount, "buy")
2214

2315
headers = {"Key": key.api_key, "Sign": signed_body(body, key.secret)}
2416
# https://poloniex.com/tradingApi
@@ -38,13 +30,7 @@ def add_buy_order_poloniex(key, pair_name, price, amount):
3830

3931
post_details = add_buy_order_poloniex_url(key, pair_name, price, amount)
4032

41-
err_msg = "add_buy_order poloniex called for {pair} for amount = {amount} with price {price}".format(pair=pair_name, amount=amount, price=price)
33+
err_msg = "add_buy_order poloniex called for {pair} for amount = {amount} with price {price}".format(
34+
pair=pair_name, amount=amount, price=price)
4235

43-
res = send_post_request_with_header(post_details, err_msg,
44-
max_tries=POLONIEX_NUM_OF_DEAL_RETRY, timeout=POLONIEX_DEAL_TIMEOUT)
45-
46-
if get_logging_level() >= LOG_ALL_MARKET_RELATED_CRAP:
47-
print_to_console(res, LOG_ALL_MARKET_RELATED_CRAP)
48-
log_to_file(res, "market_utils.log")
49-
50-
return res
36+
return send_post_request_with_logging(post_details, err_msg)

0 commit comments

Comments
 (0)