Skip to content

Commit

Permalink
updated v20 version, other minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Pettypiece committed Nov 16, 2016
1 parent 0739755 commit d821683
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 52 deletions.
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ pyyaml==3.11
tabulate==0.7.5
requests==2.11.1
ujson==1.35
v20==3.0.9.0
v20==3.0.10.0
20 changes: 9 additions & 11 deletions src/common/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import yaml
import os
import sys
Expand Down Expand Up @@ -98,7 +99,7 @@ def dump(self, path):
path = os.path.expanduser(path)

with open(path, "w") as f:
print >>f, str(self)
print(str(self), file=f)

def load(self, path):
"""
Expand Down Expand Up @@ -281,13 +282,11 @@ def create_context(self):
self.hostname,
self.port,
self.ssl,
application="sample_code"
application="sample_code",
token=self.token,
datetime_format=self.datetime_format
)

ctx.set_token(self.token)

ctx.set_datetime_format(self.datetime_format)

return ctx

def create_streaming_context(self):
Expand All @@ -297,13 +296,12 @@ def create_streaming_context(self):
ctx = v20.Context(
self.streaming_hostname,
self.port,
self.ssl
self.ssl,
application="sample_code",
token=self.token,
datetime_format=self.datetime_format
)

ctx.set_token(self.token)

ctx.set_datetime_format(self.datetime_format)

return ctx


Expand Down
15 changes: 12 additions & 3 deletions src/common/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ def get_string(prompt, default=None):
"" if default is None else " [{}]".format(default)
)

try: i = raw_input
except NameError: i = input

value = None

while value is None or len(value) == 0:
try:
value = raw_input(prompt) or default
value = i(prompt) or default
except KeyboardInterrupt:
print("")
sys.exit()
Expand Down Expand Up @@ -58,9 +61,12 @@ def get_yn(prompt, default=True):
choices
)

try: i = raw_input
except NameError: i = input

while choice is None:
try:
s = raw_input(prompt)
s = i(prompt)

if len(s) == 0 and default is not None:
return default
Expand Down Expand Up @@ -100,9 +106,12 @@ def get_from_list(choices, title, prompt, default=0):
for i, c in enumerate(choices):
print("[{}] {}".format(i, c))

try: i = raw_input
except NameError: i = input

while choice is None:
try:
s = raw_input(prompt) or default
s = i(prompt) or default

i = int(s)

Expand Down
3 changes: 1 addition & 2 deletions src/instrument/candles.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ def main():
common.config.add_argument(parser)

parser.add_argument(
"--instrument",
"instrument",
type=common.args.instrument,
required=True,
help="The instrument to get candles for"
)

Expand Down
4 changes: 1 addition & 3 deletions src/instrument/candles_poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,8 @@ def main():
common.config.add_argument(parser)

parser.add_argument(
"--instrument",
"instrument",
type=common.args.instrument,
default=None,
required=True,
help="The instrument to get candles for"
)

Expand Down
26 changes: 6 additions & 20 deletions src/market_order_full_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,26 @@ def main():
# Add Account arguments
#
parser.add_argument(
"--account-id",
required=True,
"accountid",
help="v20 Account ID"
)

parser.add_argument(
"--token",
required=True,
"token",
help="v20 Auth Token"
)

#
# Add arguments for minimal Market Order
#
parser.add_argument(
"--instrument",
"instrument",
type=common.args.instrument,
required=True,
help="The instrument to place the Market Order for"
)

parser.add_argument(
"--units",
required=True,
"units",
help="The number of units for the Market Order"
)

Expand All @@ -69,24 +65,14 @@ def main():
api = v20.Context(
args.hostname,
args.port,
True
token=args.token
)

#
# Set the auth token to use
#
api.set_token(args.token)

#
# Extract the Account ID from the arguments
#
account_id = args.account_id

#
# Submit the request to create the Market Order
#
response = api.order.market(
account_id,
args.accountid,
instrument=args.instrument,
units=args.units
)
Expand Down
2 changes: 1 addition & 1 deletion src/order/list_pending.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def main():
dest="summary",
action="store_true",
help="Print a summary of the orders",
default=False
default=True
)

parser.add_argument(
Expand Down
2 changes: 2 additions & 0 deletions src/pricing/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def main():

api = args.config.create_streaming_context()

# api.set_convert_decimal_number_to_native(False)

# api.set_stream_timeout(3)

#
Expand Down
5 changes: 2 additions & 3 deletions src/trade/close.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ def main():
common.config.add_argument(parser)

parser.add_argument(
"--trade-id",
required=True,
"tradeid",
help=(
"The ID of the Trade to close. If prepended "
"with an '@', this will be interpreted as a client Trade ID"
Expand Down Expand Up @@ -50,7 +49,7 @@ def main():

response = api.trade.close(
account_id,
args.trade_id,
args.tradeid,
units=args.units
)

Expand Down
2 changes: 1 addition & 1 deletion src/trade/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def main():
if args.all:
response = api.trade.list_open(account_id)

for trade in response.get("trades", 200):
for trade in reversed(response.get("trades", 200)):
if args.summary:
print(trade.title())
else:
Expand Down
10 changes: 5 additions & 5 deletions src/trade/set_client_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ def main():
common.config.add_argument(parser)

parser.add_argument(
"--trade-id",
required=True,
"tradeid",
help=(
"The ID of the Order to get. If prepended "
"with an '@', this will be interpreted as a client Order ID"
"The ID of the Trade to set the client extensions for. If "
"prepended with an '@', this will be interpreted as a client Order "
"ID"
)
)

Expand Down Expand Up @@ -68,7 +68,7 @@ def main():
#
response = api.trade.set_client_extensions(
account_id,
args.trade_id,
args.tradeid,
clientExtensions=clientExtensions
)

Expand Down
2 changes: 1 addition & 1 deletion src/transaction/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def main():

response = api.transaction.get(account_id, args.id)

print response.get("transaction", 200)
print(response.get("transaction", 200))


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion src/transaction/poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def main():
)

for transaction in response.get("transactions", 200):
print transaction.title()
print(transaction.title())

last_transaction_id = response.get("lastTransactionID", 200)

Expand Down

0 comments on commit d821683

Please sign in to comment.