Skip to content
This repository has been archived by the owner on Jul 20, 2020. It is now read-only.

Commit

Permalink
Merge pull request #17 from kjgd/master
Browse files Browse the repository at this point in the history
Improvements to formatters, better API spec compliance
  • Loading branch information
Nils Diefenbach authored Jan 24, 2018
2 parents dbb26c7 + c82e19f commit b0a5a50
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 62 deletions.
14 changes: 8 additions & 6 deletions hitbtc/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ def _on_message(self, ws, message):
else:
try:
method = decoded_message['method']
symbol = decoded_message['params'].pop('symbol')
params = decoded_message.pop('params')
symbol = decoded_message['params']['symbol']
params = decoded_message['params']
except Exception as e:
self.log.exception(e)
self.log.error(decoded_message)
Expand Down Expand Up @@ -148,10 +148,12 @@ def _handle_request_response(self, request, response):
# loop over item in response['result'] for:
# getSymbols, getTrades, getTradingBalance, getOrders
for item in response['result']:
try:
text += msg.format(**item)
except KeyError as e :
print("Formatter for method {} failed on item {} with KeyError {}... item keys {}".format(method, item, e, item.keys()))
# Don't print zero balances
if method is not 'getTradingBalance' or (float(item['available']) > 0 or float(item['reserved']) > 0):
try:
text += msg.format(**item)
except KeyError as e :
print("Formatter for method {} failed on item {} with KeyError {}... item keys {}".format(method, item, e, item.keys()))
self.log.info(text)
self.echo(text)
else:
Expand Down
79 changes: 23 additions & 56 deletions hitbtc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,66 +45,33 @@
'\tSide: {side}\n' \
'\tTimestamp: {timestamp}\n'

resp_get_active_orders = 'Trade ID ({id}):' \
'\tOrder type: {type}\n' \
'\tStatus: {status}\n' \
'\tPrice: {price}\n' \
'\tSize: {quantity}\n' \
'\tSide: {side}\n' \
'\tCumulative size: {cumQunatity}\n' \
'\tTime in Force: {timeInForce}\n' \
'\tCreated at: {timestamp}\n' \
'\tUpdated at: {timestamp}\n' \
'\tClient Order ID: {clientOrderId}\n' \
'\tOriginal Request Client Order ID: {originalRequestClientOrderId}\n' \
'\tReport type: {reportType}\n'

resp_get_trading_balance = 'Wallet: {currency}\n' \
'\tAvailable: {available}\n' \
'\tReserved: {reserved}\n'

resp_place_order = 'Successfully placed a new order via websocket!\n' \
'\tTrade ID ({id}):' \
'\t\tOrder type: {type}\n' \
'\t\tStatus: {status}\n' \
'\t\tPrice: {price}\n' \
order_report_template = 'Trade ID ({id}): \tStatus: {status}\n' \
'Order type: {type}' \
'\t\tPrice: {price}' \
'\t\tSize: {quantity}\n' \
'\t\tSide: {side}\n' \
'\t\tCumulative size: {cumQunatity}\n' \
'\t\tTime in Force: {timeInForce}\n' \
'\t\tCreated at: {timestamp}\n' \
'\t\tUpdated at: {timestamp}\n' \
'\t\tClient Order ID: {clientOrderId}\n' \
'\t\tReport type: {reportType}\n'
'Side: {side}\t' \
'\t\tCumulative size: {cumQuantity}' \
'\t\t\tTime in Force: {timeInForce}\n' \
'Created at: {createdAt}' \
'\t\t\t\t\tUpdated at: {updatedAt}\n' \
'Client Order ID: {clientOrderId}' \
'\t\t\t\tReport type: {reportType}'

resp_cancel_order = 'Successfully cancelled an order via websocket!\n' \
'\tTrade ID ({id}):' \
'\t\tOrder type: {type}\n' \
'\t\tStatus: {status}\n' \
'\t\tPrice: {price}\n' \
'\t\tSize: {quantity}\n' \
'\t\tSide: {side}\n' \
'\t\tCumulative size: {cumQunatity}\n' \
'\t\tTime in Force: {timeInForce}\n' \
'\t\tCreated at: {timestamp}\n' \
'\t\tUpdated at: {timestamp}\n' \
'\t\tClient Order ID: {clientOrderId}\n' \
'\t\tReport type: {reportType}\n'
original_request_clOrdID = 'Original Request Client Order ID: {originalRequestClientOrderId}'

resp_get_active_orders = order_report_template + original_request_clOrdID + '\n'


resp_get_trading_balance = 'Wallet: {currency}' \
'\t\tAvailable: {available}' \
'\t\tReserved: {reserved}\n'

resp_place_order = 'Successfully placed a new order via websocket!\n' + order_report_template + '\n'

resp_cancel_order = 'Successfully cancelled an order via websocket!\n' + order_report_template+ '\n'

resp_cancel_replace_order = 'Successfully replaced an order via websocket!\n' \
'\tTrade ID ({id}):' \
'\t\tOrder type: {type}\n' \
'\t\tStatus: {status}\n' \
'\t\tPrice: {price}\n' \
'\t\tSize: {quantity}\n' \
'\t\tSide: {side}\n' \
'\t\tCumulative size: {cumQunatity}\n' \
'\t\tTime in Force: {timeInForce}\n' \
'\t\tCreated at: {timestamp}\n' \
'\t\tUpdated at: {timestamp}\n' \
'\t\tClient Order ID: {clientOrderId}\n' \
'\t\tOriginal Request Client Order ID: {originalRequestClientOrderId}\n' \
'\t\tReport type: {reportType}\n'
resp_cancel_replace_order = 'Successfully replaced an order via websocket!\n' + order_report_template + original_request_clOrdID + '\n'

resp_subscribe_ticker = 'Succesfully subscribed to {symbol} ticker data!'
resp_subscribe_book = 'Succesfully subscribed to {symbol} order book data!'
Expand Down

0 comments on commit b0a5a50

Please sign in to comment.