Skip to content

Commit

Permalink
Merge pull request #440 from mraniki/dev
Browse files Browse the repository at this point in the history
🔇 update capitalcom.py and main.py
  • Loading branch information
mraniki authored Apr 10, 2024
2 parents 1923d0e + 78df318 commit b4eac79
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
12 changes: 6 additions & 6 deletions cefi/handler/capitalcom.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ async def get_quote(self, instrument):
logger.debug("Instrument: {}", instrument)
instrument = await self.replace_instrument(instrument)
logger.debug("Changed Instrument: {}", instrument)
search_markets = self.client.searching_market(searchTerm=instrument)
# search_markets = self.client.searching_market(searchTerm=instrument)
await asyncio.sleep(1) # Wait for 1 second
logger.debug("Instrument verification: {}", search_markets)
# logger.debug("Instrument verification: {}", search_markets)

market = self.client.single_market(instrument)
logger.debug("Raw Quote: {}", market)
# logger.debug("Raw Quote: {}", market)

quote = market["snapshot"]["offer"]
logger.debug("Quote: {}", quote)
Expand Down Expand Up @@ -131,12 +131,12 @@ async def get_bid(self, instrument):
logger.debug("Instrument: {}", instrument)
instrument = await self.replace_instrument(instrument)
logger.debug("Changed Instrument: {}", instrument)
search_markets = self.client.searching_market(searchTerm=instrument)
# search_markets = self.client.searching_market(searchTerm=instrument)
await asyncio.sleep(1) # Wait for 1 second
logger.debug("Instrument verification: {}", search_markets)
# logger.debug("Instrument verification: {}", search_markets)

market = self.client.single_market(instrument)
logger.debug("market: {}", market)
# logger.debug("market: {}", market)

quote = market["snapshot"]["bid"]
logger.debug("Quote: {}", quote)
Expand Down
6 changes: 4 additions & 2 deletions cefi/handler/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,15 @@ async def get_order_amount(self, quantity, instrument, is_percentage=True):
logger.debug("Quote {}", quote)

if not is_percentage and balance and quote:
logger.debug("Amount based on money {}", balance * quantity / quote)
return quantity

if balance and quote:
risk_percentage = float(quantity) / 100
amount = balance * risk_percentage / quote
logger.debug("Amount {}", amount)
logger.debug("Amount based on percentage {}", amount)
if amount >= self.trading_amount_threshold:
logger.debug("Amount above threshold {}", amount)
return amount

async def pre_order_checks(self, order_params):
Expand Down Expand Up @@ -250,6 +252,6 @@ async def get_trade_confirmation(self, trade, instrument, action):
trade_confirmation += f"ℹ️ {trade['id']}\n"
trade_confirmation += f"🗓️ {trade['datetime']}"
if trade_confirmation:
return f"{self.name}:\n{trade_confirmation}"
return f"{trade_confirmation}"
except Exception as e:
logger.error("Error {}", e)
4 changes: 3 additions & 1 deletion cefi/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,5 +257,7 @@ async def submit_order(self, order_params):
"""
_order = ["🧾 Order\n"]
for client in self.clients:
_order.append(f"{client.name}: {await client.execute_order(order_params)}")
_order.append(
f"{client.name}:\n{await client.execute_order(order_params)}\n"
)
return "\n".join(_order)
2 changes: 1 addition & 1 deletion tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ async def test_get_trade_confirmation(CXTrader):

for client in CXTrader.clients:
result = await client.get_trade_confirmation(trade, "InstrumentName", "SELL")
assert ("binance" in result) or ("huobi" in result) or ("capital" in result)
# assert ("binance" in result) or ("huobi" in result) or ("capital" in result)
assert "⬇️" in result
assert "⚫" in result
assert "🔵" in result
Expand Down

0 comments on commit b4eac79

Please sign in to comment.