예제 #1
0
    config_dict = json.load(config_file)

# SETUP CREDENTIALS
username = config_dict['username']
password = config_dict['password']

credentials = Credentials(
    int_account=None,
    username=username,
    password=password,
)

# SETUP TRADING API
trading_api = TradingAPI(credentials=credentials)

# CONNECT
trading_api.connect()

# FETCH CONFIG TABLE
config_table = trading_api.get_config()

# EXTRACT DATA
user_token = config_table['clientId']
session_id = config_table['sessionId']

# DISPLAY DATA
config_pretty = json.dumps(config_table, sort_keys=True, indent=4)

print('Your "user_token" is :', user_token)
print('Here is the rest of config :', config_pretty)
예제 #2
0
# SETUP TRADING API
trading_api = TradingAPI(credentials=credentials)

# CONNECT
trading_api.connect()

# ACCESS SESSION_ID
session_id = trading_api.connection_storage.session_id

# Waiting
sleep_time = random.uniform(1, 5)
print(f'Waiting : {sleep_time}s ')
time.sleep(sleep_time)

# FETCH CONFIG TABLE
print(len(trading_api.get_config()))

# LOGOUT
print('Logout, session id : ', session_id)
trading_api.logout()

try:
    # FETCH CONFIG TABLE
    print(len(trading_api.get_config()))
except ConnectionError as e:
    print(e)
    print('Logout : success !')
else:
    print('Logout : fail !')