Skip to content

Commit

Permalink
Merge pull request #432 from mraniki/dev
Browse files Browse the repository at this point in the history
🐛 update capitalcom.py, main.py and example.py
  • Loading branch information
mraniki authored Apr 8, 2024
2 parents 8f17f8a + 2100a87 commit 0005c1c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
35 changes: 17 additions & 18 deletions cefi/handler/capitalcom.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async def get_quote(self, instrument):
quote = market["snapshot"]["offer"]
logger.debug("Quote: {}", quote)

return quote
return float(quote)
except Exception as e:
logger.error("{} Error {}", self.name, e)
return e
Expand Down Expand Up @@ -122,7 +122,7 @@ async def get_bid(self, instrument):
quote = market["snapshot"]["bid"]
logger.debug("Quote: {}", quote)

return quote
return float(quote)
except Exception as e:
logger.error("{} Error {}", self.name, e)
return e
Expand Down Expand Up @@ -293,23 +293,22 @@ async def execute_order(self, order_params):
logger.debug("stop price {}", stop_price)
logger.debug("profit price {}", profit_price)
order = self.client.place_the_position(
direction=action,
epic=instrument,
size=amount,
gsl=False,
tsl=False,
stop_level=stop_price,
stop_distance=None,
stop_amount=None,
profit_level=profit_price,
profit_distance=None,
profit_amount=None,
)
# Check if the order response contains an errorCode
direction=action,
epic=instrument,
size=amount,
gsl=False,
tsl=False,
stop_level=stop_price,
stop_distance=None,
stop_amount=None,
profit_level=profit_price,
profit_distance=None,
profit_amount=None,
)

if "errorCode" in order:
# Handle the error, e.g., log it or return a specific message
logger.error(f"Error placing order: {order['errorCode']}")
return f"Error placing order: {order['errorCode']}"
logger.error(f"Error placing order: {order['errorCode']}")
return order["errorCode"]

logger.debug("Order: {}", order)
deal_reference = order["dealReference"]
Expand Down
1 change: 1 addition & 0 deletions cefi/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ async def submit_order(self, order_params):
for client in self.clients:
try:
trade = await client.execute_order(order_params)
logger.debug("trade {}", trade)
order.append(trade)
except Exception as e:
logger.error("submit_order - client {} error {}", client.name, e)
Expand Down
8 changes: 4 additions & 4 deletions examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ async def main():
# # EURUSD: -3.22
order = {
"action": "BUY",
"instrument": "BTCUSD",
"quantity": 200,
"take_profit": 10000,
"stop_loss": 100000,
"instrument": "EURUSD",
"quantity": 10,
"take_profit": 100,
"stop_loss": 1000,
"comment": "test",
}
order = await cex.submit_order(order)
Expand Down

0 comments on commit 0005c1c

Please sign in to comment.