1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
# -*- coding: utf-8 -*-
# pylint: disable=C0111,C0103,R0205
import json
import random
import pika
from pika.exchange_type import ExchangeType
print('pika version: %s' % pika.__version__)
connection = pika.BlockingConnection(
pika.ConnectionParameters(host='localhost'))
main_channel = connection.channel()
main_channel.exchange_declare(exchange='com.micex.sten', exchange_type=ExchangeType.direct)
main_channel.exchange_declare(
exchange='com.micex.lasttrades', exchange_type=ExchangeType.direct)
tickers = {
'MXSE.EQBR.LKOH': (1933, 1940),
'MXSE.EQBR.MSNG': (1.35, 1.45),
'MXSE.EQBR.SBER': (90, 92),
'MXSE.EQNE.GAZP': (156, 162),
'MXSE.EQNE.PLZL': (1025, 1040),
'MXSE.EQNL.VTBR': (0.05, 0.06)
}
def getticker():
return list(tickers.keys())[random.randrange(0, len(tickers) - 1)]
_COUNT_ = 10
for i in range(0, _COUNT_):
ticker = getticker()
msg = {
'order.stop.create': {
'data': {
'params': {
'condition': {
'ticker': ticker
}
}
}
}
}
main_channel.basic_publish(
exchange='com.micex.sten',
routing_key='order.stop.create',
body=json.dumps(msg),
properties=pika.BasicProperties(content_type='application/json'))
print('send ticker %s' % ticker)
connection.close()
|