Simple Echo Strategy¶
API¶
-
class
stakemachine.strategies.echo.Echo(*args, **kwargs)¶ -
error(*args, **kwargs)¶ What to do on an error
-
print_UpdateCallOrder(i)¶ Is called when a call order for a market pegged asset is updated
A developer may want to filter those to identify own orders.
Parameters: i (bitshares.price.CallOrder) – Call order details
-
print_accountUpdate(i)¶ This method is called when the bot’s account name receives any update. This includes anything that changes
2.6.xxxx, e.g., any operation that affects your account.
-
print_marketUpdate(i)¶ Is called when Something happens in your market.
This method is actually called by the backend and is dispatched to
onOrderMatched,onOrderPlacedandonUpdateCallOrder.Parameters: i (object) – Can be instance of FilledOrder,Order, orCallOrder
-
print_newBlock(i)¶ Is called when a block is received
Parameters: i (str) – The hash of the block Note
Unfortunately, it is currently not possible to identify the block number for
ialone. If you need to know the most recent block number, you need to usebitshares.blockchain.Blockchain
-
print_orderMatched(i)¶ Is called when an order in the market is matched
A developer may want to filter those to identify own orders.
Parameters: i (bitshares.price.FilledOrder) – Filled order details
-
print_orderPlaced(i)¶ Is called when a new order in the market is placed
A developer may want to filter those to identify own orders.
Parameters: i (bitshares.price.Order) – Order details
-
Full Source Code¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | from stakemachine.basestrategy import BaseStrategy
import logging
log = logging.getLogger(__name__)
class Echo(BaseStrategy):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
""" set call backs for events
"""
self.onOrderMatched += self.print_orderMatched
self.onOrderPlaced += self.print_orderPlaced
self.onUpdateCallOrder += self.print_UpdateCallOrder
self.onMarketUpdate += self.print_marketUpdate
self.ontick += self.print_newBlock
self.onAccount += self.print_accountUpdate
self.error_ontick = self.error
self.error_onMarketUpdate = self.error
self.error_onAccount = self.error
def error(self, *args, **kwargs):
""" What to do on an error
"""
# Cancel all future execution
self.disabled = True
def print_orderMatched(self, i):
""" Is called when an order in the market is matched
A developer may want to filter those to identify
own orders.
:param bitshares.price.FilledOrder i: Filled order details
"""
print("order matched: %s" % i)
def print_orderPlaced(self, i):
""" Is called when a new order in the market is placed
A developer may want to filter those to identify
own orders.
:param bitshares.price.Order i: Order details
"""
print("order placed: %s" % i)
def print_UpdateCallOrder(self, i):
""" Is called when a call order for a market pegged asset is updated
A developer may want to filter those to identify
own orders.
:param bitshares.price.CallOrder i: Call order details
"""
print("call update: %s" % i)
def print_marketUpdate(self, i):
""" Is called when Something happens in your market.
This method is actually called by the backend and is
dispatched to ``onOrderMatched``, ``onOrderPlaced`` and
``onUpdateCallOrder``.
:param object i: Can be instance of ``FilledOrder``, ``Order``, or ``CallOrder``
"""
print("marketupdate: %s" % i)
def print_newBlock(self, i):
""" Is called when a block is received
:param str i: The hash of the block
.. note:: Unfortunately, it is currently not possible to
identify the block number for ``i`` alone. If you
need to know the most recent block number, you
need to use ``bitshares.blockchain.Blockchain``
"""
print("new block: %s" % i)
# raise ValueError("Testing disabling")
def print_accountUpdate(self, i):
""" This method is called when the bot's account name receives
any update. This includes anything that changes
``2.6.xxxx``, e.g., any operation that affects your account.
"""
print("account: %s" % i)
|