fix errors
This commit is contained in:
23
algo/mm.py
23
algo/mm.py
@@ -46,19 +46,19 @@ class MM:
|
||||
if not lastBuyAgreed and self._lastBuy is not None:
|
||||
logging.info(f"cancel buy")
|
||||
cancel_orders.append(self._lastBuy)
|
||||
self._lastBuy = None
|
||||
elif lastBuyAgreed:
|
||||
logging.info(f"agree buy")
|
||||
|
||||
if not lastSellAgreed and self._lastSell is not None:
|
||||
logging.info(f"cancel sell")
|
||||
cancel_orders.append(self._lastSell)
|
||||
self._lastSell = None
|
||||
elif lastSellAgreed:
|
||||
logging.info(f"agree sell")
|
||||
|
||||
if len(cancel_orders) != 0:
|
||||
await self._player.cancel(self._pair.names, cancel_orders)
|
||||
self._lastBuy = None
|
||||
self._lastSell = None
|
||||
|
||||
# execute cutting
|
||||
if cutting:
|
||||
@@ -66,7 +66,6 @@ class MM:
|
||||
logging.info(f"-cut (change: {change}, pos: {pos} -> 0)")
|
||||
if posCut:
|
||||
logging.info(f"+cut (change: {change}, pos: {pos} -> 0)")
|
||||
self._lastPrice = None
|
||||
self._lastBuy = None
|
||||
self._lastSell = None
|
||||
sell_amount = pos * lot
|
||||
@@ -77,29 +76,29 @@ class MM:
|
||||
return
|
||||
|
||||
# execute new cycle
|
||||
buy_amount = _quad( pos) * lot
|
||||
sell_amount = _quad(-pos) * lot
|
||||
|
||||
self._lastPrice = None
|
||||
buy_price = price * (1 - self._delta);
|
||||
sell_price = price * (1 + self._delta);
|
||||
|
||||
order_unit = pow(10, -sales.precision)
|
||||
buy_amount = min(_quad( pos) * lot, crncy.amount / buy_price)
|
||||
sell_amount = min(_quad(-pos) * lot, sales.amount)
|
||||
order_unit = pow(10, -sales.precision)
|
||||
|
||||
logging.info(f"new cycle (pos: {pos}, price: {price}, buy: {buy_amount}, sell: {sell_amount})")
|
||||
|
||||
async def buy():
|
||||
return (None if order_unit > buy_amount else
|
||||
self._lastBuy = (
|
||||
None if order_unit > buy_amount else
|
||||
await self._player.orderLimitBuy(
|
||||
self._pair.names, amount = buy_amount, price = buy_price))
|
||||
|
||||
async def sell():
|
||||
return (None if order_unit > sell_amount else
|
||||
self._lastSell = (
|
||||
None if order_unit > sell_amount else
|
||||
await self._player.orderLimitSell(
|
||||
self._pair.names, amount = sell_amount, price = sell_price))
|
||||
|
||||
orders = await asyncio.gather(buy(), sell())
|
||||
self._lastBuy = orders[0]
|
||||
self._lastSell = orders[1]
|
||||
await asyncio.gather(buy(), sell())
|
||||
self._lastPrice = price
|
||||
|
||||
# https://kijitora-2018.hatenablog.com/entry/2018/12/23/102913
|
||||
|
Reference in New Issue
Block a user