def test_generate_omega_request(): body, omega_mess = _generate_omega_request( RequestHeader(client_id=0, sender_comp_id='asdf', access_token=__FAKE_ACCESS_TOKEN, request_id=100002)) # print(body, '\n', omega_mess) assert type(body) == capnp.lib.capnp._DynamicStructBuilder assert type(omega_mess) == capnp.lib.capnp._DynamicStructBuilder
def __init__(self, zmq_context: zmq.Context, zmq_endpoint: str, client_id: int, sender_comp_id: str, outgoing_message_queue: Queue = None): self._request_sender = RequestSender( zmq_context=zmq_context, zmq_endpoint=zmq_endpoint, outgoing_message_queue=outgoing_message_queue) self._request_header = RequestHeader(client_id=client_id, sender_comp_id=sender_comp_id, access_token='', request_id=0)
def logon_capnp(request_header: RequestHeader, client_secret: str, credentials: List[AccountCredentials]): """ Generates a capnp Logon message with a specific clientID and set of credentials. :param client_secret: (str) client_secret key assigned by Fund3. :param credentials: (List[AccountCredentials]) List of exchange credentials in the form of AccountCredentials. :param request_header: Header parameter object for requests. :return: (capnp._DynamicStructBuilder) Logon capnp object. """ request_header.access_token = '' # Empty in logon omega_message, body = _generate_omega_request( request_header=request_header) logon = body.init('logon') logon.clientSecret = client_secret logon.init('credentials', len(credentials)) logon = _set_logon_credentials(logon=logon, credentials=credentials) return omega_message, logon
def run(self): """ Threaded implementation of automatic session refresh main loop for a single client. """ self._is_running.set() while self.is_running(): # sleep until 10 seconds before the token expires time_until_session_refresh = (self.token_expire_time - dt.utcnow().timestamp() - 10.) print('SessionRefresher sleeping {} seconds'.format( time_until_session_refresh)) time.sleep(seconds=time_until_session_refresh) # increment the request_id self.request_id += 1 # send the authorization refresh request to Omega self.request_sender.request_authorization_refresh( request_header=RequestHeader( client_id=self.client_id, sender_comp_id=self.sender_comp_id, access_token=self.access_token, request_id=self.request_id), auth_refresh=AuthorizationRefresh( refresh_token=self.refresh_token)) self.waiting_for_new_token = True # poll every second waiting for AuthorizationGrant Response to # update token while self.waiting_for_new_token: print('SessionRefresher waiting 1 second for new token') time.sleep(1) return
passphrase='passphrase') TEST_OMEGA_CONFIG = { 'OMEGA_CONNECTION_STR': 'tcp://127.0.0.1:5555', 'CREDENTIALS': [TEST_ACCOUNT_CREDS_1] } TEST_ZMQ_ENCRYPTION_KEY = b'encryptionkeyencryptionkeyencryptionkeye' __FAKE_ROUTER_SOCKET_CONNECTION_STR = 'inproc://FAKE_ROUTER_SOCKET' __FAKE_DEALER_SOCKET_CONNECTION_STR = 'inproc://FAKE_DEALER_SOCKET' __FAKE_REQUEST_SENDER_CONNECTION_STR = 'inproc://FAKE_REQUEST_SENDER' __FAKE_CLIENT_SECRET = ('2B24_ih9IFVdWgxR2sEA3rj0fKlY212Ec_TwTNVCD663ktYb1' + 'ABPz4qJy0Ouze6O9vgdueei0XmZ6uGGFM34nw') __FAKE_ACCESS_TOKEN = 'FakeAccessToken' __FAKE_REQUEST_HEADER = RequestHeader(client_id=123, sender_comp_id='987', access_token=__FAKE_ACCESS_TOKEN, request_id=100001) # TODO: Integration Testing # TODO add test for cancelAllOrders @pytest.fixture(scope="session") def fake_zmq_context(): zmq_context = zmq.Context.instance() yield zmq_context @pytest.fixture(scope="module") def fake_router_socket(fake_zmq_context): router_socket = fake_zmq_context.socket(zmq.ROUTER)