README: remove ERRORS, spelling and add timeframe comment

This commit is contained in:
JacobPlaster
2019-10-09 14:26:34 +01:00
committed by Jacob Plaster
parent 510f4ef28e
commit a9afd66449
2 changed files with 38 additions and 47 deletions

View File

@@ -82,47 +82,7 @@ def _parse_deriv_status_update(sData, symbol):
# placeholder # placeholder
} }
ERRORS = {
class BfxWebsocket(GenericWebsocket):
"""
More complex websocket that heavily relies on the btfxwss module.
This websocket requires authentication and is capable of handling orders.
https://github.com/Crypto-toolbox/btfxwss
### Subscribable events:
- `all` (array|json): listen for all messages coming through
- `connected:` () called when a connection is made
- `disconnected`: () called when a connection is ended (A reconnect attempt may follow)
- `stopped`: () called when max amount of connection retries is met and the socket is closed
- `authenticated` (): called when the websocket passes authentication
- `notification` (Notification): incoming account notification
- `error` (array): error from the websocket
- `order_closed` (Order, Trade): when an order has been closed
- `order_new` (Order, Trade): when an order has been created but not closed. Note: will not be called if order is executed and filled instantly
- `order_confirmed` (Order, Trade): When an order has been submitted and received
- `wallet_snapshot` (array[Wallet]): Initial wallet balances (Fired once)
- `order_snapshot` (array[Order]): Initial open orders (Fired once)
- `positions_snapshot` (array): Initial open positions (Fired once)
- `wallet_update` (Wallet): changes to the balance of wallets
- `status_update` (json): new platform status info
- `seed_candle` (json): initial past candle to prime strategy
- `seed_trade` (json): initial past trade to prime strategy
- `funding_offer_snapshot` (array): opening funding offer balances
- `funding_loan_snapshot` (array): opening funding loan balances
- `funding_credit_snapshot` (array): opening funding credit balances
- `balance_update` (array): when the state of a balance is changed
- `new_trade` (array): a new trade on the market has been executed
- `trade_update` (array): a trade on the market has been updated
- `new_candle` (array): a new candle has been produced
- `margin_info_updates` (array): new margin information has been broadcasted
- `funding_info_updates` (array): new funding information has been broadcasted
- `order_book_snapshot` (array): initial snapshot of the order book on connection
- `order_book_update` (array): a new order has been placed into the ordebrook
- `subscribed` (Subscription): a new channel has been subscribed to
- `unsubscribed` (Subscription): a channel has been un-subscribed
"""
ERRORS = {
10000: 'Unknown event', 10000: 'Unknown event',
10001: 'Generic error', 10001: 'Generic error',
10008: 'Concurrency error', 10008: 'Concurrency error',
@@ -144,7 +104,46 @@ class BfxWebsocket(GenericWebsocket):
20051: 'Websocket server stopping', 20051: 'Websocket server stopping',
20060: 'Websocket server resyncing', 20060: 'Websocket server resyncing',
20061: 'Websocket server resync complete' 20061: 'Websocket server resync complete'
} }
class BfxWebsocket(GenericWebsocket):
"""
More complex websocket that heavily relies on the btfxwss module.
This websocket requires authentication and is capable of handling orders.
https://github.com/Crypto-toolbox/btfxwss
### Emitter events:
- `all` (array|Object): listen for all messages coming through
- `connected:` () called when a connection is made
- `disconnected`: () called when a connection is ended (A reconnect attempt may follow)
- `stopped`: () called when max amount of connection retries is met and the socket is closed
- `authenticated` (): called when the websocket passes authentication
- `notification` (Notification): incoming account notification
- `error` (array): error from the websocket
- `order_closed` (Order, Trade): when an order has been closed
- `order_new` (Order, Trade): when an order has been created but not closed. Note: will not be called if order is executed and filled instantly
- `order_confirmed` (Order, Trade): When an order has been submitted and received
- `wallet_snapshot` (array[Wallet]): Initial wallet balances (Fired once)
- `order_snapshot` (array[Order]): Initial open orders (Fired once)
- `positions_snapshot` (array): Initial open positions (Fired once)
- `wallet_update` (Wallet): changes to the balance of wallets
- `status_update` (Object): new platform status info
- `seed_candle` (Object): initial past candle to prime strategy
- `seed_trade` (Object): initial past trade to prime strategy
- `funding_offer_snapshot` (array): opening funding offer balances
- `funding_loan_snapshot` (array): opening funding loan balances
- `funding_credit_snapshot` (array): opening funding credit balances
- `balance_update` (array): when the state of a balance is changed
- `new_trade` (array): a new trade on the market has been executed
- `trade_update` (array): a trade on the market has been updated
- `new_candle` (array): a new candle has been produced
- `margin_info_updates` (array): new margin information has been broadcasted
- `funding_info_updates` (array): new funding information has been broadcasted
- `order_book_snapshot` (array): initial snapshot of the order book on connection
- `order_book_update` (array): a new order has been placed into the ordebrook
- `subscribed` (Subscription): a new channel has been subscribed to
- `unsubscribed` (Subscription): a channel has been un-subscribed
"""
def __init__(self, API_KEY=None, API_SECRET=None, host='wss://api-pub.bitfinex.com/ws/2', def __init__(self, API_KEY=None, API_SECRET=None, host='wss://api-pub.bitfinex.com/ws/2',
manageOrderBooks=False, dead_man_switch=False, ws_capacity=25, logLevel='INFO', parse_float=float, manageOrderBooks=False, dead_man_switch=False, ws_capacity=25, logLevel='INFO', parse_float=float,
@@ -248,16 +247,16 @@ class BfxWebsocket(GenericWebsocket):
await self.subscriptionManager.confirm_unsubscribe(socket_id, data) await self.subscriptionManager.confirm_unsubscribe(socket_id, data)
async def _system_error_handler(self, socketId, data): async def _system_error_handler(self, socketId, data):
err_string = self.ERRORS[data.get('code', 10000)] err_string = ERRORS[data.get('code', 10000)]
err_string = "(socketId={}) {} - {}".format( err_string = "(socketId={}) {} - {}".format(
socketId, socketId,
self.ERRORS[data.get('code', 10000)], ERRORS[data.get('code', 10000)],
data.get("msg", "")) data.get("msg", ""))
self._emit('error', err_string) self._emit('error', err_string)
async def _system_auth_handler(self, socketId, data): async def _system_auth_handler(self, socketId, data):
if data.get('status') == 'FAILED': if data.get('status') == 'FAILED':
raise AuthError(self.ERRORS[data.get('code')]) raise AuthError(ERRORS[data.get('code')])
else: else:
self._emit('authenticated', data) self._emit('authenticated', data)
self.logger.info("Authentication successful.") self.logger.info("Authentication successful.")
@@ -523,6 +522,7 @@ class BfxWebsocket(GenericWebsocket):
# Attributes # Attributes
@param symbol: the trading symbol i.e 'tBTCUSD' @param symbol: the trading symbol i.e 'tBTCUSD'
@param timeframe: resolution of the candle i.e 15m, 1h
""" """
return await self.subscribe('candles', symbol, timeframe=timeframe) return await self.subscribe('candles', symbol, timeframe=timeframe)

View File

@@ -23,8 +23,8 @@ More complex websocket that heavily relies on the btfxwss module.
This websocket requires authentication and is capable of handling orders. This websocket requires authentication and is capable of handling orders.
https://github.com/Crypto-toolbox/btfxwss https://github.com/Crypto-toolbox/btfxwss
### Subscribable events: ### Emitter events:
- `all` (array|json): listen for all messages coming through - `all` (array|Object): listen for all messages coming through
- `connected:` () called when a connection is made - `connected:` () called when a connection is made
- `disconnected`: () called when a connection is ended (A reconnect attempt may follow) - `disconnected`: () called when a connection is ended (A reconnect attempt may follow)
- `stopped`: () called when max amount of connection retries is met and the socket is closed - `stopped`: () called when max amount of connection retries is met and the socket is closed
@@ -38,9 +38,9 @@ https://github.com/Crypto-toolbox/btfxwss
- `order_snapshot` (array[Order]): Initial open orders (Fired once) - `order_snapshot` (array[Order]): Initial open orders (Fired once)
- `positions_snapshot` (array): Initial open positions (Fired once) - `positions_snapshot` (array): Initial open positions (Fired once)
- `wallet_update` (Wallet): changes to the balance of wallets - `wallet_update` (Wallet): changes to the balance of wallets
- `status_update` (json): new platform status info - `status_update` (Object): new platform status info
- `seed_candle` (json): initial past candle to prime strategy - `seed_candle` (Object): initial past candle to prime strategy
- `seed_trade` (json): initial past trade to prime strategy - `seed_trade` (Object): initial past trade to prime strategy
- `funding_offer_snapshot` (array): opening funding offer balances - `funding_offer_snapshot` (array): opening funding offer balances
- `funding_loan_snapshot` (array): opening funding loan balances - `funding_loan_snapshot` (array): opening funding loan balances
- `funding_credit_snapshot` (array): opening funding credit balances - `funding_credit_snapshot` (array): opening funding credit balances
@@ -55,16 +55,6 @@ https://github.com/Crypto-toolbox/btfxwss
- `subscribed` (Subscription): a new channel has been subscribed to - `subscribed` (Subscription): a new channel has been subscribed to
- `unsubscribed` (Subscription): a channel has been un-subscribed - `unsubscribed` (Subscription): a channel has been un-subscribed
## ERRORS
dict() -> new empty dictionary
dict(mapping) -> new dictionary initialized from a mapping object's
(key, value) pairs
dict(iterable) -> new dictionary initialized as if via:
d = {}
for k, v in iterable:
d[k] = v
dict(**kwargs) -> new dictionary initialized with the name=value pairs
in the keyword argument list. For example: dict(one=1, two=2)
## enable_flag ## enable_flag
```python ```python
BfxWebsocket.enable_flag(self, flag) BfxWebsocket.enable_flag(self, flag)
@@ -97,6 +87,7 @@ Subscribe to a candle data feed
__Attributes__ __Attributes__
- `@param symbol`: the trading symbol i.e 'tBTCUSD' - `@param symbol`: the trading symbol i.e 'tBTCUSD'
- `@param timeframe`: resolution of the candle i.e 15m, 1h
## subscribe_trades ## subscribe_trades
```python ```python