Skip to content

Commit

Permalink
aded position close sample
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Pettypiece committed Nov 28, 2016
1 parent d821683 commit 6b1782c
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 2 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
'v20-trade-get = trade.get:main',
'v20-trade-close = trade.close:main',
'v20-trade-set-client-extensions = trade.set_client_extensions:main',
'v20-position-close = position.close:main',
]
}
)
Expand Down
1 change: 0 additions & 1 deletion src/order/market.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,5 @@ def main():

print_order_create_response_transactions(response)


if __name__ == "__main__":
main()
36 changes: 36 additions & 0 deletions src/order/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,54 @@ def print_order_create_response_transactions(response):
"orderCreateTransaction"
)

common.view.print_response_entity(
response, None,
"Long Order Create",
"longOrderCreateTransaction"
)

common.view.print_response_entity(
response, None,
"Short Order Create",
"shortOrderCreateTransaction"
)

common.view.print_response_entity(
response, None,
"Order Fill",
"orderFillTransaction"
)

common.view.print_response_entity(
response, None,
"Long Order Fill",
"longOrderFillTransaction"
)

common.view.print_response_entity(
response, None,
"Short Order Fill",
"shortOrderFillTransaction"
)

common.view.print_response_entity(
response, None,
"Order Cancel",
"orderCancelTransaction"
)

common.view.print_response_entity(
response, None,
"Long Order Cancel",
"longOrderCancelTransaction"
)

common.view.print_response_entity(
response, None,
"Short Order Cancel",
"shortOrderCancelTransaction"
)

common.view.print_response_entity(
response, None,
"Order Reissue",
Expand Down
79 changes: 79 additions & 0 deletions src/position/close.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env python

import argparse
import common.config
import common.view
import common.args
from order.view import print_order_create_response_transactions


def main():
"""
Close an open Trade in an Account
"""

parser = argparse.ArgumentParser()

#
# Add the command line argument to parse to the v20 config
#
common.config.add_argument(parser)

parser.add_argument(
"instrument",
type=common.args.instrument,
help=(
"The Instrument of the Position to close. If prepended "
"with an '@', this will be interpreted as a client Trade ID"
)
)

parser.add_argument(
"--long-units",
default=None,
help=(
"The amount of the long Position to close. Either the string 'ALL' "
"indicating a full Position close, the string 'NONE', or the "
"number of units of the Position to close"
)
)

parser.add_argument(
"--short-units",
default=None,
help=(
"The amount of the short Position to close. Either the string "
"'ALL' indicating a full Position close, the string 'NONE', or the "
"number of units of the Position to close"
)
)

args = parser.parse_args()

account_id = args.config.active_account

#
# Create the api context based on the contents of the
# v20 config file
#
api = args.config.create_context()

response = api.position.close(
account_id,
args.instrument,
longUnits=args.long_units,
shortUnits=args.short_units
)

print(
"Response: {} ({})\n".format(
response.status,
response.reason
)
)

print_order_create_response_transactions(response)


if __name__ == "__main__":
main()
16 changes: 15 additions & 1 deletion src/pricing/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ def main():
help="Instrument to get prices for"
)

parser.add_argument(
'--snapshot',
action="store_true",
default=True,
help="Request an initial snapshot"
)

parser.add_argument(
'--no-snapshot',
dest="snapshot",
action="store_false",
help="Do not request an initial snapshot"
)

parser.add_argument(
'--show-heartbeats', "-s",
action='store_true',
Expand All @@ -45,7 +59,7 @@ def main():
#
response = api.pricing.stream(
account_id,
snapshot=True,
snapshot=args.snapshot,
instruments=",".join(args.instrument),
)

Expand Down

0 comments on commit 6b1782c

Please sign in to comment.