moved things to a new place !
This commit is contained in:
145
notebooks/autogen/dealManager.py
Normal file
145
notebooks/autogen/dealManager.py
Normal file
@@ -0,0 +1,145 @@
|
||||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
# In[1]:
|
||||
|
||||
|
||||
import pandas as pd
|
||||
import datetime
|
||||
import numpy as np
|
||||
import uuid
|
||||
|
||||
|
||||
# In[2]:
|
||||
|
||||
|
||||
class DealManager():
|
||||
|
||||
def __init__(self):
|
||||
self.commission=0.04
|
||||
self.columns=['uuid','figi','amount','startPrice','profit']
|
||||
self.deals = pd.DataFrame(columns=self.columns)
|
||||
self.deals = self.deals.set_index('uuid')
|
||||
|
||||
def findDealByPriceAndFig(self,price,figi):
|
||||
ans=None
|
||||
for i in range(self.deals.shape[0]):
|
||||
if self.deals.iloc[i].startPrice == price and self.deals.iloc[i].figi == figi:
|
||||
ans = self.deals.iloc[i].name
|
||||
break
|
||||
return ans
|
||||
|
||||
def openDeal(self,figi,startPrice,amount=1):
|
||||
desiredDeal=self.findDealByPriceAndFig(startPrice,figi)
|
||||
if desiredDeal == None:
|
||||
newDealDict={
|
||||
'uuid':[str(uuid.uuid4())],
|
||||
'figi':[figi],
|
||||
'startPrice':[startPrice],
|
||||
'amount':[amount]
|
||||
}
|
||||
|
||||
#newDealDict['profit']=[startPrice*pow(1+self.commission,2)]
|
||||
|
||||
|
||||
|
||||
newDeal=pd.DataFrame.from_dict(newDealDict).set_index('uuid')
|
||||
self.deals=pd.concat([self.deals, newDeal])
|
||||
else:
|
||||
self.deals.at[desiredDeal,'amount'] += amount
|
||||
|
||||
def closeDeal(self,uuid,amount):
|
||||
|
||||
desiredDeal=self.deals.loc[uuid]
|
||||
if desiredDeal.amount - amount == 0:
|
||||
self.deals = self.deals.drop(labels = [uuid],axis = 0)
|
||||
else:
|
||||
self.deals.at[uuid,'amount'] -= amount
|
||||
#self.deals.loc[uuid].amount = desiredDeal.amount - amount
|
||||
|
||||
|
||||
|
||||
# In[3]:
|
||||
|
||||
|
||||
t=DealManager()
|
||||
t.__dict__
|
||||
|
||||
|
||||
# In[ ]:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# In[4]:
|
||||
|
||||
|
||||
t.deals.shape[0]
|
||||
|
||||
|
||||
# In[5]:
|
||||
|
||||
|
||||
t.openDeal('huigi',100,1)
|
||||
t.openDeal('huigi',100,3)
|
||||
t.openDeal('huigi1',100,3)
|
||||
t.openDeal('huigi1',200,3)
|
||||
|
||||
|
||||
# In[6]:
|
||||
|
||||
|
||||
t.deals
|
||||
|
||||
|
||||
# In[7]:
|
||||
|
||||
|
||||
t.deals[t.deals.figi == 'huigi1']
|
||||
|
||||
|
||||
# In[ ]:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# In[8]:
|
||||
|
||||
|
||||
for i in range(t.deals.shape[0]):
|
||||
print(t.deals.iloc[i])
|
||||
|
||||
|
||||
# In[9]:
|
||||
|
||||
|
||||
t.findDealByPriceAndFig
|
||||
|
||||
|
||||
# In[10]:
|
||||
|
||||
|
||||
t.closeDeal('78228979-3daf-470a-9c2a-8db180c8c3b0',1)
|
||||
t.deals
|
||||
|
||||
|
||||
# In[11]:
|
||||
|
||||
|
||||
t.deals.iloc[0].name
|
||||
|
||||
|
||||
# In[12]:
|
||||
|
||||
|
||||
a=2
|
||||
a==None
|
||||
|
||||
|
||||
# In[ ]:
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user