Skip to content

Commit ce60e2f

Browse files
committed
More bug fixes to the Oanda framework to handle special circumstances.
Changes to be committed: modified: Base/OANDA-PlaceOrder
1 parent b1bcc85 commit ce60e2f

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

Base/OANDA-PlaceOrder

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def main():
256256

257257
# Initialize amount and price
258258
amount=None
259-
price=None
259+
price=(ticker['Ask']+ticker['Bid'])/2
260260

261261
# Get Minimum allowed amount (units) and cost
262262

@@ -276,15 +276,14 @@ def main():
276276
price=(ticker['Ask']+ticker['Bid'])/2
277277
amount=int(GetPCTamount(relay,price))
278278
else:
279-
amount=int(relay.Order['Units'].split('.')[0])
280-
if amount<0:
281-
price=max(ticker['Ask'],ticker['Bid'])
279+
if type(relay.Order['Units'])!=str:
280+
amount=int(relay.Order['Units'].split('.')[0])
282281
else:
283-
price=min(ticker['Ask'],ticker['Bid'])
282+
amount=relay.Order['Units']
284283

285284
# Make sure minimum is enforced. Negative is for short.
286285

287-
if abs(amount)<minimum:
286+
if type(amount)!=str and abs(amount)<minimum:
288287
if amount>=0:
289288
amount=minimum
290289
else:
@@ -384,17 +383,20 @@ def main():
384383
or (type(amount) is int and amount<0):
385384
dir='Short'
386385

387-
relay.JRLog.Write("Placing Order")
388-
relay.JRLog.Write(f"|- Asset: {relay.Order['Asset']}")
389-
relay.JRLog.Write(f"|- Action: {relay.Order['Action']}")
390-
if 'Ticket' in relay.Order:
391-
relay.JRLog.Write(f"|- Ticket: {relay.Order['Ticket']}")
392-
if type(amount) is int:
393-
relay.JRLog.Write(f"|- Units: {abs(amount):.8f} {dir}")
394-
else:
395-
relay.JRLog.Write(f"|- Units: {amount:.8f} {dir}")
396-
relay.JRLog.Write(f"|- Price: {price:.8f}")
397-
relay.JRLog.Write(f"|- Total: {total:.8f}")
386+
try:
387+
relay.JRLog.Write("Placing Order")
388+
relay.JRLog.Write(f"|- Asset: {relay.Order['Asset']}")
389+
relay.JRLog.Write(f"|- Action: {relay.Order['Action']}")
390+
if 'Ticket' in relay.Order:
391+
relay.JRLog.Write(f"|- Ticket: {relay.Order['Ticket']}")
392+
if type(amount) is int:
393+
relay.JRLog.Write(f"|- Units: {abs(amount):.8f} {dir}")
394+
else:
395+
relay.JRLog.Write(f"|- Units: {amount:.8f} {dir}")
396+
relay.JRLog.Write(f"|- Price: {price:.8f}")
397+
relay.JRLog.Write(f"|- Total: {total:.8f}")
398+
except Exception as err:
399+
relay.JRLog.Write(f"{Orphan['Key']}: Code Error - {sys.exc_info()[-1].tb_lineno}/{str(e)}",stdOut=False)
398400

399401
if (type(amount) is int and amount!=0) \
400402
or (type(amount) is str and amount.upper()=='ALL'):

0 commit comments

Comments
 (0)