Created
February 7, 2017 11:07
-
-
Save pinhopro/cf171dad31f00348cbb55f267d753947 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sys.path.insert( 0, os.path.join(ROOT_PATH, 'apps')) | |
sys.path.insert( 0, os.path.join(ROOT_PATH, 'libs')) | |
import zmq | |
from bitex.message import JsonMessage, InvalidMessageException | |
from bitex.zmq_client import TradeClient, TradeClientException | |
context = zmq.Context() | |
trade_in_socket = context.socket(zmq.REQ) | |
trade_in = "tcp://127.0.0.1:5755" | |
trade_in_socket.connect(trade_in) | |
t = TradeClient(context, trade_in_socket) | |
t.connect() | |
def add_user(user_id): | |
t = TradeClient(context, trade_in_socket) | |
t.connect() | |
t.sendJSON( {"MsgType":"U0","Username": str(user_id) ,"Password":"password" + str(user_id) , "Email": str(user_id) + "@nybitcoincenter.com", "BrokerID":1 } ) | |
for x in xrange( 3, 1001 ): | |
#add_user(x) | |
pass | |
def sendBuyOrder( qty, price, badgeId ): | |
qty = qty*1e8 | |
price = price*1e8 | |
t.sendJSON( {"MsgType":"D","ClOrdID":"9963611","Symbol":"BTCBRL","Side":"1","OrdType":"2","Price": int(price), "OrderQty": int(qty), "ClientID": badgeId}) | |
def sendSellOrder( qty, price, badgeId ): | |
qty = qty*1e8 | |
price = price*1e8 | |
t.sendJSON( {"MsgType":"D","ClOrdID":"9963611","Symbol":"BTCBRL","Side":"2","OrdType":"2","Price": int(price), "OrderQty": int(qty), "ClientID": badgeId}) | |
def reconnect(): | |
global t | |
t = TradeClient(context, trade_in_socket) | |
t.connect() | |
def login(username, password): | |
t.sendJSON( {"MsgType":"BE","UserReqID":"1","Username":username,"Password":password,"UserReqTyp":"1"} ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment