mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-20 07:14:20 +01:00
Moves Trades/Orders objects into repo
This commit is contained in:
50
bfxapi/models/Order.py
Normal file
50
bfxapi/models/Order.py
Normal file
@@ -0,0 +1,50 @@
|
||||
import time
|
||||
|
||||
class OrderClosedModel:
|
||||
ID = 0
|
||||
GID = 1
|
||||
CID = 2
|
||||
SYMBOL = 3
|
||||
MTS_CREATE = 4
|
||||
MTS_UPDATE = 5
|
||||
AMOUNT = 6
|
||||
AMOUNT_ORIG = 7
|
||||
TYPE = 8
|
||||
TYPE_PREV = 9
|
||||
FLAGS = 12
|
||||
STATUS = 13
|
||||
PRICE = 16
|
||||
PRIVE_AVG = 17
|
||||
PRICE_TRAILING = 18
|
||||
PRICE_AUX_LIMIT = 19
|
||||
NOTIFY = 23
|
||||
PLACE_ID = 25
|
||||
|
||||
def now_in_mills():
|
||||
return int(round(time.time() * 1000))
|
||||
|
||||
class Order:
|
||||
def __init__(self, closingOrderArray):
|
||||
self.id = closingOrderArray[OrderClosedModel.ID]
|
||||
self.gId = closingOrderArray[OrderClosedModel.GID]
|
||||
self.cId = closingOrderArray[OrderClosedModel.CID]
|
||||
self.symbol = closingOrderArray[OrderClosedModel.SYMBOL]
|
||||
self.mtsCreate = closingOrderArray[OrderClosedModel.MTS_CREATE]
|
||||
self.mtsUpdate = closingOrderArray[OrderClosedModel.MTS_UPDATE]
|
||||
self.amount = closingOrderArray[OrderClosedModel.AMOUNT]
|
||||
self.amountOrig = closingOrderArray[OrderClosedModel.AMOUNT_ORIG]
|
||||
self.type = closingOrderArray[OrderClosedModel.TYPE]
|
||||
self.typePrev = closingOrderArray[OrderClosedModel.TYPE_PREV]
|
||||
self.flags = closingOrderArray[OrderClosedModel.FLAGS]
|
||||
self.status = closingOrderArray[OrderClosedModel.STATUS]
|
||||
self.price = closingOrderArray[OrderClosedModel.PRICE]
|
||||
self.priceAvg = closingOrderArray[OrderClosedModel.PRIVE_AVG]
|
||||
self.priceTrailing = closingOrderArray[OrderClosedModel.PRICE_TRAILING]
|
||||
self.priceAuxLimit = closingOrderArray[OrderClosedModel.PRICE_AUX_LIMIT]
|
||||
self.notfiy = closingOrderArray[OrderClosedModel.NOTIFY]
|
||||
self.placeId = closingOrderArray[OrderClosedModel.PLACE_ID]
|
||||
|
||||
|
||||
def __str__(self):
|
||||
''' Allow us to print the Order object in a pretty format '''
|
||||
return "Order <'{0}' mtsCreate={1}>".format(self.symbol, self.mtsCreate)
|
||||
20
bfxapi/models/Trade.py
Normal file
20
bfxapi/models/Trade.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import datetime
|
||||
|
||||
class Trade:
|
||||
SHORT = 'SHORT'
|
||||
LONG = 'LONG'
|
||||
|
||||
def __init__(self, order, tag=''):
|
||||
self.order = order
|
||||
self.amount = order.amount
|
||||
self.price = order.priceAvg
|
||||
self.fee = (order.priceAvg * abs(order.amount)) * 0.002
|
||||
self.mts = order.mtsCreate
|
||||
self.date = datetime.datetime.fromtimestamp(order.mtsCreate/1000.0)
|
||||
self.direction = self.SHORT if order.amount < 0 else self.LONG
|
||||
self.tag = tag
|
||||
|
||||
def __str__(self):
|
||||
''' Allow us to print the Trade object in a pretty format '''
|
||||
return "Trade {} @ {} fee={} <order='{}'>".format(
|
||||
self.amount, self.price, self.fee, self.order)
|
||||
4
bfxapi/models/__init__.py
Normal file
4
bfxapi/models/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
name = 'models'
|
||||
|
||||
from .Order import *
|
||||
from .Trade import *
|
||||
Reference in New Issue
Block a user