Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_struct_missing_parameter(self):
result = {
"BrokerID": "45544",
"FromCurrencyID": "",
"FromCurrencyUnit": 0.0,
"ToCurrencyID": "4334",
"ExchangeRate": 11.0
}
field = ApiStructure.ExchangeRateField(
BrokerID="45544",
ToCurrencyID="4334",
ExchangeRate=11.0
)
result_dict = field.to_dict()
self.assertDictEqual(result_dict, result)
def test_to_dict(self):
result = {
"BrokerID": "45544",
"FromCurrencyID": "4343",
"FromCurrencyUnit": 19.0,
"ToCurrencyID": "4334",
"ExchangeRate": 11.0
}
field = ApiStructure.ExchangeRateField(
BrokerID="45544",
FromCurrencyID="4343",
FromCurrencyUnit=19.0,
ToCurrencyID="4334",
ExchangeRate=11.0
)
result_dict = field.to_dict()
self.assertDictEqual(result, result_dict)
def test_from_dict(self):
result = {
"BrokerID": "45544",
"FromCurrencyID": "4343",
"FromCurrencyUnit": 19.0,
"ToCurrencyID": "4334",
"ExchangeRate": 11.0
}
field = ApiStructure.ExchangeRateField.from_dict(result)
self.assertEqual(field.BrokerID, b"45544")
self.assertEqual(field.FromCurrencyID, b"4343")
self.assertEqual(field.FromCurrencyUnit, 19.0)
self.assertEqual(field.ToCurrencyID, b"4334")
self.assertEqual(field.ExchangeRate, 11.0)
def test_dict_missing_parameter(self):
result = {
"BrokerID": "45544",
"ToCurrencyID": "4334",
"ExchangeRate": 11.0
}
field = ApiStructure.ExchangeRateField.from_dict(result)
self.assertEqual(field.BrokerID, b"45544")
self.assertEqual(field.FromCurrencyID, b"")
self.assertEqual(field.FromCurrencyUnit, 0.0)
self.assertEqual(field.ToCurrencyID, b"4334")
self.assertEqual(field.ExchangeRate, 11.0)
def test_get_version(self):
print(MdApiPy.GetApiVersion())
#
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ctpwrapper. If not, see .
"""
import time
from ctpwrapper.TraderApi import TraderApiWrapper
class TraderApiPy(TraderApiWrapper):
def Create(self, pszFlowPath=""):
super(TraderApiPy, self).Create(pszFlowPath.encode())
def Release(self):
super(TraderApiPy, self).Release()
def Init(self):
super(TraderApiPy, self).Init()
time.sleep(0.1) # wait for c++ init
def Join(self):
return super(TraderApiPy, self).Join()
def GetTradingDay(self):
"""
def OnRspUserLogin(self, pRspUserLogin, pRspInfo, nRequestID, bIsLast):
if pRspInfo.ErrorID != 0:
print("Md OnRspUserLogin failed error_id=%s msg:%s",
pRspInfo.ErrorID, pRspInfo.ErrorMsg.decode('gbk'))
else:
print("Md user login successfully")
inv = ApiStructure.QryInvestorField(BrokerID=self.broker_id, InvestorID=self.investor_id)
self.ReqQryInvestor(inv, self.inc_request_id())
req = ApiStructure.SettlementInfoConfirmField.from_dict({"BrokerID": self.broker_id,
"InvestorID": self.investor_id})
self.ReqSettlementInfoConfirm(req, self.inc_request_id())
def OnFrontConnected(self):
req = ApiStructure.ReqUserLoginField(BrokerID=self.broker_id,
UserID=self.investor_id,
Password=self.password)
self.ReqUserLogin(req, self.request_id)
print("trader on front connection")
def OnFrontConnected(self):
"""
:return:
"""
user_login = ApiStructure.ReqUserLoginField(BrokerID=self.broker_id,
UserID=self.investor_id,
Password=self.password)
self.ReqUserLogin(user_login, self.request_id)
def OnRspUserLogin(self, pRspUserLogin, pRspInfo, nRequestID, bIsLast):
if pRspInfo.ErrorID != 0:
print("Md OnRspUserLogin failed error_id=%s msg:%s",
pRspInfo.ErrorID, pRspInfo.ErrorMsg.decode('gbk'))
else:
print("Md user login successfully")
inv = ApiStructure.QryInvestorField(BrokerID=self.broker_id, InvestorID=self.investor_id)
self.ReqQryInvestor(inv, self.inc_request_id())
req = ApiStructure.SettlementInfoConfirmField.from_dict({"BrokerID": self.broker_id,
"InvestorID": self.investor_id})
self.ReqSettlementInfoConfirm(req, self.inc_request_id())