예제 #1
0
def exchange_currency_table():
    engine = engine_local()
    sql = '''create table if not exists exchange_currency(
      id int primary key auto_increment not null,
      exchange varchar(20) not null,
      date date not null,
      name varchar(50) not null,
      symbol varchar(20) not null )
    '''
    engine.execute(sql)
    return
예제 #2
0
def coin_index_table():
    engine = engine_local()
    sql = '''create table if not exists coin_index(
    id int not null primary key auto_increment,
    `date` date not null unique ,
    coin_index decimal(10,4) null,
    coin_index_return decimal(10,4) null
    )
    '''
    engine.execute(sql)

    return
예제 #3
0
def depth_table():
    engine = engine_local()
    sql = ''' create table if not exists depth(
    coin_id varchar(20) not null,
    pair varchar(20) not null,
    exchange varchar(20) not null,
    date bigint not null,
    ask1_p decimal(20,10) null,
    ask2_p decimal(20,10) null,
    ask3_p decimal(20,10) null,
    ask4_p decimal(20,10) null,
    ask5_p decimal(20,10) null,
    ask6_p decimal(20,10) null,
    ask7_p decimal(20,10) null,
    ask8_p decimal(20,10) null,
    ask9_p decimal(20,10) null,
    ask10_p decimal(20,10) null,
    ask1_v decimal(20,10) null,
    ask2_v decimal(20,10) null,
    ask3_v decimal(20,10) null,
    ask4_v decimal(20,10) null,
    ask5_v decimal(20,10) null,
    ask6_v decimal(20,10) null,
    ask7_v decimal(20,10) null,
    ask8_v decimal(20,10) null,
    ask9_v decimal(20,10) null,
    ask10_v decimal(20,10) null,
    bid1_p decimal(20,10) null,
    bid2_p decimal(20,10) null,
    bid3_p decimal(20,10) null,
    bid4_p decimal(20,10) null,
    bid5_p decimal(20,10) null,
    bid6_p decimal(20,10) null,
    bid7_p decimal(20,10) null,
    bid8_p decimal(20,10) null,
    bid9_p decimal(20,10) null,
    bid10_p decimal(20,10) null,
    bid1_v decimal(20,10) null,
    bid2_v decimal(20,10) null,
    bid3_v decimal(20,10) null,
    bid4_v decimal(20,10) null,
    bid5_v decimal(20,10) null,
    bid6_v decimal(20,10) null,
    bid7_v decimal(20,10) null,
    bid8_v decimal(20,10) null,
    bid9_v decimal(20,10) null,
    bid10_v decimal(20,10) null,
    primary key(pair,exchange,date));
    '''
    engine.execute(sql)

    return
예제 #4
0
def bitfinex_kline_table():
    engine = engine_local()
    sql = '''create table if not exists kline_1m(
        coin_id varchar(20) not null,
        date datetime not null,
        exchange varchar(20) not null,
        open decimal(20,9) null,
        close decimal(20,9) null,
        high decimal(20,9) null,
        low decimal(20,9) null,
        vol decimal(20,4) null,
        primary key(coin_id,date,exchange
        )
              '''
    cur = engine.execute(sql)

    return
예제 #5
0
파일: binance.py 프로젝트: wufeipku/python
#-*- coding:utf-8 -*-
import websocket
import json
import sys
import pandas as pd
import time
from database import engine_local
import requests

engine = engine_local()
re = requests.get('https://api.binance.com/api/v1/exchangeInfo')
data = re.json()['symbols']
pairs = []
for d in data:
    pairs.append(d['symbol'])

pair_dict = {}
initial = {}
def on_open(self):

    for p in pairs[0:1]:

        self.send('{"stream":"bnbbtc@depth","data":"message"}')
        #self.send("{'event':'addChannel','channel':'ok_sub_spot_abl_btc_ticker'}")
def on_message(self,message): #data decompress
    message = json.loads(message)
    print(message)
#-----------------------------------------------------------------------------------------
    #k线数据存储
    # print(pair_dict)
    # if len(message) == 4: