-
Notifications
You must be signed in to change notification settings - Fork 5
/
cancel_all_orders.py
executable file
·54 lines (41 loc) · 1.74 KB
/
cancel_all_orders.py
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
#!/usr/bin/env python
import sys
import click
from bitshares.account import Account
from bitshares.market import Market
from uptick.decorators import unlock
from bitsharesscripts.decorators import chain, common_options
@click.command()
@common_options
@chain
@unlock
@click.option('--buy-only', default=False, is_flag=True, help='cancel only buy orders')
@click.option('--sell-only', default=False, is_flag=True, help='cancel only sell orders')
@click.option('--market', help='cancel orders only on specified market only, format is QUOTE/BASE')
@click.argument('account')
@click.pass_context
def main(ctx, buy_only, sell_only, market, account):
"""Cancel all orders of specified account.
Optionally, you can select market like BTC/USD and choose buy/sell orders only
"""
if buy_only and sell_only:
ctx.log.critical('--buy-only and --sell-only are mutually exclusive')
sys.exit(1)
account = Account(account, blockchain_instance=ctx.bitshares)
orders = [order for order in account.openorders if 'id' in order]
if market:
market = Market(market, blockchain_instance=ctx.bitshares)
market_ids = [market['base']['symbol'], market['quote']['symbol']]
orders = [
order
for order in orders
if order['base']['symbol'] in market_ids and order['quote']['symbol'] in market_ids
]
if buy_only:
orders = [order for order in orders if order['base']['symbol'] == market['base']['symbol']]
elif sell_only:
orders = [order for order in orders if order['base']['symbol'] == market['quote']['symbol']]
ids = [order['id'] for order in orders if 'id' in order]
ctx.bitshares.cancel(ids, account=account)
if __name__ == '__main__':
main()