Add forcebuy and forcesell

This commit is contained in:
Matthias 2019-04-26 12:50:13 +02:00
parent bc4342b2d0
commit 6e4b159611
2 changed files with 44 additions and 2 deletions

View File

@ -123,9 +123,10 @@ class ApiServer(RPC):
methods=['GET', 'POST'])
app.add_url_rule('/whitelist', 'whitelist', view_func=self._whitelist,
methods=['GET'])
app.add_url_rule('/forcebuy', 'forcebuy', view_func=self._forcebuy, methods=['POST'])
app.add_url_rule('/forcesell', 'forcesell', view_func=self._forcesell, methods=['POST'])
# TODO: Implement the following
# forcebuy
# forcesell
# help (?)
def run(self):
@ -325,3 +326,23 @@ class ApiServer(RPC):
add = request.json.get("blacklist", None) if request.method == 'POST' else None
results = self._rpc_blacklist(add)
return self.rest_dump(results)
@safe_rpc
def _forcebuy(self):
"""
Handler for /forcebuy.
"""
asset = request.json.get("pair")
price = request.json.get("price", None)
trade = self._rpc_forcebuy(asset, price)
# TODO: Returns a trade, we need to jsonify that.
return self.rest_dump(trade)
@safe_rpc
def _forcesell(self):
"""
Handler for /forcesell.
"""
tradeid = request.json.get("tradeid")
results = self._rpc_forcesell(tradeid)
return self.rest_dump(results)

View File

@ -167,6 +167,27 @@ class FtRestClient():
else:
return self._post("blacklist", data={"blacklist": args})
def forcebuy(self, pair, price=None):
"""
Buy an asset
:param pair: Pair to buy (ETH/BTC)
:param price: Optional - price to buy
:returns: json object of the trade
"""
data = {"pair": pair,
"price": price
}
return self._post("forcebuy", data=data)
def forcesell(self, tradeid):
"""
Force-sell a trade
:param tradeid: Id of the trade (can be received via status command)
:returns: json object
"""
return self._post("forcesell", data={"tradeid": tradeid})
def add_arguments():
parser = argparse.ArgumentParser()