Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import sys
- import time
- import config
- import argparse
- import threading
- from BinanceAPI import *
- client = BinanceAPI(config.api_key, config.api_secret)
- parser = argparse.ArgumentParser()
- # parser.add_argument("--quantity", type=int, help="Buy/Sell Quantity", default=100)
- parser.add_argument("--coin", type=str, help="Market Symbol (Ex: XVG)", required=True)
- parser.add_argument("--basecoin", type=str, help="Market Symbol (Ex: BTC)", default="ETH")
- parser.add_argument("--percentFall", type=float, help="% Percent to which the value has to fluncate before action is taken.", default=3)
- parser.add_argument("--actionTime", type=float, help="Seconds between buy/sell attempts", default=0.1)
- # parser.add_argument("--loopTime", type=float, help="Seconds for loop between value checking", default=0.5)
- option = parser.parse_args()
- # _quantity = option.quantity
- _coin = option.coin
- _basecoin = option.basecoin
- _percentFall = option.percentFall
- _actionTime = option.actionTime
- # _loopTime = option.loopTime
- def getBalance(symbol):
- balance = client.get_account()["balances"]
- specBalance = balance['balances']
- for index, item in enumerate(specBalance):
- if item["asset"] == symbol : # coin to trade
- return item["free"]
- def getMinimumRule(symbol):
- if symbol == "BTC" :
- return 0.002
- # ADD MORE!
- def buy():
- while (1):
- order = client.buy_market(_coin + _basecoin, getBalance(_basecoin))
- if 'msg' in order:
- message("Error: " + order['msg'])
- print ("__Order(buy) placed: %s Id: %d, Price: %.8f, Quantity: %.8f" % (_coin + _basecoin, order['orderId'], order['price'], order['origQty']))
- time.sleep(_actionTime)
- qorder = client.query_order(_coin + _basecoin, order['orderId'])
- if qorder['orderId'] != None:
- if qorder['status'] == "FILLED":
- print ("____Order(buy) FILLED. Done.")
- break
- else:
- print ("____Order(buy) Not FILLED. Canceling order.")
- client.cancel(_coin + _basecoin, orderId)
- if getBalance(_basecoin) < getMinimumRule(_basecoin):
- print ("______Order(buy): No more %s." % (_basecoin))
- break
- def sell():
- while (1) :
- order = client.sell_market(_coin + _basecoin, getBalance(_coin))
- if 'msg' in order:
- message("Error: " + order['msg'])
- print ("__Order(sell): %s Id: %d, Price: %.8f, Quantity: %.8f" % (_coin + _basecoin, order['orderId'], order['price'], order['origQty']))
- time.sleep(_actionTime)
- qorder = client.query_order(_coin + _basecoin, order['orderId'])
- if qorder['orderId'] != None:
- if qorder['status'] == "FILLED" :
- print ("____Order(sell) FILLED. Done.")
- break
- else:
- print ("____Order(sell) Not FILLED. Canceling order.")
- client.cancel(_coin + _basecoin, orderId)
- if getBalance(_coin) < getMinimumRule(_coin):
- print ("______Order(sell): No more %s." % (_coin))
- break
- def main():
- print ("---- Welcome to PnDBot by au limbo ----")
- print ("-- Coin: %s" % (_coin))
- print ("-- Basecoin: %s" % (_basecoin))
- print ("-- Percent Fall: %i" % (_percentFall))
- print ("-- Action time: %f\n\n" % (_actionTime))
- buy()
- preValue = client.get_ticker(_coin + _basecoin)
- while (1) :
- value = client.get_ticker(_coin + _basecoin)
- print ("Value: %.8f, preValue: %.8f" % (value, preValue))
- if value + (value * _percentFall / 100) < preValue :
- sell()
- break
- elif value > preValue :
- preValue = client.get_ticker(_coin + _basecoin)
- time.sleep(_actionTime)
Advertisement
Add Comment
Please, Sign In to add comment