Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/whittlem/pycryptobot into main
Browse files Browse the repository at this point in the history
  • Loading branch information
whittlem committed May 13, 2021
2 parents 6a45a22 + e9c99e9 commit c273006
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
4 changes: 2 additions & 2 deletions models/PyCryptoBot.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
parser.add_argument('--verbose', type=int, help='verbose output=1, minimal output=0')
parser.add_argument('--config', type=str, help="Use the config file at the given location. e.g 'myconfig.json'")
parser.add_argument('--logfile', type=str, help="Use the log file at the given location. e.g 'mymarket.log'")
parser.add_argument('--buypercent', type=str, help="percentage of quote currency to buy")
parser.add_argument('--sellpercent', type=str, help="percentage of base currency to sell")
parser.add_argument('--buypercent', type=int, help="percentage of quote currency to buy")
parser.add_argument('--sellpercent', type=int, help="percentage of base currency to sell")
parser.add_argument('--lastaction', type=str, help="optionally set the last action (BUY, SELL)")

# optional options
Expand Down
34 changes: 19 additions & 15 deletions pycryptobot.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,25 @@

account = TradingAccount(app)

if account.getBalance(app.getBaseCurrency()) < account.getBalance(app.getQuoteCurrency()):
state.last_action = 'SELL'
elif account.getBalance(app.getBaseCurrency()) > account.getBalance(app.getQuoteCurrency()):
state.last_action = 'BUY'
orders = account.getOrders(app.getMarket(), '', 'done')
if len(orders) > 0:
df = orders[-1:]

if str(df.action.values[0]) == 'buy':
state.last_action = 'BUY'
state.last_buy_size = float(df[df.action == 'buy']['size'])
state.last_buy_filled = float(df[df.action == 'buy']['filled'])
state.last_buy_price = float(df[df.action == 'buy']['price'])
state.last_buy_fee = round(state.last_buy_filled * state.last_buy_price * app.getTakerFee(), 2)
else:
state.last_action = 'SELL'
state.last_buy_price = 0.0
else:
# If we do not have any orders, pick last action based on balance
if account.getBalance(app.getBaseCurrency()) < account.getBalance(app.getQuoteCurrency()):
state.last_action = 'SELL'
elif account.getBalance(app.getBaseCurrency()) > account.getBalance(app.getQuoteCurrency()):
state.last_action = 'BUY'

if app.getExchange() == 'binance':
if state.last_action == 'SELL' and account.getBalance(app.getQuoteCurrency()) < 0.001:
Expand All @@ -65,17 +80,6 @@
elif state.last_action == 'BUY' and account.getBalance(app.getBaseCurrency()) < 0.001:
raise Exception('Insufficient available funds to place sell order: ' + str(account.getBalance(app.getBaseCurrency())) + ' < 0.1 ' + app.getBaseCurrency() + "\nNote: A manual limit order places a hold on available funds.")

orders = account.getOrders(app.getMarket(), '', 'done')
if len(orders) > 0:
df = orders[-1:]

if str(df.action.values[0]) == 'buy':
state.last_buy_size = float(df[df.action == 'buy']['size'])
state.last_buy_filled = float(df[df.action == 'buy']['filled'])
state.last_buy_price = float(df[df.action == 'buy']['price'])
state.last_buy_fee = round(state.last_buy_filled * state.last_buy_price * app.getTakerFee(), 2)
else:
state.last_buy_price = 0.0

def calculateMargin(buy_size: float=0.0, buy_filled: int=0.0, buy_price: int=0.0, buy_fee: float=0.0, sell_percent: float=100, sell_price: float=0.0, sell_fee: float=0.0, sell_taker_fee: float=0.0, debug: bool=False) -> float:
if debug is True:
Expand Down

0 comments on commit c273006

Please sign in to comment.