Advertisement
Guest User

Python Transaction Object Sample

a guest
Oct 9th, 2017
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.53 KB | None | 0 0
  1. class Transaction:
  2.     start_time=None
  3.     def __init__(self,currency,stop_loss,volume):
  4.         self.currency=currency
  5.         self.stop_loss=stop_loss
  6.         self.volume=volume
  7.         self.profitability=None
  8.     def realise(self): #Series of instructions to realise transaction for each Capital way it will be different
  9.         self.transaction_starttime=datetime.datetime.now()
  10.         raise NotImplementedError("Transaction class is only a template. Subclass must implement abstract method")
  11.     def stop(self): #stop transaction in case if profitability changes to an unwanted value parameter stop_loss
  12.         raise NotImplementedError("Transaction class is only a template. Subclass must implement abstract method")
  13.     def prof_watchdog(self): #check if transaction is still profitable on each realising step
  14.         if self.profitability>=self.stop_loss:
  15.             return True
  16.         else:
  17.             return False
  18.     def conclude(self): #Update Balance and transaction history to json file
  19.         duration_time=json.loads(open("UserDedicatedJsonData/TransactionsTime.json", "r").read())
  20.  
  21.         duration_time[self.__str__()][len(duration_time[self.__str__()])+1]=datetime.timedelta(datetime.datetime.now(),self.transaction_starttime)
  22.  
  23.         with open('UserDedicatedJsonData/TransactionsTime.json', 'w+') as outfile:
  24.             json.dump(duration_time, outfile)
  25.  
  26.         self.transaction_starttime=0
  27.         raise NotImplementedError("Transaction class is only a template. Subclass must implement abstract method")
  28.     def update_prof(self):
  29.         raise NotImplementedError("Transaction class is only a template. Subclass must implement abstract method")
  30.     def get_profitability(self):
  31.         return self.profitability
  32.  
  33. class KrakenBitbayTransaction(Transaction):
  34.     def __init__(self,currency,stop_loss,volume):
  35.         Transaction.__init__(self,currency,stop_loss,volume)
  36.         self.profitability=Count_Circuit_Profitability.count_kraken_bitbay(self.volume,self.currency)
  37.     def __str__(self):
  38.         return "KrakenBitbayTransaction"+str(self.currency)
  39.     def realise(self): #TODO this method is still as pseudocode
  40.         currency_balance=KrakenPrivateMethods.KrakenPrivateAPI.getBalance()['$currency']
  41.         KrakenPrivateMethods.KrakenPrivateAPI.AddBuyOrder(self,
  42.             str(self.currency)+"EUR",HTTP_GET_DATA.kraken_BTCEUR,KrakenPrivateMethods.KrakenPrivateAPI.getBalance())
  43.     def update_prof(self):
  44.         self.profitability=Count_Circuit_Profitability.count_kraken_bitbay(self.volume,self.currency)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement