Skip to content

Commit

Permalink
Merge pull request #333 from mraniki/dev
Browse files Browse the repository at this point in the history
⬆️ 🤖 - Your business will go through a period of considerable expansion
  • Loading branch information
mraniki authored Feb 11, 2024
2 parents 49429c9 + 70e5b4a commit 4561fba
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 79 deletions.
43 changes: 9 additions & 34 deletions cefi/protocol/ccxt.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,57 +27,32 @@ class CexCcxt(CexClient):

def __init__(
self,
protocol="ccxt",
name=None,
api_key=None,
secret=None,
password=None,
testmode=True,
defaulttype="spot",
ordertype="market",
leverage_type="isolated",
leverage=1,
trading_risk_percentage=True,
trading_risk_amount=1,
trading_slippage=2,
trading_amount_threshold=0,
trading_asset="USDT",
trading_asset_separator=None,
mapping=None,
**kwargs,
):
"""
Initialize the ccxt client
"""
super().__init__(**kwargs)
self.protocol="ccxt"
client = getattr(ccxt, self.name)

client = getattr(ccxt, name)
self.client = client(
{
"apiKey": api_key,
"secret": secret,
"password": password,
"apiKey": self.api_key,
"secret": self.secret,
"password": self.password,
"enableRateLimit": True,
"options": {
"defaultType": defaulttype,
"defaultType": self.defaulttype,
},
}
)
if testmode:
if self.testmode:
self.client.set_sandbox_mode("enabled")
self.account_number = self.client.uid
self.name = self.client.id
self.trading_asset = trading_asset
self.separator = trading_asset_separator
self.trading_risk_percentage = trading_risk_percentage
self.trading_risk_amount = trading_risk_amount
self.trading_slippage = trading_slippage
self.trading_amount_threshold = trading_amount_threshold
self.leverage_type = leverage_type
self.leverage = leverage
self.defaulttype = defaulttype
self.ordertype = ordertype
self.mapping = mapping


async def get_quote(self, instrument):
"""
Expand Down
47 changes: 46 additions & 1 deletion cefi/protocol/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,57 @@ class CexClient:

def __init__(
self,
**kwargs,
protocol=None,
name=None,
user_id=None,
api_key=None,
host=None,
port=None,
broker_client_id=None,
broker_account_number=None,
broker_gateway=True,
secret=None,
password=None,
testmode=True,
defaulttype="spot",
ordertype="market",
leverage_type="isolated",
leverage=1,
trading_risk_percentage=True,
trading_risk_amount=1,
trading_slippage=2,
trading_amount_threshold=0,
trading_asset="USDT",
trading_asset_separator=None,
mapping=None,
):
"""
Initialize the Cex object
"""
self.protocol = protocol
self.name = name
self.user_id = user_id
self.api_key = api_key
self.host = host
self.port = port
self.broker_client_id = broker_client_id
self.broker_account_number = broker_account_number
self.broker_gateway = broker_gateway
self.secret = secret
self.password = password
self.testmode = testmode
self.trading_asset = trading_asset
self.separator = trading_asset_separator
self.trading_risk_percentage = trading_risk_percentage
self.trading_risk_amount = trading_risk_amount
self.trading_slippage = trading_slippage
self.trading_amount_threshold = trading_amount_threshold
self.leverage_type = leverage_type
self.leverage = leverage
self.defaulttype = defaulttype
self.ordertype = ordertype
self.mapping = mapping

async def get_quote(self, symbol):
"""
Expand Down
53 changes: 10 additions & 43 deletions cefi/protocol/ib_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,6 @@ class CexIB(CexClient):

def __init__(
self,
protocol="ib",
name=None,
user_id=None,
api_key=None,
host=None,
port=None,
broker_client_id=None,
broker_account_number=None,
broker_gateway=True,
secret=None,
password=None,
testmode=True,
defaulttype="spot",
ordertype="market",
leverage_type="isolated",
leverage=1,
trading_risk_percentage=True,
trading_risk_amount=1,
trading_slippage=2,
trading_amount_threshold=0,
trading_asset="USDT",
trading_asset_separator=None,
mapping=None,
**kwargs,
):
"""
Expand All @@ -69,35 +46,25 @@ def __init__(
a debug message using the logger module.
"""

self.trading_asset = trading_asset
self.separator = trading_asset_separator
self.trading_risk_percentage = trading_risk_percentage
self.trading_risk_amount = trading_risk_amount
self.trading_slippage = trading_slippage
self.trading_amount_threshold = trading_amount_threshold
self.leverage_type = leverage_type
self.leverage = leverage
self.defaulttype = defaulttype
self.ordertype = ordertype
self.mapping = mapping
if broker_gateway:
super().__init__(**kwargs)
self.protocol="ib"
if self.broker_gateway:
ibc = IBC(
976,
gateway=True,
tradingMode="paper" if testmode else "live",
userid=user_id,
password=password,
tradingMode="paper" if self.testmode else "live",
userid=self.user_id,
password=self.password,
)
ibc.start()
IB.run()
self.client = IB()
self.client.connect(
host=host,
port=port,
clientId=broker_client_id or 1,
host=self.host,
port=self.port,
clientId=self.broker_client_id or 1,
readonly=False,
account=broker_account_number or "",
account=self.broker_account_number or "",
)
self.name = self.client.id
self.account_number = self.client.managedAccounts()[0]
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ packages = [
python = "^3.10"
dynaconf = ">=3.1.12"
loguru = ">=0.6"
ccxt = "4.2.41"
ccxt = "4.2.42"
ib_insync = "0.9.86"

[ tool.poetry.group.dev.dependencies]
Expand Down

0 comments on commit 4561fba

Please sign in to comment.