コード例 #1
0
ファイル: 2main_binance.py プロジェクト: z772/mirror_trader
def process_message(msg):
    # for debuggin -- printing any message's full data
    # print(msg)
    global copy_clients
    if msg['e'] != 'executionReport':
        return

    try:
        print('processing new message... Action: ' + msg['S'] +
              ' -- Symbol: ' + msg['s'])
        f = open('orders.json', 'a')
        f.write(json.dumps(msg, indent=4, sort_keys=True))
        f.close()
    except Exception as ex:
        print(ex)

    copy_clients = get_clients()
    try:
        count = 0
        # main for-loop where the copy-clients are getting new trades/updates
        for cclient in copy_clients:
            if cclient.active == False:
                continue
            try:
                count = count + 1

                if msg['e'] == 'executionReport' and msg['x'] != "CANCELED":
                    if count == 1:
                        print('\nMASTER ACCOUNT:: Placed an order: ' +
                              str(msg) + '\n')
                        if msg['o'] != 'MARKET':
                            mainOrders.append(msg['i'])
                    copy_order(cclient, msg, count)
                    continue
                else:
                    if 'CANCELED' == msg['x']:
                        if count == 1:
                            print('\nMASTER ACCOUNT:: Cancelled order ' +
                                  str(msg['i']))
                            if msg['i'] in mainOrders:
                                mainOrders.pop(mainOrders.index(msg['i']))
                        cancel_order(cclient, msg)

            except Exception as ex:
                console_message(ex, "binance")
    except Exception as ex:
        console_message(ex, "binance")
コード例 #2
0
import os
import sys

__DIR__ = os.path.dirname(os.path.realpath(__file__))

sys.path.insert(0, __DIR__)
sys.path.insert(0, __DIR__ + '/../')

from modules.helper import *


list_clients(get_clients(), 'deribit')

# Read the deribit API keys - also do check if is testnet or not
f = open(__DIR__ + '/main_account.txt', 'r')
CREDENTIALS = f.read().split('\n')
CREDENTIALS = CREDENTIALS[0].split('   ')

api_key = CREDENTIALS[0]
api_secret = CREDENTIALS[1]
testnet = CREDENTIALS[2]

os.environ['DERIBIT_API_KEY'] = api_key
os.environ['DERIBIT_API_SECRET'] = api_secret
if testnet == 'testnet':
	os.environ["RUN_ENV"] = 'development'
else:
	os.environ["RUN_ENV"] = 'live'

from deribitapi import Deribit
from deribit_websocket import DeribitWebsocket
コード例 #3
0
import os
import sys
from binance.client import Client
from binance.websockets import BinanceSocketManager

__DIR__ = os.path.dirname(os.path.realpath(__file__))

sys.path.insert(0, __DIR__)
sys.path.insert(0, __DIR__ + '/../')

from modules.helper import *

list_clients(get_clients(), 'binance')

# Read the main_account's API keys
f = open(__DIR__ + '/main_account.txt', 'r')
CREDENTIALS = f.read().split('\n')
CREDENTIALS = CREDENTIALS[0].split('   ')

print(CREDENTIALS[0])
print(CREDENTIALS[1])

binance_api_key = CREDENTIALS[0]
binance_api_secret = CREDENTIALS[1]

os.environ['BINANCE_API_KEY'] = binance_api_key
os.environ['BINANCE_API_SECRET'] = binance_api_secret


from copy_clients import copy_order
from copy_clients import init_copy_clients
コード例 #4
0
def process_message(msg):
    # for debuggin -- printing any message's full data
    # print(msg)
    global copy_clients

    if msg['table'] == 'position':
        if 'leverage' not in msg['data'][0].keys():
            if 'crossMargin' not in msg['data'][0].keys():
                return
    try:
        print('processing new message... Action:' + msg['action'] +
              ' -- Symbol:' + msg['data'][0]['symbol'])
        if msg['action'] != 'partial':
            if msg['action'] == 'update' and (msg['data'][0]['orderID']
                                              not in mainOrders):
                return
            f = open(__DIR__ + '/orders.json', 'a')
            f.write(json.dumps(msg, indent=4, sort_keys=True))
            f.close()
    except Exception as ex:
        print(ex)

    update_copy_clients(balance, resetArgs, symbols)
    copy_clients = get_clients()
    try:
        count = 0
        for cclient in copy_clients:
            if cclient.active == False:
                continue
            try:
                count = count + 1
                if msg['table'] == 'position' and (
                        'leverage' in msg['data'][0].keys()
                        or 'crossMargin' in msg['data'][0].keys()):
                    if msg['data'][0]['liquidationPrice'] != 0:
                        update_position(cclient, msg, 'price')
                        continue

                if msg['action'] == 'insert':
                    if count == 1:
                        print('\nMASTER ACCOUNT:: Placed an order: ' +
                              str(msg['data'][0]) + '\n')
                        if msg['data'][0]['ordType'] != 'Market':
                            mainOrders.append(msg['data'][0]['orderID'])
                    copy_order(cclient, msg, count)
                    continue

                if msg['action'] == 'update':
                    msgKeys = msg['data'][0].keys()

                    if 'price' in msgKeys:
                        if count == 1:
                            print('\nMASTER ACCOUNT:: Updated Price: ' +
                                  str(msg['data'][0]) + '\n')
                        update_order(cclient, msg, 'price')
                        continue

                    if 'pegOffsetValue' in msgKeys:
                        if count == 1:
                            print('\nMASTER ACCOUNT:: Updated stopPx: ' +
                                  str(msg['data'][0]) + '\n')
                        update_order(cclient, msg, 'pegOffsetValue')
                        continue

                    if 'stopPx' in msgKeys:
                        if count == 1:
                            print('\nMASTER ACCOUNT:: Updated stopPx: ' +
                                  str(msg['data'][0]) + '\n')
                        update_order(cclient, msg, 'stopPx')

                    if 'orderQty' in msgKeys:
                        if count == 1:
                            print('\nMASTER ACCOUNT:: Updated Quantity: ' +
                                  str(msg['data'][0]) + '\n')
                        update_order(cclient, msg, 'orderQty')

                    if 'ordStatus' in msgKeys:
                        if 'Canceled' == msg['data'][0]['ordStatus']:
                            if count == 1:
                                for cnclOrd in msg['data']:
                                    print(
                                        '\nMASTER ACCOUNT:: Cancelled order ' +
                                        cnclOrd['orderID'])
                                    if cnclOrd['orderID'] in mainOrders:
                                        mainOrders.pop(
                                            mainOrders.index(
                                                cnclOrd['orderID']))
                            cancel_order(cclient, msg)
            except Exception as ex:
                print(ex)
    except Exception as ex:
        print(ex)
コード例 #5
0
import os
import sys

__DIR__ = os.path.dirname(os.path.realpath(__file__))

sys.path.insert(0, __DIR__)
sys.path.insert(0, __DIR__ + '/../')

from modules.helper import *

list_clients(get_clients(), 'bitmex')

# Read the bitmex API keys - also do check if is testnet or not
f = open(__DIR__ + '/main_account.txt', 'r')
CREDENTIALS = f.read().split('\n')
CREDENTIALS = CREDENTIALS[0].split('   ')

bitmex_key = CREDENTIALS[0]
bitmex_secret = CREDENTIALS[1]
testnet = CREDENTIALS[2]

os.environ['BITMEX_API_KEY'] = bitmex_key
os.environ['BITMEX_API_SECRET'] = bitmex_secret
if testnet == 'testnet':
    os.environ["RUN_ENV"] = 'development'
else:
    os.environ["RUN_ENV"] = 'live'

import bitmex
from bitmex_websocket import Instrument
from copy_clients import copy_order