Objectify orders and order manager

This commit is contained in:
Jacob Plaster
2018-11-28 13:27:36 +00:00
parent 2c89dc3941
commit 8278b3424c
2 changed files with 101 additions and 49 deletions

View File

@@ -24,7 +24,8 @@ def now_in_mills():
return int(round(time.time() * 1000))
class Order:
def __init__(self, closingOrderArray):
def __init__(self, bfxapi, closingOrderArray):
self.bfxapi = bfxapi
self.id = closingOrderArray[OrderClosedModel.ID]
self.gId = closingOrderArray[OrderClosedModel.GID]
self.cId = closingOrderArray[OrderClosedModel.CID]
@@ -45,11 +46,40 @@ class Order:
self.placeId = closingOrderArray[OrderClosedModel.PLACE_ID]
self.is_pending_bool = True
self.is_confirmed_bool = False
self.is_open_bool = False
async def update(self, price=None, amount=None, delta=None, price_aux_limit=None,
price_trailing=None, flags=None, time_in_force=None):
payload = { "id": self.id }
if price is not None:
payload['price'] = str(price)
if amount is not None:
payload['amount'] = str(amount)
if delta is not None:
payload['delta'] = str(delta)
if price_aux_limit is not None:
payload['price_aux_limit'] = str(price_aux_limit)
if price_trailing is not None:
payload['price_trailing'] = str(price_trailing)
if flags is not None:
payload['flags'] = str(flags)
if time_in_force is not None:
payload['time_in_force'] = str(time_in_force)
await self.bfxapi._send_auth_command('ou', payload)
async def close(self):
await self.bfxapi._send_auth_command('oc', { 'id': self.id })
def set_confirmed(self):
self.is_pending_bool = False
self.is_confirmed_bool = True
def set_open_state(self, isOpen):
self.is_open_bool = isOpen
def isOpen(self):
return self.is_open_bool
def isPending(self):
return self.is_pending_bool