Skip to content

Commit 6b1782c

Browse files
author
Dave Pettypiece
committed
aded position close sample
1 parent d821683 commit 6b1782c

5 files changed

Lines changed: 131 additions & 2 deletions

File tree

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
'v20-trade-get = trade.get:main',
3737
'v20-trade-close = trade.close:main',
3838
'v20-trade-set-client-extensions = trade.set_client_extensions:main',
39+
'v20-position-close = position.close:main',
3940
]
4041
}
4142
)

src/order/market.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,5 @@ def main():
6161

6262
print_order_create_response_transactions(response)
6363

64-
6564
if __name__ == "__main__":
6665
main()

src/order/view.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,54 @@ def print_order_create_response_transactions(response):
6767
"orderCreateTransaction"
6868
)
6969

70+
common.view.print_response_entity(
71+
response, None,
72+
"Long Order Create",
73+
"longOrderCreateTransaction"
74+
)
75+
76+
common.view.print_response_entity(
77+
response, None,
78+
"Short Order Create",
79+
"shortOrderCreateTransaction"
80+
)
81+
7082
common.view.print_response_entity(
7183
response, None,
7284
"Order Fill",
7385
"orderFillTransaction"
7486
)
7587

88+
common.view.print_response_entity(
89+
response, None,
90+
"Long Order Fill",
91+
"longOrderFillTransaction"
92+
)
93+
94+
common.view.print_response_entity(
95+
response, None,
96+
"Short Order Fill",
97+
"shortOrderFillTransaction"
98+
)
99+
76100
common.view.print_response_entity(
77101
response, None,
78102
"Order Cancel",
79103
"orderCancelTransaction"
80104
)
81105

106+
common.view.print_response_entity(
107+
response, None,
108+
"Long Order Cancel",
109+
"longOrderCancelTransaction"
110+
)
111+
112+
common.view.print_response_entity(
113+
response, None,
114+
"Short Order Cancel",
115+
"shortOrderCancelTransaction"
116+
)
117+
82118
common.view.print_response_entity(
83119
response, None,
84120
"Order Reissue",

src/position/close.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env python
2+
3+
import argparse
4+
import common.config
5+
import common.view
6+
import common.args
7+
from order.view import print_order_create_response_transactions
8+
9+
10+
def main():
11+
"""
12+
Close an open Trade in an Account
13+
"""
14+
15+
parser = argparse.ArgumentParser()
16+
17+
#
18+
# Add the command line argument to parse to the v20 config
19+
#
20+
common.config.add_argument(parser)
21+
22+
parser.add_argument(
23+
"instrument",
24+
type=common.args.instrument,
25+
help=(
26+
"The Instrument of the Position to close. If prepended "
27+
"with an '@', this will be interpreted as a client Trade ID"
28+
)
29+
)
30+
31+
parser.add_argument(
32+
"--long-units",
33+
default=None,
34+
help=(
35+
"The amount of the long Position to close. Either the string 'ALL' "
36+
"indicating a full Position close, the string 'NONE', or the "
37+
"number of units of the Position to close"
38+
)
39+
)
40+
41+
parser.add_argument(
42+
"--short-units",
43+
default=None,
44+
help=(
45+
"The amount of the short Position to close. Either the string "
46+
"'ALL' indicating a full Position close, the string 'NONE', or the "
47+
"number of units of the Position to close"
48+
)
49+
)
50+
51+
args = parser.parse_args()
52+
53+
account_id = args.config.active_account
54+
55+
#
56+
# Create the api context based on the contents of the
57+
# v20 config file
58+
#
59+
api = args.config.create_context()
60+
61+
response = api.position.close(
62+
account_id,
63+
args.instrument,
64+
longUnits=args.long_units,
65+
shortUnits=args.short_units
66+
)
67+
68+
print(
69+
"Response: {} ({})\n".format(
70+
response.status,
71+
response.reason
72+
)
73+
)
74+
75+
print_order_create_response_transactions(response)
76+
77+
78+
if __name__ == "__main__":
79+
main()

src/pricing/stream.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@ def main():
2323
help="Instrument to get prices for"
2424
)
2525

26+
parser.add_argument(
27+
'--snapshot',
28+
action="store_true",
29+
default=True,
30+
help="Request an initial snapshot"
31+
)
32+
33+
parser.add_argument(
34+
'--no-snapshot',
35+
dest="snapshot",
36+
action="store_false",
37+
help="Do not request an initial snapshot"
38+
)
39+
2640
parser.add_argument(
2741
'--show-heartbeats', "-s",
2842
action='store_true',
@@ -45,7 +59,7 @@ def main():
4559
#
4660
response = api.pricing.stream(
4761
account_id,
48-
snapshot=True,
62+
snapshot=args.snapshot,
4963
instruments=",".join(args.instrument),
5064
)
5165

0 commit comments

Comments
 (0)