def get_orders(): print( '查询挂单' ) r = api_call( 'GET', '/{}/orders'.format( account ) ) print( r.json(), width=100 ) orders = pd.DataFrame(r.json(),columns=['contract','exchange_oid','bs','entrust_amount','entrust_price','status']) return orders
def get_balance(account): #print( '查看账户信息' ) r = api_call( 'GET', '/{}/info'.format( account ) ) #pprint(r.json(), width=100) #print('查看position') position = r.json()['position'] position = pd.DataFrame(position,columns=['contract','total_amount','available','frozen']) position.index = position['contract'] return position
def eos_usdt_usdk_price(): res = requests.get('https://1token.trade/api/v1/quote/single-tick/okex/eos.usdt') #pprint(res.json(), width=1000) #卖一价 eos_usdt_ask = res.json()['asks'][0]['price'] #print('eos_usdt_ask:',eos_usdt_ask) #买一价 eos_usdt_bid = res.json()['bids'][0]['price'] #print('eos_usdt_bid:',eos_usdt_bid) res = requests.get( 'https://1token.trade/api/v1/quote/single-tick/okex/eos.usdk' ) #pprint(res.json(), width=1000) #卖一价 eos_usdk_ask = res.json()['asks'][0]['price'] #print('eos_usdk_ask:',eos_usdk_ask) #买一价 eos_usdk_bid = res.json()['bids'][0]['price'] #print('eos_usdk_bid:',eos_usdk_bid) res = requests.get( 'https://1token.trade/api/v1/quote/single-tick/okex/usdt.usdk' ) #pprint(res.json(), width=1000) #卖一价 usdt_usdk_ask = res.json()['asks'][0]['price'] #print('usdt_usdk_ask:',usdt_usdk_ask) #买一价 usdt_usdk_bid = res.json()['bids'][0]['price'] #print('usdt_usdk_bid:',usdt_usdk_bid) eos_usdt_usdk_eos = eos_usdt_bid * usdt_usdk_bid /eos_usdk_ask / 1.0002/1.0002/1.0002 eos_usdk_usdt_eos = eos_usdk_bid / usdt_usdk_ask / eos_usdt_ask / 1.0002/1.0002/1.0002 if eos_usdt_usdk_eos >= 1: print( 'eos_usdt_usdk_eos', eos_usdt_usdk_eos ) print( '下单' ) r = api_call( 'POST', '/{}/orders'.format( account ), data={'contract': 'okex/eos.usdt', 'price': eos_usdt_bid, 'bs': 's', 'amount': 10, 'options': {'close': False}} ) #print( r.json() ) r = api_call( 'POST', '/{}/orders'.format( account ), data={'contract': 'okex/usdt.usdk', 'price': usdt_usdk_bid, 'bs': 's', 'amount': 10*eos_usdt_bid, 'options': {'close': False}} ) print( r.json() ) r = api_call( 'POST', '/{}/orders'.format( account ), data={'contract': 'okex/eos.usdk', 'price': eos_usdk_ask, 'bs': 'b', 'amount': 10*eos_usdt_bid/eos_usdk_ask, 'options': {'close': False}} ) print( r.json() ) elif eos_usdk_usdt_eos>=1: print( 'eos_usdk_usdt_eos', eos_usdk_usdt_eos ) print( '下单' ) r = api_call( 'POST', '/{}/orders'.format( account ), data={'contract': 'okex/eos.usdk', 'price': eos_usdk_bid, 'bs': 's', 'amount': 10, 'options': {'close': False}} ) #print( r.json() ) r = api_call( 'POST', '/{}/orders'.format( account ), data={'contract': 'okex/usdt.usdk', 'price': usdt_usdk_ask, 'bs': 'b', 'amount': 10 * usdt_usdk_ask, 'options': {'close': False}} ) #print( r.json() ) r = api_call( 'POST', '/{}/orders'.format( account ), data={'contract': 'okex/eos.usdk', 'price': eos_usdk_ask, 'bs': 'b', 'amount': 10 * usdt_usdk_ask / eos_usdt_ask, 'options': {'close': False}} )
r = api_call( 'POST', '/{}/orders'.format( account ), data={'contract': 'okex/usdt.usdk', 'price': usdt_usdk_ask, 'bs': 'b', 'amount': 10 * usdt_usdk_ask, 'options': {'close': False}} ) #print( r.json() ) r = api_call( 'POST', '/{}/orders'.format( account ), data={'contract': 'okex/eos.usdk', 'price': eos_usdk_ask, 'bs': 'b', 'amount': 10 * usdt_usdk_ask / eos_usdt_ask, 'options': {'close': False}} ) #print( r.json() ) import time if __name__ == '__main__': account = 'okex/mock-eos-usdt-usdk' print( '查看账户信息' ) r = api_call( 'GET', '/{}/info'.format( account ) ) print( r.json() ) count = 0 profit = 1 print('start') while True: eos_usdt_usdk_price() time.sleep(1)
def cancle_orders(exchange_oids): for exchange_oid in exchange_oids: print('撤销订单:{}'.format(exchange_oid)) r = api_call( 'DELETE', '/{}/orders'.format( account ), params={'exchange_oid': exchange_oid} ) pprint( r.json(), width=100 )
def sell(price ,amount,contract='okex/usdt.usdk'): r = api_call( 'POST', '/{}/orders'.format( account ), data={'contract': contract, 'price': price, 'bs': 's', 'amount': amount} ) print( r.json() )
def cancle_all_orders(): print('撤销所有订单') r = api_call('DELETE', '/{}/orders/all'.format(account)) print(r.json())