File: producer.py

package info (click to toggle)
python-pika 0.9.14-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,048 kB
  • ctags: 2,110
  • sloc: python: 10,046; makefile: 134
file content (41 lines) | stat: -rw-r--r-- 1,533 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/python
# -*- coding: utf-8 -*-

import pika    
import json
import random

print(('pika version: %s') % pika.__version__)

connection   = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
main_channel = connection.channel()  

if pika.__version__=='0.9.5':
    main_channel.exchange_declare(exchange='com.micex.sten',       type='direct')
    main_channel.exchange_declare(exchange='com.micex.lasttrades', type='direct')
else:
    main_channel.exchange_declare(exchange='com.micex.sten',       exchange_type='direct')
    main_channel.exchange_declare(exchange='com.micex.lasttrades', exchange_type='direct')

tickers = {}
tickers['MXSE.EQBR.LKOH'] = (1933,1940)
tickers['MXSE.EQBR.MSNG'] = (1.35,1.45)
tickers['MXSE.EQBR.SBER'] = (90,92)
tickers['MXSE.EQNE.GAZP'] = (156,162)
tickers['MXSE.EQNE.PLZL'] = (1025,1040)
tickers['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()