def phemex_auth(acct_type, account): """ Authenticatate with API using key/secret Returns: Coinbase phemex client object """ api_key = account['key'] api_secret = account['secret'] exchange = ccxt.phemex({ 'enableRateLimit': True, # https://github.com/ccxt/ccxt/wiki/Manual#rate-limit 'apiKey': api_key, # testnet keys if using the testnet sandbox 'secret': api_secret, # testnet keys if using the testnet sandbox 'options': { 'defaultType': acct_type, }, }) return exchange
# -*- coding: utf-8 -*- import os import sys root = os.path.dirname( os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.append(root + '/python') import ccxt # noqa: E402 exchange = ccxt.phemex({ 'apiKey': 'YOUR_API_KEY', 'secret': 'YOUR_SECRET', 'enableRateLimit': True, }) # exchange.set_sandbox_mode(True) # Example 1: Creating stop-market order symbol = 'LTC/USDT' type = 'market' side = 'buy' amount = 0.5 params = { 'stopPrice': 50, } stop_market = exchange.create_order(symbol, type, side, amount, None, params) print(stop_market)
import sys from pprint import pprint root = os.path.dirname( os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.append(root + '/python') import ccxt # noqa: E402 print('CCXT Version:', ccxt.__version__) exchange = ccxt.phemex({ 'enableRateLimit': True, # https://github.com/ccxt/ccxt/wiki/Manual#rate-limit 'apiKey': 'YOUR_API_KEY', # testnet keys if using the testnet sandbox 'secret': 'YOUR_SECRET', # testnet keys if using the testnet sandbox 'options': { 'defaultType': 'swap', }, }) # exchange.set_sandbox_mode(True) # uncomment to use the testnet sandbox markets = exchange.load_markets() # example 1 positions = exchange.fetch_positions(None, {'code': 'BTC'}) pprint(positions) print('------------------------------------------------------------')
import os import sys from pprint import pprint root = os.path.dirname( os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.append(root + '/python') import ccxt # noqa: E402 print('CCXT Version:', ccxt.__version__) exchange = ccxt.phemex({ 'apiKey': 'YOUR_API_KEY', # testnet keys if using the testnet sandbox 'secret': 'YOUR_SECRET', # testnet keys if using the testnet sandbox 'options': { 'defaultType': 'swap', }, }) # exchange.set_sandbox_mode(True) # uncomment to use the testnet sandbox markets = exchange.load_markets() amount = 20 symbol = 'BTC/USD:USD' # Opening and Canceling a pending contract (limit) order order = exchange.create_order(symbol, 'limit', 'buy', amount, '20000') response = exchange.cancel_order(order['id'], symbol) pprint(response)
def bind_ccxt(self): return ccxt.phemex(self.ccxt_args)
# -*- coding: utf-8 -*- import os import sys root = os.path.dirname( os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.append(root + '/python') import ccxt # noqa: E402 exchange = ccxt.phemex({ 'apiKey': 'YOUR_API_KEY', 'secret': 'YOUR_SECRET', }) # exchange.set_sandbox_mode(True) # Example 1: Creating stop-market order symbol = 'LTC/USDT' type = 'market' side = 'buy' amount = 0.5 params = { 'stopPrice': 50, } stop_market = exchange.create_order(symbol, type, side, amount, None, params) print(stop_market)
#fetch lowest bid and highest ask between phemex and bitmex import matplotlib.pyplot as plt import matplotlib.animation as animation from matplotlib import style import ccxt import time import datetime import os test_mode = True #initialize exchanges exchange = ccxt.bitmex() exchange2 = ccxt.phemex() #Depending on test mode, configures exchanges and api keys if test_mode == True: exchange2.set_sandbox_mode(True) if 'test' in exchange.urls: exchange.urls['api'] = exchange.urls['test'] exchange.apiKey = 'lvSX7y8egJqSVz68fl2sQMSH' exchange.secret = 'MaK-UKQNEFBUz2mZEsbI8gPIi2dqYCcuqpWqpP-VJlj3rjqK' exchange2.apiKey = '70dc8e4d-ef5f-49b0-8d14-c58d65203d97' exchange2.secret = 'cIupY1__5mgXg01MTbLVASlp5vZHu7No_sxnu1RqBBNjYTViYTg4Yi1lYzg2LTQ0NjctOGY5MS0yOGZjNDJkZDMwYTY' else: exchange.apiKey = 'WAX0woPHSd5XdsqpM361HqaB' exchange.secret = 'loDFqktFVo826ErMF8Dc5ioZYitevlYbuSdiBzBn91LJJTSH' exchange2.apiKey = 'd51e6c97-d3a6-41ee-82b3-224e3d439073' exchange2.secret = 'ZjEvIv1pGuYaDS1zOr1tj0ths0ESOE86p1rSiHDMpWFiNmE0MDk2My0zMzA5LTRmZTgtYTM4ZS1lNjY4ZTI3Zjc5ZGI' #load markets markets = exchange.load_markets() markets2 = exchange2.load_markets()