def get_hq(keyword, platform): if platform == 'okcoin': apikey = '99ad2439-28f3-4297-8532-54ce8b7dc52c' secretkey = 'E1AE48319FF5C7C6ADA39C3040ACC6B8' okcoinRESTURL = 'www.okcoin.cn' # 请求注意:国内账号需要 修改为 www.okcoin.cn okcoinSpot = OKCoinSpot(okcoinRESTURL, apikey, secretkey) ticker_key = keyword + '_cny' f = okcoinSpot.ticker(ticker_key) doc = f # doc = json.loads(f) print(u' 现货行情 ') print(doc) timeArray = time.localtime(int(doc['date'])) otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray) ret_msg = keyword + ''' 最新成交价:¥{} 买一:¥{} 卖一:¥{} 最高:¥{} 最低:¥{} 成交量:{} 时间:{} ''' return ret_msg.format(doc['ticker']['last'], doc['ticker']['buy'], doc['ticker']['sell'], doc['ticker']['high'], doc['ticker']['low'], doc['ticker']['vol'], otherStyleTime) elif platform == 'chbtc': hq = get_hq_chbtc(keyword) print(hq) return hq else: pass
def api_get(self, method, params={}): # 现货API if self.account: apikey, secretkey = get_account_key("okex", self.account) okcoinSpot = OKCoinSpot(okcoinRESTURL, apikey, secretkey) if method == "userinfo": api_do = "okcoinSpot.%s()" % (method) return eval(api_do) elif method in ["buy", "sell"]: return okcoinSpot.trade(params["symbol"], method, params["price"], params["amount"]) elif method == "cancelOrder": return okcoinSpot.cancelOrder(params["symbol"], params["id"]) elif method in ["order_info", "orders_info"]: return okcoinSpot.orderinfo(params["symbol"], params["id"]) elif method == "ticker": return okcoinSpot.ticker(symbol=params["symbol"]) elif method == "funds_transfer": return okcoinSpot.funds_transfer(params["amount"],params["From"],params["To"], params["symbol"]) elif method == "withdraw": #tradepwd = get_tradepwd("okex", self.account) tradepwd="huangxinyu2" return okcoinSpot.withdraw(params["symbol"], params["address"], params["amount"], tradepwd, params["fee"], params["addr_tag"])
def api_get(self, method, params={}): # 现货API if self.account: apikey, secretkey = get_account_key("okex", self.account) okcoinSpot = OKCoinSpot(okcoinRESTURL, apikey, secretkey) if method == "userinfo": api_do = "okcoinSpot.%s()" % (method) return eval(api_do) elif method in ["buy", "sell"]: return okcoinSpot.trade(params["symbol"], method, params["price"], params["amount"]) elif method == "cancelOrder": return okcoinSpot.cancelOrder(params["symbol"], params["id"]) elif method in ["order_info", "orders_info"]: return okcoinSpot.orderinfo(params["symbol"], params["id"]) elif method == "ticker": return okcoinSpot.ticker(symbol=params["symbol"]) elif method == "funds_transfer": return okcoinSpot.funds_transfer(params["amount"], params["from"], params["to"], symbol=params["symbol"])
def __init__(self, dbconfig, credential): self.__my_future_client = OKCoinFuture(credential['okcoinRESTURL'], credential['apikey'], credential['secretkey']) self.__my_spot_client = OKCoinSpot(credential['okcoinRESTURL'], credential['apikey'], credential['secretkey']) self.__mydb = MySQL(dbconfig['host'], dbconfig['user'], dbconfig['passwd'], dbconfig['db'])
def read_key(): okcoinRESTURL = 'www.okcoin.com' #请求注意:国内账号需要 修改为 www.okcoin.cn with open('lijianhui', 'r') as apis: keys = json.loads(apis.read()) #现货API okcoinSpot = OKCoinSpot(okcoinRESTURL, keys["api"], keys["secret"]) #期货API okcoinFuture = OKCoinFuture(okcoinRESTURL, keys["api"], keys["secret"]) return okcoinSpot, okcoinFuture
def __init__(self): ##初始化apikey,secretkey,url apikey = config.apikey secretkey = config.secretkey okcoinRESTURL = 'www.okex.com' #请求注意:国内账号需要 修改为 www.okcoin.cn #现货API self.okcoinSpot = OKCoinSpot(okcoinRESTURL,apikey,secretkey) # 期货API self.okcoinFuture = OKCoinFuture(okcoinRESTURL, apikey, secretkey) self.depth = {}
def __init__(self, mykey=None, mysecret=None): if mykey and mysecret: self.mykey,self.mysecret = mykey,mysecret else: filename = CURRENTURL+r'\key' with open(filename,'r',encoding='utf-8') as f: data = f.read() self.mykey,self.mysecret = data.split('\n') self.mykey = self.mykey.strip() self.mysecret = self.mysecret.strip() okcoinRESTURL = 'www.okb.com' # print(self.mykey,self.mysecret) self.okcoinSpot = OKCoinSpot(okcoinRESTURL,self.mykey,self.mysecret)
def collect_okcoin(): # ------------------------------ # collect data from Okcoin API # ------------------------------ # API_KEY_OKCOIN='b4dd3278-df06-48af-8925-40120f46563b' # API_SECRET_OKCOIN='1F8A97B89F03A095238823CB1FAA3827' import sys sys.path.insert(0, '/Users/G_bgyl/si507/final_project/okcoin_lib') from OkcoinSpotAPI import OKCoinSpot from OkcoinFutureAPI import OKCoinFuture #初始化apikey,secretkey,url okcoinRESTURL = 'www.okcoin.com' #请求注意:国内账号需要 修改为 www.okcoin.cn #现货API okcoinSpot = OKCoinSpot(okcoinRESTURL, API_KEY_OKCOIN, API_SECRET_OKCOIN) #期货API okcoinFuture = OKCoinFuture(okcoinRESTURL, API_KEY_OKCOIN, API_SECRET_OKCOIN) # pprint.pprint (okcoinSpot.depth('btc_usd')) okcoin_depth = okcoinSpot.depth('btc_usd') # pprint.pprint(okcoin_depth) bids = [] for each_b in okcoin_depth['bids']: bids.append(['bids'] + each_b) asks = [] for each_a in okcoin_depth['bids']: asks.append(['asks'] + each_a) okcoin_data = bids + asks # print(len(okcoin_depth['bids']),len(okcoin_depth['asks']),len(okcoin_data)) return okcoin_data
'sell', 'coin_vol', 'day_low', 'unit_amount' ] # create tempdata # tempdata = pd.DataFrame(columns=column) conn = mysql.connector.connect(user='******', password='******', database='btc', use_unicode=True) yconnect = create_engine( 'mysql://*****:*****@localhost:3306/btc?charset=utf8') print('database has connected') #set ssl config 总是报SSL错误,没办法只能加上下面这句,不验证SSL了。 ssl._create_default_https_context = ssl._create_unverified_context #现货API okcoinSpot = OKCoinSpot(okcoinRESTURL, apikey, secretkey) #期货API okcoinFuture = OKCoinFuture(okcoinRESTURL, apikey, secretkey) print('start to request') def job(): zr_mk_qian = okcoinFuture.future_ticker('btc_usd', 'this_week') # print(zr_mk_qian) tempdata = pd.DataFrame( [[zr_mk_qian['date']] + list(zr_mk_qian['ticker'].values())], columns=column) cursor = conn.cursor() # tempdata = [zr_mk_qian['date']] + list(zr_mk_qian['ticker'].values()) # print(len(tempdata)) # cursor.execute("insert into btc_future_thisweek VALUES ([zr_mk_qian['date']] + list(zr_mk_qian['ticker'].values()))")
# codding: utf-8 from OkcoinSpotAPI import OKCoinSpot url = 'https://www.okcoin.cn' username = '******' password = '******' trade_pwd = 'guohongming03' OKCoin_spot = OKCoinSpot(url, username, password) if OKCoin_spot.login() == 1: print('login success!') else: print('login failed!') # account_info = OKCoin_spot.account_info() # 账户信息 # print(account_info) # financing_info = OKCoin_spot.financing_info() # 融资融币借放款深度前10名。 # print(financing_info) # borrow_info = OKCoin_spot.borrow_lend_info() # 借款信息(人民币,btc,ltc) # print(borrow_info) trade_value = (OKCoin_spot.trade_value()) # 最新交易价格 print(trade_value) # borrow_cny_apply = OKCoin_spot.borrow_cny_apply(100) # 申请人民币借款 # print(borrow_cny_apply) # back_cny = OKCoin_spot.back_cny() # 人民币还款 # print(back_cny)
from JubiSpotAPI import JubiSpot from YunbiSpotAPI import YunbiSpot from enum import Enum #class Coin(Enum): # BTC_CNY = 'btc_cny' # LTC_CNY = 'ltc_cny' # ETH_CNY = 'eth_cny' #初始化 OKCoin 参数 okcoin_apikey = 'ak' okcoin_secretkey = 'sK' okcoinRESTURL = 'www.okcoin.cn' #请求注意:国内账号需要 修改为 www.okcoin.cn #OKCoin现货API okcoinSpot = OKCoinSpot(okcoinRESTURL, okcoin_apikey, okcoin_secretkey) #初始化 YUNBI 参数 yunbi_apikey = 'ak' yunbi_secretkey = 'sk' yunbiRESTURL = 'www.yunbi.com' yunbiSpot = YunbiSpot(yunbiRESTURL, yunbi_apikey, yunbi_secretkey) #初始化 CHBTC 参数 chbtc_apikey = 'ak' chbtc_secretkey = 'sk' chbtc_market = 'api.chbtc.com' #行情api chbtc_trade = 'trade.chbtc.com' #交易api chbtcMarket = CHBtcSpot(chbtc_market, chbtc_apikey, chbtc_secretkey) #行情