subscribe and redeem endpoints
This commit is contained in:
parent
b08f320fe1
commit
394c71035d
|
|
@ -120,9 +120,12 @@ class earner:
|
|||
return float(self.earning_balance)
|
||||
|
||||
|
||||
def subscribe(self,amount):
|
||||
def subscribe(self,amount,force_pause=False):
|
||||
print(f"{datetime.datetime.now().strftime('[%Y/%m/%d %H:%M:%S]')} | {str(self.connector).upper()} | Subscribing {amount} {self.currency}")
|
||||
self.write_to_log(f"Subscribing {amount} {self.currency}")
|
||||
|
||||
if force_pause:
|
||||
self.pause = True
|
||||
available_product = self.connector.get_available_products(self.currency)
|
||||
subscription = {}
|
||||
if available_product["coin"]==self.currency:
|
||||
|
|
@ -153,10 +156,12 @@ class earner:
|
|||
self.write_to_log("Subscription failed! - " + str(subscription))
|
||||
return 1
|
||||
|
||||
def redeem(self,amount):
|
||||
#Redeem
|
||||
def redeem(self,amount,force_pause=False):
|
||||
print(f"{datetime.datetime.now().strftime('[%Y/%m/%d %H:%M:%S]')} | {str(self.connector).upper()} | Redeeming {amount} {self.currency}")
|
||||
self.write_to_log(f"Redeeming {amount} {self.currency}")
|
||||
|
||||
if force_pause:
|
||||
self.pause = True
|
||||
available_product = self.connector.get_available_products(self.currency)
|
||||
redemption = {}
|
||||
if available_product["coin"]==self.currency:
|
||||
|
|
|
|||
59
main.py
59
main.py
|
|
@ -387,6 +387,65 @@ def get_total_balance():
|
|||
return jsonify({'Error': 'API key not valid'}), 401
|
||||
|
||||
|
||||
@earn_api.route("/subscribe", methods=["POST"])
|
||||
def subscribe():
|
||||
'''
|
||||
args:
|
||||
broker: broker name
|
||||
force_pause: True or False
|
||||
'''
|
||||
if "X-API-KEY" in request.headers and request.headers.get("X-API-KEY") in valid_keys:
|
||||
valid_brokers = [str(item.connector) for item in earners]
|
||||
if request.json is None:
|
||||
return jsonify({'Error': 'request.json is None'})
|
||||
broker = request.json["broker"]
|
||||
amount = request.json["amount"]
|
||||
force_pause = request.json["force_pause"]
|
||||
if broker is None:
|
||||
return jsonify({'Error': 'broker is None'})
|
||||
if broker not in valid_brokers:
|
||||
return jsonify({'Error': 'broker not valid'})
|
||||
if amount is None:
|
||||
return jsonify({'Error': 'amount is None'})
|
||||
if force_pause is None:
|
||||
return jsonify({'Error': 'force_pause is None'})
|
||||
for item in earners:
|
||||
if str(item.connector)==broker:
|
||||
subscription = item.subscribe(amount, force_pause=force_pause)
|
||||
return jsonify({'Success': str(subscription)})
|
||||
return jsonify({'Error': 'broker not found'})
|
||||
return jsonify({'Error': 'API key not valid'}), 401
|
||||
|
||||
|
||||
@earn_api.route("/redeem", methods=["POST"])
|
||||
def redeem():
|
||||
'''
|
||||
args:
|
||||
broker: broker name
|
||||
force_pause: True or False
|
||||
'''
|
||||
if "X-API-KEY" in request.headers and request.headers.get("X-API-KEY") in valid_keys:
|
||||
valid_brokers = [str(item.connector) for item in earners]
|
||||
if request.json is None:
|
||||
return jsonify({'Error': 'request.json is None'})
|
||||
broker = request.json["broker"]
|
||||
amount = request.json["amount"]
|
||||
force_pause = request.json["force_pause"]
|
||||
if broker is None:
|
||||
return jsonify({'Error': 'broker is None'})
|
||||
if broker not in valid_brokers:
|
||||
return jsonify({'Error': 'broker not valid'})
|
||||
if amount is None:
|
||||
return jsonify({'Error': 'amount is None'})
|
||||
if force_pause is None:
|
||||
return jsonify({'Error': 'force_pause is None'})
|
||||
for item in earners:
|
||||
if str(item.connector)==broker:
|
||||
subscription = item.redeem(amount, force_pause=force_pause)
|
||||
return jsonify({'Success': str(subscription)})
|
||||
return jsonify({'Error': 'broker not found'})
|
||||
return jsonify({'Error': 'API key not valid'}), 401
|
||||
|
||||
|
||||
def run_API(port):
|
||||
serve(earn_api, host="0.0.0.0", port=port)
|
||||
|
|
|
|||
Loading…
Reference in New Issue