Skip to content

Commit d821683

Browse files
author
Dave Pettypiece
committed
updated v20 version, other minor changes
1 parent 0739755 commit d821683

13 files changed

Lines changed: 43 additions & 52 deletions

File tree

requirements/base.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ pyyaml==3.11
22
tabulate==0.7.5
33
requests==2.11.1
44
ujson==1.35
5-
v20==3.0.9.0
5+
v20==3.0.10.0

src/common/config.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
import yaml
23
import os
34
import sys
@@ -98,7 +99,7 @@ def dump(self, path):
9899
path = os.path.expanduser(path)
99100

100101
with open(path, "w") as f:
101-
print >>f, str(self)
102+
print(str(self), file=f)
102103

103104
def load(self, path):
104105
"""
@@ -281,13 +282,11 @@ def create_context(self):
281282
self.hostname,
282283
self.port,
283284
self.ssl,
284-
application="sample_code"
285+
application="sample_code",
286+
token=self.token,
287+
datetime_format=self.datetime_format
285288
)
286289

287-
ctx.set_token(self.token)
288-
289-
ctx.set_datetime_format(self.datetime_format)
290-
291290
return ctx
292291

293292
def create_streaming_context(self):
@@ -297,13 +296,12 @@ def create_streaming_context(self):
297296
ctx = v20.Context(
298297
self.streaming_hostname,
299298
self.port,
300-
self.ssl
299+
self.ssl,
300+
application="sample_code",
301+
token=self.token,
302+
datetime_format=self.datetime_format
301303
)
302304

303-
ctx.set_token(self.token)
304-
305-
ctx.set_datetime_format(self.datetime_format)
306-
307305
return ctx
308306

309307

src/common/input.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@ def get_string(prompt, default=None):
1010
"" if default is None else " [{}]".format(default)
1111
)
1212

13+
try: i = raw_input
14+
except NameError: i = input
15+
1316
value = None
1417

1518
while value is None or len(value) == 0:
1619
try:
17-
value = raw_input(prompt) or default
20+
value = i(prompt) or default
1821
except KeyboardInterrupt:
1922
print("")
2023
sys.exit()
@@ -58,9 +61,12 @@ def get_yn(prompt, default=True):
5861
choices
5962
)
6063

64+
try: i = raw_input
65+
except NameError: i = input
66+
6167
while choice is None:
6268
try:
63-
s = raw_input(prompt)
69+
s = i(prompt)
6470

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

109+
try: i = raw_input
110+
except NameError: i = input
111+
103112
while choice is None:
104113
try:
105-
s = raw_input(prompt) or default
114+
s = i(prompt) or default
106115

107116
i = int(s)
108117

src/instrument/candles.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ def main():
2424
common.config.add_argument(parser)
2525

2626
parser.add_argument(
27-
"--instrument",
27+
"instrument",
2828
type=common.args.instrument,
29-
required=True,
3029
help="The instrument to get candles for"
3130
)
3231

src/instrument/candles_poll.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,8 @@ def main():
141141
common.config.add_argument(parser)
142142

143143
parser.add_argument(
144-
"--instrument",
144+
"instrument",
145145
type=common.args.instrument,
146-
default=None,
147-
required=True,
148146
help="The instrument to get candles for"
149147
)
150148

src/market_order_full_example.py

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,26 @@ def main():
3434
# Add Account arguments
3535
#
3636
parser.add_argument(
37-
"--account-id",
38-
required=True,
37+
"accountid",
3938
help="v20 Account ID"
4039
)
4140

4241
parser.add_argument(
43-
"--token",
44-
required=True,
42+
"token",
4543
help="v20 Auth Token"
4644
)
4745

4846
#
4947
# Add arguments for minimal Market Order
5048
#
5149
parser.add_argument(
52-
"--instrument",
50+
"instrument",
5351
type=common.args.instrument,
54-
required=True,
5552
help="The instrument to place the Market Order for"
5653
)
5754

5855
parser.add_argument(
59-
"--units",
60-
required=True,
56+
"units",
6157
help="The number of units for the Market Order"
6258
)
6359

@@ -69,24 +65,14 @@ def main():
6965
api = v20.Context(
7066
args.hostname,
7167
args.port,
72-
True
68+
token=args.token
7369
)
7470

75-
#
76-
# Set the auth token to use
77-
#
78-
api.set_token(args.token)
79-
80-
#
81-
# Extract the Account ID from the arguments
82-
#
83-
account_id = args.account_id
84-
8571
#
8672
# Submit the request to create the Market Order
8773
#
8874
response = api.order.market(
89-
account_id,
75+
args.accountid,
9076
instrument=args.instrument,
9177
units=args.units
9278
)

src/order/list_pending.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def main():
1414
dest="summary",
1515
action="store_true",
1616
help="Print a summary of the orders",
17-
default=False
17+
default=True
1818
)
1919

2020
parser.add_argument(

src/pricing/stream.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ def main():
3636

3737
api = args.config.create_streaming_context()
3838

39+
# api.set_convert_decimal_number_to_native(False)
40+
3941
# api.set_stream_timeout(3)
4042

4143
#

src/trade/close.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ def main():
1919
common.config.add_argument(parser)
2020

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

5150
response = api.trade.close(
5251
account_id,
53-
args.trade_id,
52+
args.tradeid,
5453
units=args.units
5554
)
5655

src/trade/get.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def main():
6363
if args.all:
6464
response = api.trade.list_open(account_id)
6565

66-
for trade in response.get("trades", 200):
66+
for trade in reversed(response.get("trades", 200)):
6767
if args.summary:
6868
print(trade.title())
6969
else:

0 commit comments

Comments
 (0)