subscribing and redeeming
This commit is contained in:
parent
ef9262c9db
commit
7d5581bfff
|
|
@ -108,8 +108,25 @@ class earner:
|
||||||
|
|
||||||
def subscribe(self,amount):
|
def subscribe(self,amount):
|
||||||
print(f"{str(self.connector)} | Subscribing {amount} {self.currency}")
|
print(f"{str(self.connector)} | Subscribing {amount} {self.currency}")
|
||||||
|
available_product = self.connector.get_available_products(self.currency)
|
||||||
if True:
|
subscription = {}
|
||||||
|
if available_product["asset"]==self.currency:
|
||||||
|
#Every exchange has it own subscription method
|
||||||
|
if str(self.connector) in ["binance","kucoin"]:
|
||||||
|
subscription = self.connector.subscribe_product(available_product["productId"],amount)
|
||||||
|
elif str(self.connector)=="gateio":
|
||||||
|
min_rate = self.connector.get_min_rate(available_product["asset"])["min_rate"]
|
||||||
|
time.sleep(.5) #For the sake of the API
|
||||||
|
subscription = self.connector.subscribe_product(available_product["productId"],amount,min_rate)
|
||||||
|
elif str(self.connector)=="okx":
|
||||||
|
transfer = self.connector.transfer_to_funding(available_product["asset"],str(amount))
|
||||||
|
transfer_state = self.connector.get_transfer_state(transfer["transId"])
|
||||||
|
if "Success" in transfer_state:
|
||||||
|
subscription = self.connector.subscribe_product(available_product["productId"],amount)
|
||||||
|
else:
|
||||||
|
print(f"{str(self.connector)} - Transfer of funds failed!")
|
||||||
|
return 1
|
||||||
|
if "Success" in subscription:
|
||||||
self.last_subscription_time = time.time()
|
self.last_subscription_time = time.time()
|
||||||
return 0
|
return 0
|
||||||
return 1
|
return 1
|
||||||
|
|
@ -117,7 +134,27 @@ class earner:
|
||||||
|
|
||||||
def redeem(self,amount):
|
def redeem(self,amount):
|
||||||
print(f"{str(self.connector)} | Redeeming {amount} {self.currency}")
|
print(f"{str(self.connector)} | Redeeming {amount} {self.currency}")
|
||||||
if True:
|
available_product = self.connector.get_available_products(self.currency)
|
||||||
|
redemption = {}
|
||||||
|
if available_product["asset"]==self.currency:
|
||||||
|
if str(self.connector) in ["binance","gateio"]:
|
||||||
|
redemption = self.connector.redeem_product(available_product["productId"],amount=amount)
|
||||||
|
elif str(self.connector)=="kucoin":
|
||||||
|
position = self.connector.get_position(self.currency)
|
||||||
|
if "Error" not in position:
|
||||||
|
redemption = self.connector.redeem_product(position["orderId"],amount=amount)
|
||||||
|
else:
|
||||||
|
print(f"{str(self.connector)} - Position not found!")
|
||||||
|
return 1
|
||||||
|
elif str(self.connector)=="okx":
|
||||||
|
redemption_step = self.connector.redeem_product(self.currency, amount=amount)
|
||||||
|
if "Success" in redemption_step:
|
||||||
|
transfer_step = self.connector.transfer_to_trading(self.currency, redemption_step["amount"])
|
||||||
|
redemption = self.connector.get_transfer_state(transfer_step["transId"])
|
||||||
|
else:
|
||||||
|
print(f"{str(self.connector)} - Redemption failed!")
|
||||||
|
return 1
|
||||||
|
if "Sucess" in redemption:
|
||||||
self.last_redemption_time = time.time()
|
self.last_redemption_time = time.time()
|
||||||
return 0
|
return 0
|
||||||
return 1
|
return 1
|
||||||
|
|
|
||||||
6
main.py
6
main.py
|
|
@ -12,6 +12,7 @@ import time
|
||||||
import datetime
|
import datetime
|
||||||
import json
|
import json
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
import socket
|
||||||
|
|
||||||
|
|
||||||
def load_keys_from_db(file_name: str) -> list:
|
def load_keys_from_db(file_name: str) -> list:
|
||||||
|
|
@ -101,7 +102,7 @@ def main():
|
||||||
total_on_trading = sum([item.get_trading_balance() for item in earners])
|
total_on_trading = sum([item.get_trading_balance() for item in earners])
|
||||||
total_on_earning = sum([item.get_earning_balance() for item in earners])
|
total_on_earning = sum([item.get_earning_balance() for item in earners])
|
||||||
time_of_day = datetime.datetime.now().strftime('[%Y/%m/%d %H:%M:%S]')
|
time_of_day = datetime.datetime.now().strftime('[%Y/%m/%d %H:%M:%S]')
|
||||||
print(f"{time_of_day} | Version {version} | Total funds: {total_on_trading+total_on_earning:.2f} | Total on earn: {total_on_earning:.2f} ({total_on_earning/total_on_trading*100:.2f}%)")
|
print(f"{time_of_day} | Version {version} | Total funds: {total_on_trading+total_on_earning:.2f} | On earn: {total_on_earning:.2f} ({total_on_earning/total_on_trading*100:.2f}%)")
|
||||||
print(f"Uptime: {seconds_to_time(time.time()-start_time)} | Last subscription: {last_subscription_key} - {last_subscription_value} | Last redemption: {last_redemption_key} - {last_redemption_value}")
|
print(f"Uptime: {seconds_to_time(time.time()-start_time)} | Last subscription: {last_subscription_key} - {last_subscription_value} | Last redemption: {last_redemption_key} - {last_redemption_value}")
|
||||||
print(colors.blue+"="*80+colors.white)
|
print(colors.blue+"="*80+colors.white)
|
||||||
#Wait for next lap
|
#Wait for next lap
|
||||||
|
|
@ -391,11 +392,12 @@ Missing endpoints:
|
||||||
|
|
||||||
def run_API(port):
|
def run_API(port):
|
||||||
serve(earn_api, host="0.0.0.0", port=port)
|
serve(earn_api, host="0.0.0.0", port=port)
|
||||||
|
#earn_api.run(host="0.0.0.0", port=port)
|
||||||
|
|
||||||
|
|
||||||
if __name__=="__main__":
|
if __name__=="__main__":
|
||||||
|
|
||||||
version = "2025.01.07"
|
version = "2025.01.08"
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
|
|
||||||
with open("config.json") as f:
|
with open("config.json") as f:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue