首页   注册   登录
 chengxuan 最近的时间轴更新
chengxuan

chengxuan

V2EX 第 55513 号会员,加入于 2014-02-08 21:32:03 +08:00
求助:如何用 py 修改整段 linux 服务器内文件内容?有神器吗?
Python  •  chengxuan  •  2014-08-18 00:21:58 AM  •  最后回复来自 jpuyy
14
求助,如何把 linux 系统制作成为 img 镜像
Linux  •  chengxuan  •  2014-07-16 23:49:35 PM  •  最后回复来自 sandtears
8
求助 python 报错误 给予解决者 100 元话费
Python  •  chengxuan  •  2014-06-01 13:49:14 PM  •  最后回复来自 xuzhe
36
人生第一次入手 macbook pro 大家都在用神马软件?求推荐
MacBook Pro  •  chengxuan  •  2014-12-11 11:26:51 AM  •  最后回复来自 shiongmao
19
chengxuan 最近回复了
sudo reboot 试试吧!
2014-08-19 13:02:16 +08:00
回复了 XXOO 创建的主题 云计算 腾讯云 HK IP 测试
@xxoo 好贵阿!!
@magine 感谢 我试试。。哈哈 没事 没事。。。
@janxin 还有其他吗?
2014-07-16 15:16:59 +08:00
回复了 chengxuan 创建的主题 Linux 求助,如何把 linux 系统制作成为 img 镜像
急急急!!
2014-05-31 17:49:58 +08:00
回复了 chengxuan 创建的主题 Python 求助 python 报错误 给予解决者 100 元话费
@binux 在线等你。。
2014-05-31 17:42:32 +08:00
回复了 chengxuan 创建的主题 Python 求助 python 报错误 给予解决者 100 元话费
@binux qq或者mail发给我[email protected]
2014-05-31 17:34:24 +08:00
回复了 chengxuan 创建的主题 Python 求助 python 报错误 给予解决者 100 元话费
@liushuaikobe
@binux
@Crossin
源码贴出,跪谢各位大神。

#coding=utf-8
import time, re, requests, md5, urllib, urllib2, json ,sys ,os
#sys.path.append(os.path.dirname(__file__).replace('\\','/'))
from huobi import HuoBi
from bitfinex import Bitfinex
from configs import config,keys
class getprice(object):
def __init__(self):
#获取动态配置
self.huobi = HuoBi(keys['huobi']['key'],keys['huobi']['secretKey'])
self.bitf = Bitfinex(keys['bitf']['key'],keys['bitf']['secretKey'])
def buy_seller(self):
p1 = self.get_huobi()
pr1 = p1['sell']
p2 = self.get_bitf()
pr2 = p2['sell'] * config['rate']
if pr1 > pr2:
pre = (pr1 - pr2) / pr1 * 100
if pre >= config['agio']:
self.huobi_sell(p1['buy'])
self.bitf_sell('buy',p2['sell'])
else:
pre = (pr2 - pr1) / pr2 * 100
if pre >= config['agio']:
self.huobi_buy(p1['sell'])
self.bitf_sell('sell',p2['buy'])
print("huobi : %s %s finex : %s ") % (pr1,pre,pr2)
def get_huobi_seller(self):
try:
r = requests.get('http://market.huobi.com/staticmarket/depth_btc_json.js')
return r
except:
time.sleep(18)
self.get_huobi_seller()
def get_bitf_seller(self):
try:
r = requests.get('https://api.bitfinex.com/v1/book/btcusd')
return r
except:
time.sleep(18)
self.get_bitf_seller()
def get_huobi(self):
r1 = self.get_huobi_seller()
t = r1.json()
p1 = t['asks'][-5]
p2 = t['bids'][4]
pr1 = float(p1[0])
pr2 = float(p2[0])
return {'buy':pr2,'sell':pr1}
def get_bitf(self):
r2 = self.get_bitf_seller()
t = r2.json()
p1 = t['asks'][4]
p2 = t['bids'][4]
pr1 = float(p1['price'])
pr2 = float(p2['price'])
return {'buy':pr2,'sell':pr1}
def huobi_sell(self,price=''):
#getattr(huobi,method)
price = self.get_huobi()
price = price['buy']
info = self.huobi.sell(price,config['amount']) #{u'result': u'success', u'id': 18161354}
print(info)
def huobi_buy(self,price):
info = self.huobi.buy(price,config['amount'])
print(info)
def bitf_sell(self,side='sell',price=''):
"""
symbol (string): The name of the symbol (see `/symbols`).
amount (decimal): Order size: how much to buy or sell.
price (price): Price to buy or sell at. May omit if a market order.
exchange (string): "bitfinex".
side (string): Either "buy" or "sell".
type (string): Either "market" / "limit" / "stop" / "trailing-stop" / "fill-or-kill" / "exchange market" / "exchange limit" / "exchange stop" / "exchange trailing-stop" / "exchange fill-or-kill". (type starting by "exchange " are exchange orders, others are margin trading orders)
is_hidden (bool) true if the order should be hidden. Default is false.
"""
price = self.get_bitf()
price = price['buy']

params = {
"symbol":"btcusd",
"amount" : str(config['amount']),
"price" : str(price),
"exchange" : "bitfinex",
"side" : side,
"type" : "exchange market",
}

info = self.bitf.order_new(params)
print(info)
x = getprice()
while config['start']:
x.buy_seller()
time.sleep(18)
关于   ·   FAQ   ·   API   ·   我们的愿景   ·   广告投放   ·   感谢   ·   实用小工具   ·   910 人在线   最高记录 5168   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.3 · 15ms · UTC 20:06 · PVG 04:06 · LAX 12:06 · JFK 15:06
♥ Do have faith in what you're doing.