Improve navigating trades and positions by cross-linking
This commit is contained in:
@@ -131,7 +131,6 @@ class BaseExchange(ABC):
|
||||
def validate_response(self, response, method):
|
||||
schema = self.get_schema(method)
|
||||
# Return a dict of the validated response
|
||||
print("RESP", response)
|
||||
response_valid = schema(**response).dict()
|
||||
return response_valid
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from oandapyV20 import API
|
||||
from oandapyV20.endpoints import accounts, orders, positions, pricing
|
||||
from oandapyV20.endpoints import accounts, orders, positions, pricing, trades
|
||||
|
||||
from core.exchanges import BaseExchange
|
||||
|
||||
@@ -52,8 +52,6 @@ class OANDAExchange(BaseExchange):
|
||||
data = {
|
||||
"order": {
|
||||
# "price": "1.5000", - added later
|
||||
"stopLossOnFill": {"timeInForce": "GTC", "price": str(trade.stop_loss)},
|
||||
"takeProfitOnFill": {"price": str(trade.take_profit)},
|
||||
"timeInForce": trade.time_in_force.upper(),
|
||||
"instrument": trade.symbol,
|
||||
"units": str(amount),
|
||||
@@ -61,6 +59,13 @@ class OANDAExchange(BaseExchange):
|
||||
"positionFill": "DEFAULT",
|
||||
}
|
||||
}
|
||||
if trade.stop_loss is not None:
|
||||
data["order"]["stopLossOnFill"] = {
|
||||
"timeInForce": "GTC",
|
||||
"price": str(trade.stop_loss),
|
||||
}
|
||||
if trade.take_profit is not None:
|
||||
data["order"]["takeProfitOnFill"] = {"price": str(trade.take_profit)}
|
||||
if trade.price is not None:
|
||||
if trade.type == "limit":
|
||||
data["order"]["price"] = str(trade.price)
|
||||
@@ -75,13 +80,14 @@ class OANDAExchange(BaseExchange):
|
||||
response = self.call(r)
|
||||
trade.response = response
|
||||
trade.status = "posted"
|
||||
trade.order_id = response["id"]
|
||||
trade.order_id = str(int(response["id"]) + 1)
|
||||
trade.client_order_id = response["requestID"]
|
||||
trade.save()
|
||||
return response
|
||||
|
||||
def get_trade(self, trade_id):
|
||||
r = accounts.TradeDetails(accountID=self.account_id, tradeID=trade_id)
|
||||
# OANDA is off by one...
|
||||
r = trades.TradeDetails(accountID=self.account_id, tradeID=trade_id)
|
||||
return self.call(r)
|
||||
|
||||
def update_trade(self, trade):
|
||||
|
||||
Reference in New Issue
Block a user