mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-20 07:14:20 +01:00
16
.travis.yml
16
.travis.yml
@@ -1,12 +1,12 @@
|
|||||||
language: python
|
language: python
|
||||||
python:
|
|
||||||
- "3.4"
|
before_install:
|
||||||
- "3.5"
|
- sudo apt-get update
|
||||||
- "3.6"
|
- sudo apt-get install python3
|
||||||
# PyPy versions
|
- sudo apt-get install python3-pip
|
||||||
- "pypy3.5"
|
- sudo python3 -m pip install --upgrade pip
|
||||||
# command to install dependencies
|
# command to install dependencies
|
||||||
install:
|
install:
|
||||||
- python3 -m pip -U install -r requirements.txt
|
- python3 -m pip install -r requirements.txt --user
|
||||||
# command to run tests
|
# command to run tests
|
||||||
script: pylint --rcfile=pylint.rc bfxapi
|
script: python3 -m pylint --rcfile=pylint.rc bfxapi
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ class OrderClosedModel:
|
|||||||
FLAGS = 12
|
FLAGS = 12
|
||||||
STATUS = 13
|
STATUS = 13
|
||||||
PRICE = 16
|
PRICE = 16
|
||||||
PRIVE_AVG = 17
|
PRICE_AVG = 17
|
||||||
PRICE_TRAILING = 18
|
PRICE_TRAILING = 18
|
||||||
PRICE_AUX_LIMIT = 19
|
PRICE_AUX_LIMIT = 19
|
||||||
NOTIFY = 23
|
NOTIFY = 23
|
||||||
@@ -112,16 +112,18 @@ class Order:
|
|||||||
def __init__(self, oid, gid, cid, symbol, mts_create, mts_update, amount,
|
def __init__(self, oid, gid, cid, symbol, mts_create, mts_update, amount,
|
||||||
amount_orig, o_type, typePrev, flags, status, price, price_avg,
|
amount_orig, o_type, typePrev, flags, status, price, price_avg,
|
||||||
price_trailing, price_aux_limit, notfiy, place_id):
|
price_trailing, price_aux_limit, notfiy, place_id):
|
||||||
# pylint: disable=invalid-name
|
self.id = oid # pylint: disable=invalid-name
|
||||||
self.id = oid
|
|
||||||
self.gid = gid
|
self.gid = gid
|
||||||
self.cid = cid
|
self.cid = cid
|
||||||
self.symbol = symbol
|
self.symbol = symbol
|
||||||
self.mts_create = mts_create
|
self.mts_create = mts_create
|
||||||
self.mts_update = mts_update
|
self.mts_update = mts_update
|
||||||
# self.amount = amount
|
|
||||||
self.amount = amount
|
self.amount = amount
|
||||||
self.amount_orig = amount_orig
|
self.amount_orig = amount_orig
|
||||||
|
if self.amount_orig > 0:
|
||||||
|
self.amount_filled = amount_orig - amount
|
||||||
|
else:
|
||||||
|
self.amount_filled = -(abs(amount_orig) - abs(amount))
|
||||||
self.type = o_type
|
self.type = o_type
|
||||||
self.type_prev = typePrev
|
self.type_prev = typePrev
|
||||||
self.flags = flags
|
self.flags = flags
|
||||||
@@ -134,7 +136,6 @@ class Order:
|
|||||||
self.place_id = place_id
|
self.place_id = place_id
|
||||||
self.tag = ""
|
self.tag = ""
|
||||||
self.fee = 0
|
self.fee = 0
|
||||||
|
|
||||||
self.is_pending_bool = True
|
self.is_pending_bool = True
|
||||||
self.is_confirmed_bool = False
|
self.is_confirmed_bool = False
|
||||||
self.is_open_bool = False
|
self.is_open_bool = False
|
||||||
@@ -144,9 +145,9 @@ class Order:
|
|||||||
if price_avg:
|
if price_avg:
|
||||||
# check if order is taker or maker
|
# check if order is taker or maker
|
||||||
if self.type in LIMIT_ORDERS:
|
if self.type in LIMIT_ORDERS:
|
||||||
self.fee = (price_avg * abs(amount)) * 0.001
|
self.fee = (price_avg * abs(self.amount_filled)) * 0.001
|
||||||
else:
|
else:
|
||||||
self.fee = (price_avg * abs(amount)) * 0.002
|
self.fee = (price_avg * abs(self.amount_filled)) * 0.002
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_raw_order(raw_order):
|
def from_raw_order(raw_order):
|
||||||
@@ -168,7 +169,7 @@ class Order:
|
|||||||
flags = raw_order[OrderClosedModel.FLAGS]
|
flags = raw_order[OrderClosedModel.FLAGS]
|
||||||
status = raw_order[OrderClosedModel.STATUS]
|
status = raw_order[OrderClosedModel.STATUS]
|
||||||
price = raw_order[OrderClosedModel.PRICE]
|
price = raw_order[OrderClosedModel.PRICE]
|
||||||
price_avg = raw_order[OrderClosedModel.PRIVE_AVG]
|
price_avg = raw_order[OrderClosedModel.PRICE_AVG]
|
||||||
price_trailing = raw_order[OrderClosedModel.PRICE_TRAILING]
|
price_trailing = raw_order[OrderClosedModel.PRICE_TRAILING]
|
||||||
price_aux_limit = raw_order[OrderClosedModel.PRICE_AUX_LIMIT]
|
price_aux_limit = raw_order[OrderClosedModel.PRICE_AUX_LIMIT]
|
||||||
notfiy = raw_order[OrderClosedModel.NOTIFY]
|
notfiy = raw_order[OrderClosedModel.NOTIFY]
|
||||||
@@ -217,5 +218,6 @@ class Order:
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
''' Allow us to print the Order object in a pretty format '''
|
''' Allow us to print the Order object in a pretty format '''
|
||||||
text = "Order <'{}' mts_create={} status='{}' id={}>"
|
text = "Order <'{}' amount_orig={} amount_filled={} mts_create={} status='{}' id={}>"
|
||||||
return text.format(self.symbol, self.mts_create, self.status, self.id)
|
return text.format(self.symbol, self.amount_orig, self.amount_filled,
|
||||||
|
self.mts_create, self.status, self.id)
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ class OrderClosedModel:
|
|||||||
FLAGS = 12
|
FLAGS = 12
|
||||||
STATUS = 13
|
STATUS = 13
|
||||||
PRICE = 16
|
PRICE = 16
|
||||||
PRIVE_AVG = 17
|
PRICE_AVG = 17
|
||||||
PRICE_TRAILING = 18
|
PRICE_TRAILING = 18
|
||||||
PRICE_AUX_LIMIT = 19
|
PRICE_AUX_LIMIT = 19
|
||||||
NOTIFY = 23
|
NOTIFY = 23
|
||||||
@@ -112,16 +112,18 @@ class Order:
|
|||||||
def __init__(self, oid, gid, cid, symbol, mts_create, mts_update, amount,
|
def __init__(self, oid, gid, cid, symbol, mts_create, mts_update, amount,
|
||||||
amount_orig, o_type, typePrev, flags, status, price, price_avg,
|
amount_orig, o_type, typePrev, flags, status, price, price_avg,
|
||||||
price_trailing, price_aux_limit, notfiy, place_id):
|
price_trailing, price_aux_limit, notfiy, place_id):
|
||||||
# pylint: disable=invalid-name
|
self.id = oid # pylint: disable=invalid-name
|
||||||
self.id = oid
|
|
||||||
self.gid = gid
|
self.gid = gid
|
||||||
self.cid = cid
|
self.cid = cid
|
||||||
self.symbol = symbol
|
self.symbol = symbol
|
||||||
self.mts_create = mts_create
|
self.mts_create = mts_create
|
||||||
self.mts_update = mts_update
|
self.mts_update = mts_update
|
||||||
# self.amount = amount
|
|
||||||
self.amount = amount
|
self.amount = amount
|
||||||
self.amount_orig = amount_orig
|
self.amount_orig = amount_orig
|
||||||
|
if self.amount_orig > 0:
|
||||||
|
self.amount_filled = amount_orig - amount
|
||||||
|
else:
|
||||||
|
self.amount_filled = -(abs(amount_orig) - abs(amount))
|
||||||
self.type = o_type
|
self.type = o_type
|
||||||
self.type_prev = typePrev
|
self.type_prev = typePrev
|
||||||
self.flags = flags
|
self.flags = flags
|
||||||
@@ -134,7 +136,6 @@ class Order:
|
|||||||
self.place_id = place_id
|
self.place_id = place_id
|
||||||
self.tag = ""
|
self.tag = ""
|
||||||
self.fee = 0
|
self.fee = 0
|
||||||
|
|
||||||
self.is_pending_bool = True
|
self.is_pending_bool = True
|
||||||
self.is_confirmed_bool = False
|
self.is_confirmed_bool = False
|
||||||
self.is_open_bool = False
|
self.is_open_bool = False
|
||||||
@@ -144,9 +145,9 @@ class Order:
|
|||||||
if price_avg:
|
if price_avg:
|
||||||
# check if order is taker or maker
|
# check if order is taker or maker
|
||||||
if self.type in LIMIT_ORDERS:
|
if self.type in LIMIT_ORDERS:
|
||||||
self.fee = (price_avg * abs(amount)) * 0.001
|
self.fee = (price_avg * abs(self.amount_filled)) * 0.001
|
||||||
else:
|
else:
|
||||||
self.fee = (price_avg * abs(amount)) * 0.002
|
self.fee = (price_avg * abs(self.amount_filled)) * 0.002
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_raw_order(raw_order):
|
def from_raw_order(raw_order):
|
||||||
@@ -168,7 +169,7 @@ class Order:
|
|||||||
flags = raw_order[OrderClosedModel.FLAGS]
|
flags = raw_order[OrderClosedModel.FLAGS]
|
||||||
status = raw_order[OrderClosedModel.STATUS]
|
status = raw_order[OrderClosedModel.STATUS]
|
||||||
price = raw_order[OrderClosedModel.PRICE]
|
price = raw_order[OrderClosedModel.PRICE]
|
||||||
price_avg = raw_order[OrderClosedModel.PRIVE_AVG]
|
price_avg = raw_order[OrderClosedModel.PRICE_AVG]
|
||||||
price_trailing = raw_order[OrderClosedModel.PRICE_TRAILING]
|
price_trailing = raw_order[OrderClosedModel.PRICE_TRAILING]
|
||||||
price_aux_limit = raw_order[OrderClosedModel.PRICE_AUX_LIMIT]
|
price_aux_limit = raw_order[OrderClosedModel.PRICE_AUX_LIMIT]
|
||||||
notfiy = raw_order[OrderClosedModel.NOTIFY]
|
notfiy = raw_order[OrderClosedModel.NOTIFY]
|
||||||
@@ -217,5 +218,6 @@ class Order:
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
''' Allow us to print the Order object in a pretty format '''
|
''' Allow us to print the Order object in a pretty format '''
|
||||||
text = "Order <'{}' mts_create={} status='{}' id={}>"
|
text = "Order <'{}' amount_orig={} amount_filled={} mts_create={} status='{}' id={}>"
|
||||||
return text.format(self.symbol, self.mts_create, self.status, self.id)
|
return text.format(self.symbol, self.amount_orig, self.amount_filled,
|
||||||
|
self.mts_create, self.status, self.id)
|
||||||
|
|||||||
@@ -38,13 +38,13 @@ class OrderManager:
|
|||||||
Called every time an order signal has been received. This function
|
Called every time an order signal has been received. This function
|
||||||
manages the local list of open orders.
|
manages the local list of open orders.
|
||||||
"""
|
"""
|
||||||
if order.cId in self.pending_orders:
|
if order.cid in self.pending_orders:
|
||||||
await self._execute_confirm_callback(order.cId, order)
|
await self._execute_confirm_callback(order.cid, order)
|
||||||
if isClosed:
|
if isClosed:
|
||||||
await self._execute_close_callback(order.cId, order)
|
await self._execute_close_callback(order.cid, order)
|
||||||
order.set_confirmed()
|
order.set_confirmed()
|
||||||
# remove from pending orders list
|
# remove from pending orders list
|
||||||
del self.pending_orders[order.cId]
|
del self.pending_orders[order.cid]
|
||||||
self.bfxapi._emit('order_confirmed', order)
|
self.bfxapi._emit('order_confirmed', order)
|
||||||
else:
|
else:
|
||||||
await self._execute_confirm_callback(order.id, order)
|
await self._execute_confirm_callback(order.id, order)
|
||||||
@@ -123,10 +123,10 @@ class OrderManager:
|
|||||||
@param onClose: function called when the bitfinex websocket receives signal that the order
|
@param onClose: function called when the bitfinex websocket receives signal that the order
|
||||||
was closed due to being filled or cancelled
|
was closed due to being filled or cancelled
|
||||||
"""
|
"""
|
||||||
cId = self._gen_unqiue_cid()
|
cid = self._gen_unqiue_cid()
|
||||||
# create base payload with required data
|
# create base payload with required data
|
||||||
payload = {
|
payload = {
|
||||||
"cid": cId,
|
"cid": cid,
|
||||||
"type": str(market_type),
|
"type": str(market_type),
|
||||||
"symbol": symbol,
|
"symbol": symbol,
|
||||||
"amount": str(amount),
|
"amount": str(amount),
|
||||||
@@ -146,11 +146,11 @@ class OrderManager:
|
|||||||
if (time_in_force):
|
if (time_in_force):
|
||||||
payload['tif'] = time_in_force
|
payload['tif'] = time_in_force
|
||||||
# submit the order
|
# submit the order
|
||||||
self.pending_orders[cId] = payload
|
self.pending_orders[cid] = payload
|
||||||
self._create_callback(cId, onConfirm=onConfirm, onClose=onClose)
|
self._create_callback(cid, onConfirm=onConfirm, onClose=onClose)
|
||||||
await self.bfxapi._send_auth_command('on', payload)
|
await self.bfxapi._send_auth_command('on', payload)
|
||||||
self.logger.info("Order cid={} ({} {} @ {}) dispatched".format(
|
self.logger.info("Order cid={} ({} {} @ {}) dispatched".format(
|
||||||
cId, symbol, amount, price))
|
cid, symbol, amount, price))
|
||||||
|
|
||||||
async def update_order(self, orderId, price=None, amount=None, delta=None, price_aux_limit=None,
|
async def update_order(self, orderId, price=None, amount=None, delta=None, price_aux_limit=None,
|
||||||
price_trailing=None, hidden=False, close=False, reduce_only=False,
|
price_trailing=None, hidden=False, close=False, reduce_only=False,
|
||||||
|
|||||||
@@ -7,4 +7,5 @@ disable=too-few-public-methods,
|
|||||||
too-many-locals,
|
too-many-locals,
|
||||||
no-init,
|
no-init,
|
||||||
len-as-condition,
|
len-as-condition,
|
||||||
too-many-instance-attributes
|
too-many-instance-attributes,
|
||||||
|
invalid-name
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
eventemitter==0.2.0
|
eventemitter==0.2.0
|
||||||
asyncio==3.4.3
|
asyncio==3.4.3
|
||||||
websockets==7.0
|
websockets==7.0
|
||||||
pylint==1.8.3
|
pylint==2.2.2
|
||||||
|
|||||||
Reference in New Issue
Block a user