forked from oanda/v20-python-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dave Pettypiece
committed
Nov 28, 2016
1 parent
d821683
commit 6b1782c
Showing
5 changed files
with
131 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,5 @@ def main(): | |
|
||
print_order_create_response_transactions(response) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters