From 427e99710e6e219d0ae20046f975395b24e3f575 Mon Sep 17 00:00:00 2001 From: JOlson Date: Sat, 9 May 2020 16:37:38 +1200 Subject: [PATCH] Fix docstring, comment typos --- bfxapi/models/deposit_address.py | 4 +++- bfxapi/models/notification.py | 4 +++- bfxapi/models/order.py | 6 ++++-- bfxapi/models/position.py | 4 +++- bfxapi/models/subscription.py | 4 ++-- bfxapi/models/transfer.py | 4 +++- bfxapi/models/withdraw.py | 4 +++- bfxapi/tests/test_ws_capacity.py | 6 +++--- bfxapi/tests/test_ws_orderbook.py | 4 ++-- bfxapi/tests/test_ws_orders.py | 22 +++++++++++----------- bfxapi/tests/test_ws_subscriptions.py | 6 +++--- bfxapi/utils/auth.py | 2 +- bfxapi/utils/custom_logger.py | 10 +++++----- bfxapi/websockets/bfx_websocket.py | 2 +- bfxapi/websockets/generic_websocket.py | 2 +- bfxapi/websockets/order_manager.py | 9 +++------ bfxapi/websockets/subscription_manager.py | 2 +- 17 files changed, 52 insertions(+), 43 deletions(-) diff --git a/bfxapi/models/deposit_address.py b/bfxapi/models/deposit_address.py index 02497de..c259b18 100644 --- a/bfxapi/models/deposit_address.py +++ b/bfxapi/models/deposit_address.py @@ -37,6 +37,8 @@ class DepositAddress: return DepositAddress(method, currency, address) def __str__(self): - ''' Allow us to print the Transfer object in a pretty format ''' + """ + Allow us to print the Transfer object in a pretty format + """ text = "DepositAddress <{} method={} currency={}>" return text.format(self.address, self.method, self.currency) diff --git a/bfxapi/models/notification.py b/bfxapi/models/notification.py index 84d91b5..e4a02c6 100644 --- a/bfxapi/models/notification.py +++ b/bfxapi/models/notification.py @@ -114,6 +114,8 @@ class Notification: return basic def __str__(self): - ''' Allow us to print the Notification object in a pretty format ''' + """ + Allow us to print the Notification object in a pretty format + """ text = "Notification <'{}' ({}) - {} notify_info={}>" return text.format(self.notify_type, self.status, self.text, self.notify_info) diff --git a/bfxapi/models/order.py b/bfxapi/models/order.py index 8b8a05d..1bb6928 100644 --- a/bfxapi/models/order.py +++ b/bfxapi/models/order.py @@ -209,7 +209,7 @@ class Order: """ Check if the order is still open - @return bool: Ture if order open else False + @return bool: True if order open else False """ return self.is_open_bool @@ -230,7 +230,9 @@ class Order: return self.is_confirmed_bool def __str__(self): - ''' Allow us to print the Order object in a pretty format ''' + """ + Allow us to print the Order object in a pretty format + """ text = "Order <'{}' amount_orig={} amount_filled={} mts_create={} status='{}' id={}>" return text.format(self.symbol, self.amount_orig, self.amount_filled, self.mts_create, self.status, self.id) diff --git a/bfxapi/models/position.py b/bfxapi/models/position.py index e748bd7..91ca2ae 100644 --- a/bfxapi/models/position.py +++ b/bfxapi/models/position.py @@ -100,7 +100,9 @@ class Position: lev, pid, mtsc, mtsu, ptype, coll, coll_min, meta) def __str__(self): - ''' Allow us to print the Trade object in a pretty format ''' + """ + Allow us to print the Trade object in a pretty format + """ text = "Position '{}' {} x {} " return text.format(self.symbol, self.base_price, self.amount, self.status, self.profit_loss) diff --git a/bfxapi/models/subscription.py b/bfxapi/models/subscription.py index 449b16e..55dfeba 100644 --- a/bfxapi/models/subscription.py +++ b/bfxapi/models/subscription.py @@ -18,7 +18,7 @@ class Subscription: """ Object used to represent an individual subscription to the websocket. This class also exposes certain functions which helps to manage the subscription - such as unsibscribe and subscribe. + such as unsubscribe and subscribe. """ def __init__(self, socket, channel_name, symbol, key=None, timeframe=None, **kwargs): @@ -49,7 +49,7 @@ class Subscription: async def unsubscribe(self): """ - Send an unsubscription request to the bitfinex socket + Send an un-subscription request to the bitfinex socket """ if not self.is_subscribed(): raise Exception("Subscription is not subscribed to websocket") diff --git a/bfxapi/models/transfer.py b/bfxapi/models/transfer.py index c6db63e..544250f 100644 --- a/bfxapi/models/transfer.py +++ b/bfxapi/models/transfer.py @@ -47,7 +47,9 @@ class Transfer: return Transfer(mts, wallet_from, wallet_to, currency_from, currency_to, amount) def __str__(self): - ''' Allow us to print the Transfer object in a pretty format ''' + """ + Allow us to print the Transfer object in a pretty format + """ text = "Transfer <{} from {} ({}) to {} ({}) mts={}>" return text.format(self.amount, self.wallet_from, self.currency_from, self.wallet_to, self.currency_to, self.mts) diff --git a/bfxapi/models/withdraw.py b/bfxapi/models/withdraw.py index 7b2d136..a13879d 100644 --- a/bfxapi/models/withdraw.py +++ b/bfxapi/models/withdraw.py @@ -45,7 +45,9 @@ class Withdraw: return Withdraw(w_id, method, wallet, amount) def __str__(self): - ''' Allow us to print the Withdraw object in a pretty format ''' + """ + Allow us to print the Withdraw object in a pretty format + """ text = "Withdraw " return text.format(self.id, self.wallet, self.method, self.amount, self.fee) diff --git a/bfxapi/tests/test_ws_capacity.py b/bfxapi/tests/test_ws_capacity.py index d7b28fb..48cdbf9 100644 --- a/bfxapi/tests/test_ws_capacity.py +++ b/bfxapi/tests/test_ws_capacity.py @@ -8,7 +8,7 @@ from .helpers import (create_stubbed_client, ws_publish_connection_init, ws_publ async def test_ws_creates_new_socket(): client = create_stubbed_client() client.ws.ws_capacity = 5 - # publsh connection created message + # publish connection created message await ws_publish_connection_init(client.ws) # create a bunch of websocket subscriptions for symbol in ['tXRPBTC', 'tLTCUSD']: @@ -25,12 +25,12 @@ async def test_ws_creates_new_socket(): async def test_ws_uses_authenticated_socket(): client = create_stubbed_client() client.ws.ws_capacity = 2 - # publsh connection created message + # publish connection created message await ws_publish_connection_init(client.ws) # create a bunch of websocket subscriptions for symbol in ['tXRPBTC', 'tLTCUSD', 'tETHBTC', 'tBTCUSD', 'tETHUSD', 'tLTCBTC']: await client.ws.subscribe('candles', symbol, timeframe='1m') - # publsh connection created message on socket (0 by default) + # publish connection created message on socket (0 by default) await ws_publish_connection_init(client.ws) # send auth accepted (on socket by default) await ws_publish_auth_accepted(client.ws) diff --git a/bfxapi/tests/test_ws_orderbook.py b/bfxapi/tests/test_ws_orderbook.py index cdeae1f..ebbee52 100644 --- a/bfxapi/tests/test_ws_orderbook.py +++ b/bfxapi/tests/test_ws_orderbook.py @@ -5,7 +5,7 @@ from .helpers import create_stubbed_client, ws_publish_connection_init, ws_publi async def test_checksum_generation(): client = create_stubbed_client() symbol = "tXRPBTC" - # publsh connection created message + # publish connection created message await ws_publish_connection_init(client.ws) # publish checksum flag accepted await ws_publish_conf_accepted(client.ws, 131072) @@ -37,7 +37,7 @@ async def test_checksum_generation(): async def test_checksum_really_samll_numbers_generation(): client = create_stubbed_client() symbol = "tVETBTC" - # publsh connection created message + # publish connection created message await ws_publish_connection_init(client.ws) # publish checksum flag accepted await ws_publish_conf_accepted(client.ws, 131072) diff --git a/bfxapi/tests/test_ws_orders.py b/bfxapi/tests/test_ws_orders.py index 23ee04e..b28a841 100644 --- a/bfxapi/tests/test_ws_orders.py +++ b/bfxapi/tests/test_ws_orders.py @@ -7,7 +7,7 @@ from .helpers import (create_stubbed_client, ws_publish_auth_accepted, ws_publis @pytest.mark.asyncio async def test_submit_order(): client = create_stubbed_client() - # publsh connection created message + # publish connection created message await ws_publish_connection_init(client.ws) ## send auth accepted await ws_publish_auth_accepted(client.ws) @@ -25,7 +25,7 @@ async def test_submit_order(): @pytest.mark.asyncio async def test_submit_update_order(): client = create_stubbed_client() - # publsh connection created message + # publish connection created message await ws_publish_connection_init(client.ws) ## send auth accepted await ws_publish_auth_accepted(client.ws) @@ -44,7 +44,7 @@ async def test_submit_update_order(): @pytest.mark.asyncio async def test_submit_cancel_order(): client = create_stubbed_client() - # publsh connection created message + # publish connection created message await ws_publish_connection_init(client.ws) ## send auth accepted await ws_publish_auth_accepted(client.ws) @@ -59,7 +59,7 @@ async def test_submit_cancel_order(): @pytest.mark.asyncio async def test_events_on_new_order(): client = create_stubbed_client() - # publsh connection created message + # publish connection created message await ws_publish_connection_init(client.ws) ## send auth accepted await ws_publish_auth_accepted(client.ws) @@ -94,7 +94,7 @@ async def test_events_on_new_order(): @pytest.mark.asyncio async def test_events_on_cancel_order(): client = create_stubbed_client() - # publsh connection created message + # publish connection created message await ws_publish_connection_init(client.ws) ## send auth accepted await ws_publish_auth_accepted(client.ws) @@ -114,7 +114,7 @@ async def test_events_on_cancel_order(): @pytest.mark.asyncio async def test_closed_callback_on_submit_order_closed(): client = create_stubbed_client() - # publsh connection created message + # publish connection created message await ws_publish_connection_init(client.ws) ## send auth accepted await ws_publish_auth_accepted(client.ws) @@ -131,7 +131,7 @@ async def test_closed_callback_on_submit_order_closed(): @pytest.mark.asyncio async def test_confirmed_callback_on_submit_order_closed(): client = create_stubbed_client() - # publsh connection created message + # publish connection created message await ws_publish_connection_init(client.ws) ## send auth accepted await ws_publish_auth_accepted(client.ws) @@ -147,7 +147,7 @@ async def test_confirmed_callback_on_submit_order_closed(): @pytest.mark.asyncio async def test_confirmed_callback_on_submit_new_order(): client = create_stubbed_client() - # publsh connection created message + # publish connection created message await ws_publish_connection_init(client.ws) ## send auth accepted await ws_publish_auth_accepted(client.ws) @@ -163,7 +163,7 @@ async def test_confirmed_callback_on_submit_new_order(): @pytest.mark.asyncio async def test_confirmed_callback_on_submit_order_update(): client = create_stubbed_client() - # publsh connection created message + # publish connection created message await ws_publish_connection_init(client.ws) ## send auth accepted await ws_publish_auth_accepted(client.ws) @@ -179,7 +179,7 @@ async def test_confirmed_callback_on_submit_order_update(): @pytest.mark.asyncio async def test_confirmed_callback_on_submit_cancel_order(): client = create_stubbed_client() - # publsh connection created message + # publish connection created message await ws_publish_connection_init(client.ws) ## send auth accepted await ws_publish_auth_accepted(client.ws) @@ -195,7 +195,7 @@ async def test_confirmed_callback_on_submit_cancel_order(): @pytest.mark.asyncio async def test_confirmed_callback_on_submit_cancel_group_order(): client = create_stubbed_client() - # publsh connection created message + # publish connection created message await ws_publish_connection_init(client.ws) ## send auth accepted await ws_publish_auth_accepted(client.ws) diff --git a/bfxapi/tests/test_ws_subscriptions.py b/bfxapi/tests/test_ws_subscriptions.py index 8c1313d..2928215 100644 --- a/bfxapi/tests/test_ws_subscriptions.py +++ b/bfxapi/tests/test_ws_subscriptions.py @@ -7,7 +7,7 @@ from .helpers import (create_stubbed_client, ws_publish_connection_init, EventWa async def test_submit_subscribe(): client = create_stubbed_client() symb = 'tXRPBTC' - # publsh connection created message + # publish connection created message await ws_publish_connection_init(client.ws) # Create new subscription to orderbook @@ -42,7 +42,7 @@ async def test_event_subscribe(): client = create_stubbed_client() symb = 'tXRPBTC' pair = 'XRPBTC' - # publsh connection created message + # publish connection created message await ws_publish_connection_init(client.ws) # create a new subscription await client.ws.subscribe('trades', symb) @@ -60,7 +60,7 @@ async def test_submit_unsubscribe(): client = create_stubbed_client() symb = 'tXRPBTC' pair = 'XRPBTC' - # publsh connection created message + # publish connection created message await ws_publish_connection_init(client.ws) # create new subscription to trades await client.ws.subscribe('trades', symb) diff --git a/bfxapi/utils/auth.py b/bfxapi/utils/auth.py index 097c88e..a83a2f0 100644 --- a/bfxapi/utils/auth.py +++ b/bfxapi/utils/auth.py @@ -12,7 +12,7 @@ def generate_auth_payload(API_KEY, API_SECRET): """ Generate a signed payload - @return json Oject headers + @return json Object headers """ nonce = _gen_nonce() authMsg, sig = _gen_signature(API_KEY, API_SECRET, nonce) diff --git a/bfxapi/utils/custom_logger.py b/bfxapi/utils/custom_logger.py index 6ae38c3..7411ccb 100644 --- a/bfxapi/utils/custom_logger.py +++ b/bfxapi/utils/custom_logger.py @@ -37,7 +37,7 @@ def formatter_message(message, use_color = True): def format_word(message, word, color_seq, bold=False, underline=False): """ - Surround the fiven word with a sequence + Surround the given word with a sequence """ replacer = color_seq + word + RESET_SEQ if underline: @@ -47,9 +47,9 @@ def format_word(message, word, color_seq, bold=False, underline=False): return message.replace(word, replacer) class Formatter(logging.Formatter): - ''' + """ This Formatted simply colors in the levelname i.e 'INFO', 'DEBUG' - ''' + """ def __init__(self, msg, use_color = True): logging.Formatter.__init__(self, msg) self.use_color = use_color @@ -66,10 +66,10 @@ class Formatter(logging.Formatter): return logging.Formatter.format(self, record) class CustomLogger(logging.Logger): - ''' + """ This adds extra logging functions such as logger.trade and also sets the logger to use the custom formatter - ''' + """ FORMAT = "[$BOLD%(name)s$RESET] [%(levelname)s] %(message)s" COLOR_FORMAT = formatter_message(FORMAT, True) TRADE = 50 diff --git a/bfxapi/websockets/bfx_websocket.py b/bfxapi/websockets/bfx_websocket.py index 89c10e0..a7d20bc 100644 --- a/bfxapi/websockets/bfx_websocket.py +++ b/bfxapi/websockets/bfx_websocket.py @@ -596,7 +596,7 @@ class BfxWebsocket(GenericWebsocket): Unsubscribe from the channel with the given chanId # Attributes - @param onComplete: function called when the bitfinex websocket resoponds with + @param onComplete: function called when the bitfinex websocket responds with a signal that confirms the subscription has been unsubscribed to """ return await self.subscriptionManager.unsubscribe(*args, **kwargs) diff --git a/bfxapi/websockets/generic_websocket.py b/bfxapi/websockets/generic_websocket.py index 134279f..91ef8f8 100644 --- a/bfxapi/websockets/generic_websocket.py +++ b/bfxapi/websockets/generic_websocket.py @@ -81,7 +81,7 @@ class GenericWebsocket: def run(self): """ - Starte the websocket connection. This functions spawns the initial socket + Start the websocket connection. This functions spawns the initial socket thread and connection. """ self._start_new_socket() diff --git a/bfxapi/websockets/order_manager.py b/bfxapi/websockets/order_manager.py index 9ec3c93..a35312f 100644 --- a/bfxapi/websockets/order_manager.py +++ b/bfxapi/websockets/order_manager.py @@ -55,9 +55,9 @@ class OrderManager: self.bfxapi._emit('order_closed', order) async def build_from_order_snapshot(self, raw_ws_data): - ''' + """ Rebuild the user orderbook based on an incoming snapshot - ''' + """ osData = raw_ws_data[2] self.open_orders = {} for raw_order in osData: @@ -206,10 +206,7 @@ class OrderManager: @param orderId: the id of the order that you want to update @param onConfirm: function called when the bitfinex websocket receives signal that the - order - was confirmed - @param onClose: function called when the bitfinex websocket receives signal that the order - was closed due to being filled or cancelled + order was confirmed """ self._create_callback(orderId, onConfirm, self.pending_cancel_confirm_callbacks) await self.bfxapi._send_auth_command('oc', {'id': orderId}) diff --git a/bfxapi/websockets/subscription_manager.py b/bfxapi/websockets/subscription_manager.py index 0a342f9..c90c073 100644 --- a/bfxapi/websockets/subscription_manager.py +++ b/bfxapi/websockets/subscription_manager.py @@ -146,7 +146,7 @@ class SubscriptionManager: # unsubscribe first and call callback to subscribe await self.unsubscribe(chan_id, re_sub) else: - # already unsibscribed, so just subscribe + # already unsubscribed, so just subscribe await sub.subscribe() def channel_count(self):