From bf863f43b2afb5243ca7b7a1d0eeb43ee3b88938 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Thu, 10 Nov 2022 07:20:28 +0000 Subject: [PATCH] Check exchange name and remove redundant code, use IOC orders for OANDA --- core/exchanges/oanda.py | 2 +- core/lib/market.py | 21 +++------------------ core/lib/schemas/oanda_s.py | 34 ---------------------------------- 3 files changed, 4 insertions(+), 53 deletions(-) diff --git a/core/exchanges/oanda.py b/core/exchanges/oanda.py index b8fdad5..01e51db 100644 --- a/core/exchanges/oanda.py +++ b/core/exchanges/oanda.py @@ -43,7 +43,7 @@ class OANDAExchange(BaseExchange): # "price": "1.5000", - added later "stopLossOnFill": {"timeInForce": "GTC", "price": str(trade.stop_loss)}, "takeProfitOnFill": {"price": str(trade.take_profit)}, - "timeInForce": "GTC", + "timeInForce": "IOC", "instrument": trade.symbol, "units": str(amount), "type": trade.type.upper(), diff --git a/core/lib/market.py b/core/lib/market.py index c68904a..e00f35d 100644 --- a/core/lib/market.py +++ b/core/lib/market.py @@ -7,24 +7,6 @@ from core.util import logs log = logs.get_logger(__name__) - -def get_balance(account): - account_info = account.client.get_account() - cash = account_info["equity"] - try: - return float(cash) - except ValueError: - return False - - -def get_market_value(account, symbol): - try: - position = account.client.get_position(symbol) - return float(position["market_value"]) - except APIError: - return False - - def execute_strategy(callback, strategy): cash_balance = strategy.account.client.get_balance() log.debug(f"Cash balance: {cash_balance}") @@ -35,6 +17,9 @@ def execute_strategy(callback, strategy): base = callback.base quote = callback.quote direction = hook.direction + if callback.exchange != account.exchange: + log.error("Market exchange differs from account exchange.") + return if account.exchange == "alpaca": if quote not in ["usd", "usdt", "usdc", "busd"]: log.error(f"Quote not compatible with Dollar: {quote}") diff --git a/core/lib/schemas/oanda_s.py b/core/lib/schemas/oanda_s.py index c206040..921e3d8 100644 --- a/core/lib/schemas/oanda_s.py +++ b/core/lib/schemas/oanda_s.py @@ -179,40 +179,6 @@ AccountDetailsSchema = { } -{ - "account": { - "marginCloseoutNAV": "35454.4740", - "marginUsed": "10581.5000", - "currency": "EUR", - "resettablePL": "-13840.3525", - "NAV": "35454.4740", - "marginCloseoutMarginUsed": "10581.5000", - "marginCloseoutPositionValue": "211630.0000", - "openTradeCount": 2, - "id": "101-004-1435156-001", - "hedgingEnabled": False, - "marginCloseoutPercent": "0.14923", - "marginCallMarginUsed": "10581.5000", - "openPositionCount": 1, - "positionValue": "211630.0000", - "pl": "-13840.3525", - "lastTransactionID": "2123", - "marginAvailable": "24872.9740", - "marginRate": "0.05", - "marginCallPercent": "0.29845", - "pendingOrderCount": 0, - "withdrawalLimit": "24872.9740", - "unrealizedPL": "0.0000", - "alias": "hootnotv20", - "createdByUserID": 1435156, - "marginCloseoutUnrealizedPL": "0.0000", - "createdTime": "2016-06-24T21:03:50.914647476Z", - "balance": "35454.4740", - }, - "lastTransactionID": "2123", -} - - class AccountSummaryNested(BaseModel): marginCloseoutNAV: str marginUsed: str