Skip to content

Sourcery refactored master branch #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions thewife/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ def main():
parameter['upper']):
trade.sell()
break
else:
pass
Comment on lines -90 to -91
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:

except KeyboardInterrupt:
quit()

Expand Down
11 changes: 3 additions & 8 deletions thewife/indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ def compute_profit(params):
logger.info('\tPeriod: ' + str(params['period']))
logger.info('\tLower threshold: ' + str(params['lower']))
logger.info('\tUpper threshold: ' + str(params['upper']))
else:
pass

Comment on lines -92 to -94
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Indicator.__optimize_signal refactored with the following changes:

data = self.__compute_indicator(
period=params['period'],
lower=params['lower'],
Expand Down Expand Up @@ -185,10 +182,8 @@ def indicator(self):
# refresh candlestick
self.ohlcv = self.__fetch_ohlcv()

# compute signal with best parameter
data = self.__compute_indicator(
return self.__compute_indicator(
period=self.setting['parameter']['period'],
lower=self.setting['parameter']['lower'],
upper=self.setting['parameter']['upper'])

return data
upper=self.setting['parameter']['upper'],
)
Comment on lines -188 to +189
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Indicator.indicator refactored with the following changes:

This removes the following comments ( why? ):

# compute signal with best parameter

134 changes: 107 additions & 27 deletions thewife/trade.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,31 @@ def amount(x):
price = self.__buy_price

try:
logger.info('Attempt to buy ' + target + ' @ ' +
'{0:.8f}'.format(price) + ' ' + base)

self.__notify('Attempt to BUY ' + target + ' @ ' +
'{0:.8f}'.format(price) + ' ' + base)
logger.info(
(
(
(
f'Attempt to buy {target} @ '
+ '{0:.8f}'.format(price)
)
+ ' '
)
+ base
)
)

self.__notify(
(
(
(
f'Attempt to BUY {target} @ '
+ '{0:.8f}'.format(price)
)
+ ' '
)
+ base
)
)
Comment on lines -65 to +89
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Trade.buy refactored with the following changes:


left = self.funds
order = auth.create_limit_buy_order(self.pair,
Expand All @@ -81,7 +101,7 @@ def amount(x):

remaining = order_status['remaining']
left = abs(left - order_status['cost'])
logger.info('Remaining: ' + str(remaining))
logger.info(f'Remaining: {str(remaining)}')

if (remaining != 0.0 or remaining != 0):
logger.info('Buy order was partially filled')
Expand All @@ -93,22 +113,42 @@ def amount(x):

price = self.__buy_price

logger.info('Attempt to buy ' + target + ' @ ' +
'{0:.8f}'.format(price) + ' ' + base)
logger.info(
(
(
(
f'Attempt to buy {target} @ '
+ '{0:.8f}'.format(price)
)
+ ' '
)
+ base
)
)

order = auth.create_limit_buy_order(
order_status['symbol'], amount(left), price)
elif (remaining == 0.0 or remaining == 0):
logger.info('Successfully bought ' + target)
self.__notify('Successfully bought ' + target + ' @ ' +
'{0:.8f}'.format(price) + ' ' + base)
elif remaining in [0.0, 0]:
logger.info(f'Successfully bought {target}')
self.__notify(
(
(
(
f'Successfully bought {target} @ '
+ '{0:.8f}'.format(price)
)
+ ' '
)
+ base
)
)
break

sleep(self.refreshrate)
except (ccxt.InvalidOrder, ccxt.InsufficientFunds):
logger.info('Invalid order or quantity')
logger.info('Funds: ' + str(self.funds))
logger.info('Amount: ' + str(amount(self.funds)))
logger.info(f'Funds: {str(self.funds)}')
logger.info(f'Amount: {str(amount(self.funds))}')
except Exception as e:
logger.exception(e)

Expand All @@ -132,11 +172,31 @@ def balance():
price = self.__sell_price

try:
logger.info('Attempt to sell ' + target + ' @ ' +
'{0:.8f}'.format(price) + ' ' + base)

self.__notify('Attempt to SELL ' + target + ' @ ' +
'{0:.8f}'.format(price) + ' ' + base)
logger.info(
(
(
(
f'Attempt to sell {target} @ '
+ '{0:.8f}'.format(price)
)
+ ' '
)
+ base
)
)

self.__notify(
(
(
(
f'Attempt to SELL {target} @ '
+ '{0:.8f}'.format(price)
)
+ ' '
)
+ base
)
)
Comment on lines -135 to +199
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Trade.sell refactored with the following changes:


order = auth.create_limit_sell_order(self.pair, balance(),
price)
Expand All @@ -150,7 +210,7 @@ def balance():
id=order_id, symbol=self.pair)

remaining = order_status['remaining']
logger.info('Remaining: ' + str(remaining))
logger.info(f'Remaining: {str(remaining)}')

if remaining != 0.0 or remaining != 0:
logger.info('Sell order was partially filled')
Expand All @@ -159,20 +219,40 @@ def balance():

price = self.__sell_price

logger.info('Attempt to sell ' + target + ' @ ' +
'{0:.8f}'.format(price) + ' ' + base)
logger.info(
(
(
(
f'Attempt to sell {target} @ '
+ '{0:.8f}'.format(price)
)
+ ' '
)
+ base
)
)

order = auth.create_limit_sell_order(
self.pair, balance(), price)
elif remaining == 0.0 or remaining == 0:
logger.info('Successfully sold ' + target)
self.__notify('Successfully sold ' + target + ' @ ' +
'{0:.8f}'.format(price) + ' ' + base)
elif remaining in [0.0, 0]:
logger.info(f'Successfully sold {target}')
self.__notify(
(
(
(
f'Successfully sold {target} @ '
+ '{0:.8f}'.format(price)
)
+ ' '
)
+ base
)
)
break

sleep(self.refreshrate)
except (ccxt.InvalidOrder, ccxt.InsufficientFunds):
logger.info('Invalid order or quantity')
logger.info('Balance: ' + str(balance()))
logger.info(f'Balance: {str(balance())}')
except Exception as e:
logger.exception(e)